From c1037294baae4308fe1858fda2939f4157cdb119 Mon Sep 17 00:00:00 2001 From: zainab8585 Date: Mon, 9 Sep 2024 09:45:07 +0200 Subject: [PATCH] [ADD]ADD account_attachments --- .../account_attachments/__init__.py | 1 + .../account_attachments/__manifest__.py | 20 +++++++ .../account_attachments/i18n/ar_001.po | 0 .../account_attachments/models/__init__.py | 1 + .../models/account_move.py | 52 ++++++++++++++++++ .../static/description/icon.png | Bin 0 -> 12756 bytes .../views/account_move_view.xml | 18 ++++++ 7 files changed, 92 insertions(+) create mode 100755 odex25_project/account_attachments/__init__.py create mode 100755 odex25_project/account_attachments/__manifest__.py create mode 100755 odex25_project/account_attachments/i18n/ar_001.po create mode 100755 odex25_project/account_attachments/models/__init__.py create mode 100755 odex25_project/account_attachments/models/account_move.py create mode 100755 odex25_project/account_attachments/static/description/icon.png create mode 100755 odex25_project/account_attachments/views/account_move_view.xml diff --git a/odex25_project/account_attachments/__init__.py b/odex25_project/account_attachments/__init__.py new file mode 100755 index 000000000..0650744f6 --- /dev/null +++ b/odex25_project/account_attachments/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/odex25_project/account_attachments/__manifest__.py b/odex25_project/account_attachments/__manifest__.py new file mode 100755 index 000000000..0cc807a9e --- /dev/null +++ b/odex25_project/account_attachments/__manifest__.py @@ -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, +} diff --git a/odex25_project/account_attachments/i18n/ar_001.po b/odex25_project/account_attachments/i18n/ar_001.po new file mode 100755 index 000000000..e69de29bb diff --git a/odex25_project/account_attachments/models/__init__.py b/odex25_project/account_attachments/models/__init__.py new file mode 100755 index 000000000..9c0a42138 --- /dev/null +++ b/odex25_project/account_attachments/models/__init__.py @@ -0,0 +1 @@ +from . import account_move diff --git a/odex25_project/account_attachments/models/account_move.py b/odex25_project/account_attachments/models/account_move.py new file mode 100755 index 000000000..255ae56ea --- /dev/null +++ b/odex25_project/account_attachments/models/account_move.py @@ -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 + diff --git a/odex25_project/account_attachments/static/description/icon.png b/odex25_project/account_attachments/static/description/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..b906f743aa724f2836697055dba8a937ca55d05e GIT binary patch literal 12756 zcmeIuF#!Mo0K%a4Pi+e?h(KY$fB^#r3>YwAz<>b*1`HT5V8DO@0|pEjFkrxd0RsjM a7%*VKfB^#r3>YwAz<>b*1`HT5@E#a3)Bphh literal 0 HcmV?d00001 diff --git a/odex25_project/account_attachments/views/account_move_view.xml b/odex25_project/account_attachments/views/account_move_view.xml new file mode 100755 index 000000000..a19bdc848 --- /dev/null +++ b/odex25_project/account_attachments/views/account_move_view.xml @@ -0,0 +1,18 @@ + + + + account.move.inherit.form.attachment + account.move + + + + + + + + +