[ADD]ADD account_attachments

This commit is contained in:
zainab8585 2024-09-09 09:45:07 +02:00
parent dff852eda9
commit c1037294ba
7 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1 @@
from . import models

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
################################################################################
{
'name': "Account Attachments",
'version': '14.0.1.0.0',
'category': 'Account',
'summary': 'Helps to view all documents attached to account',
'description': """account Attachments module allows user to view
all the documents attached to account.""",
'company': 'Expert',
'website': 'https://www.expert.com',
'depends': ['base','account'],
'data': [
'views/account_move_view.xml'
],
'license': 'AGPL-3',
'installable': True,
'auto_install': False,
'application': True,
}

View File

@ -0,0 +1 @@
from . import account_move

View File

@ -0,0 +1,52 @@
from odoo import api, fields, models, _
class AccountMove(models.Model):
_inherit = "account.move"
attach_no = fields.Integer(compute='get_attachments')
def get_attachments(self):
action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
action['domain'] = str([('res_model', '=', 'account.move'), ('res_id', 'in', self.ids)])
action['context'] = "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
domain = [('res_model', '=', 'account.move'), ('res_id', '=', self.id)]
self.attach_no = self.env['ir.attachment'].search_count(domain)
return action
# def get_attachments(self):
# # Action for opening the attachment window
# action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
# # Prepare domain for attachments related to account.move and project.invoice
# account_move_ids = self.ids # IDs of account.move
# # Get all related project.invoice records based on the invoice_id
# project_invoice_ids = self.env['project.invoice'].search([('invoice_id', 'in', account_move_ids)]).ids
#
# # Expand the domain to include both account.move and project.invoice attachments
# action['domain'] = [
# '|', # OR operator to include attachments from both models
# '&', # AND operator for account.move
# ('res_model', '=', 'account.move'),
# ('res_id', 'in', account_move_ids),
# '&', # AND operator for project.invoice
# ('res_model', '=', 'project.invoice'),
# ('res_id', 'in', project_invoice_ids),
# ]
#
# # Context for creating new attachments
# action['context'] = "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
#
# # Update attachment count for smart button
# domain = [
# '|', # OR operator for counting attachments from both models
# '&', # AND operator for the first condition (account.move)
# ('res_model', '=', 'account.move'),
# ('res_id', 'in', account_move_ids),
# '&', # AND operator for the second condition (project.invoice)
# ('res_model', '=', 'project.invoice'),
# ('res_id', 'in', project_invoice_ids),
# ]
#
# self.attach_no = self.env['ir.attachment'].search_count(domain)
#
# return action

View File

@ -0,0 +1,18 @@
<!-- Inherit Form View to Modify it -->
<odoo>
<record id="account_move_view" model="ir.ui.view">
<field name="name">account.move.inherit.form.attachment</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button name="get_attachments" type="object"
class="oe_stat_button"
icon="fa-file-text-o">
<field name="attach_no" widget="statinfo" string="Documents"/>
</button>
</xpath>
</field>
</record>
</odoo>