Merge pull request #1051 from expsa/zainab_acc_pro

Update and rename account_move.py to account_move
This commit is contained in:
zainab2097 2024-09-09 17:09:26 +03:00 committed by GitHub
commit 5cabc43d24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 62 deletions

View File

@ -0,0 +1,43 @@
from odoo import api, fields, models, _
class AccountMove(models.Model):
_inherit = "account.move"
attach_no = fields.Integer(compute='get_attachments')
res_model = fields.Char()
res_id = fields.Integer()
# 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):
self.ensure_one()
action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
related_ids = self.ids
related_models = 'account.move'
if self.res_id and self.res_model:
related_ids = self.ids + [res_id]
related_models = ['account.move', self.res_model]
action['domain'] = [
('res_model', 'in',related_models),
('res_id', 'in', related_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 = [
('res_model', 'in', related_models),
('res_id', 'in', related_ids),]
self.attach_no = self.env['ir.attachment'].search_count(domain)
return action

View File

@ -1,62 +0,0 @@
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
# Combine account.move and project.invoice ids
related_ids = account_move_ids + project_invoice_ids
action['domain'] = [
('res_model', 'in', ['account.move', 'project.invoice']),
('res_id', 'in', related_ids),]
# 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 = [
('res_model', 'in', ['account.move', 'project.invoice']),
('res_id', 'in', related_ids),]
# 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

@ -12,6 +12,12 @@
<field name="attach_no" widget="statinfo" string="Documents"/>
</button>
</xpath>
<xpath expr="//page[@name='other_info']" position="inside">
<group name="model_info" string='Model Info'>
<field name='res_model'/>
<field name='res_id'/>
</group>
</xpath>
</field>
</record>