diff --git a/agreement_account/README.rst b/agreement_account/README.rst index bcfdcffdb..1aa005989 100644 --- a/agreement_account/README.rst +++ b/agreement_account/README.rst @@ -14,13 +14,13 @@ Agreement Account :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github - :target: https://github.com/OCA/contract/tree/12.0/agreement_account + :target: https://github.com/OCA/contract/tree/14.0/agreement_account :alt: OCA/contract .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_account :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/110/12.0 + :target: https://runbot.odoo-community.org/runbot/110/14.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -79,6 +79,6 @@ Current `maintainers `__: |maintainer-alexis-via| |maintainer-bealdav| -This module is part of the `OCA/contract `_ project on GitHub. +This module is part of the `OCA/contract `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/agreement_account/__manifest__.py b/agreement_account/__manifest__.py index d70831428..ba236f799 100644 --- a/agreement_account/__manifest__.py +++ b/agreement_account/__manifest__.py @@ -3,26 +3,26 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Agreement Account', - 'summary': "Agreement on invoices", - 'version': '12.0.1.0.0', - 'category': 'Contract', - 'author': 'Akretion, Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/contract', - 'license': 'AGPL-3', - 'depends': [ - 'agreement', - 'account', + "name": "Agreement Account", + "summary": "Agreement on invoices", + "version": "14.0.1.0.0", + "category": "Contract", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/contract", + "license": "AGPL-3", + "depends": [ + "agreement", + "account", ], - 'data': [ - 'security/ir.model.access.csv', - 'views/agreement.xml', - 'views/account_invoice.xml', - ], - 'development_status': 'Beta', - 'maintainers': [ - 'alexis-via', - 'bealdav', + "data": [ + "security/ir.model.access.csv", + "views/agreement.xml", + "views/account_move.xml", ], - 'installable': True, + "development_status": "Beta", + "maintainers": [ + "alexis-via", + "bealdav", + ], + "installable": True, } diff --git a/agreement_account/models/__init__.py b/agreement_account/models/__init__.py index 720f31c8b..77c035979 100644 --- a/agreement_account/models/__init__.py +++ b/agreement_account/models/__init__.py @@ -1,2 +1,2 @@ +from . import account_move from . import agreement -from . import account_invoice diff --git a/agreement_account/models/account_invoice.py b/agreement_account/models/account_invoice.py deleted file mode 100644 index a6bdc4122..000000000 --- a/agreement_account/models/account_invoice.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2017-2020 Akretion France (http://www.akretion.com/) -# @author: Alexis de Lattre -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - - -from odoo import fields, models - - -class AccountInvoice(models.Model): - _inherit = 'account.invoice' - - agreement_id = fields.Many2one( - comodel_name='agreement', string='Agreement', ondelete='restrict', - track_visibility='onchange', readonly=True, copy=False, - states={'draft': [('readonly', False)]}) diff --git a/agreement_account/models/account_move.py b/agreement_account/models/account_move.py new file mode 100644 index 000000000..e8e0d798d --- /dev/null +++ b/agreement_account/models/account_move.py @@ -0,0 +1,20 @@ +# Copyright 2017-2020 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import fields, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + agreement_id = fields.Many2one( + comodel_name="agreement", + string="Agreement", + ondelete="restrict", + tracking=True, + readonly=True, + copy=False, + states={"draft": [("readonly", False)]}, + ) diff --git a/agreement_account/models/agreement.py b/agreement_account/models/agreement.py index ddbc4ef42..809228458 100644 --- a/agreement_account/models/agreement.py +++ b/agreement_account/models/agreement.py @@ -7,30 +7,33 @@ from odoo import fields, models class Agreement(models.Model): - _inherit = 'agreement' + _inherit = "agreement" invoice_ids = fields.One2many( - 'account.invoice', 'agreement_id', string='Invoices', readonly=True) + "account.move", "agreement_id", string="Invoices", readonly=True + ) out_invoice_count = fields.Integer( - compute='_compute_invoice_count', string='# of Customer Invoices') + compute="_compute_invoice_count", string="# of Customer Invoices" + ) in_invoice_count = fields.Integer( - compute='_compute_invoice_count', string='# of Vendor Bills') + compute="_compute_invoice_count", string="# of Vendor Bills" + ) def _compute_invoice_count(self): - base_domain = [ - ('agreement_id', 'in', self.ids), - ('state', 'not in', ('draft', 'cancel'))] - aio = self.env['account.invoice'] + base_domain = [("agreement_id", "in", self.ids)] + aio = self.env["account.move"] out_rg_res = aio.read_group( - base_domain + [('type', 'in', ('out_invoice', 'out_refund'))], - ['agreement_id'], ['agreement_id']) - out_data = dict( - [(x['agreement_id'][0], x['agreement_id_count']) for x in out_rg_res]) + base_domain + [("move_type", "in", ("out_invoice", "out_refund"))], + ["agreement_id"], + ["agreement_id"], + ) + out_data = {x["agreement_id"][0]: x["agreement_id_count"] for x in out_rg_res} in_rg_res = aio.read_group( - base_domain + [('type', 'in', ('in_invoice', 'in_refund'))], - ['agreement_id'], ['agreement_id']) - in_data = dict( - [(x['agreement_id'][0], x['agreement_id_count']) for x in in_rg_res]) + base_domain + [("move_type", "in", ("in_invoice", "in_refund"))], + ["agreement_id"], + ["agreement_id"], + ) + in_data = {x["agreement_id"][0]: x["agreement_id_count"] for x in in_rg_res} for agreement in self: agreement.out_invoice_count = out_data.get(agreement.id, 0) agreement.in_invoice_count = in_data.get(agreement.id, 0) diff --git a/agreement_account/tests/__init__.py b/agreement_account/tests/__init__.py new file mode 100644 index 000000000..b636caa99 --- /dev/null +++ b/agreement_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_agreement diff --git a/agreement_account/tests/test_agreement.py b/agreement_account/tests/test_agreement.py new file mode 100644 index 000000000..9a2982da9 --- /dev/null +++ b/agreement_account/tests/test_agreement.py @@ -0,0 +1,31 @@ +# Copyright 2017-2020 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestAgreement(TransactionCase): + def setUp(self): + super().setUp() + self.test_customer = self.env["res.partner"].create({"name": "TestCustomer"}) + self.test_agreement_sale = self.env["agreement"].create( + { + "name": "TestAgreement-Sale", + "code": "SALE", + "partner_id": self.test_customer.id, + "domain": "sale", + } + ) + self.test_agreement_purchase = self.env["agreement"].create( + { + "name": "TestAgreement-Purchase", + "code": "PURCHASE", + "partner_id": self.test_customer.id, + "domain": "purchase", + } + ) + + def test_compute_invoice_count(self): + self.test_agreement_sale._compute_invoice_count() + self.test_agreement_purchase._compute_invoice_count() diff --git a/agreement_account/views/account_invoice.xml b/agreement_account/views/account_invoice.xml deleted file mode 100644 index 891ca4f05..000000000 --- a/agreement_account/views/account_invoice.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - agreement.customer.invoice.form - account.invoice - - - - - - - - - - - agreement.supplier.invoice.form - account.invoice - - - - - - - - - - agreement.account.invoice.search - account.invoice - - - - - - - - - - - - - diff --git a/agreement_account/views/account_move.xml b/agreement_account/views/account_move.xml new file mode 100644 index 000000000..459270743 --- /dev/null +++ b/agreement_account/views/account_move.xml @@ -0,0 +1,58 @@ + + + + + agreement.customer.invoice.form + account.move + + + + + + + + + + + agreement.supplier.invoice.form + account.move + + + + + + + + + + agreement.account.move.search + account.move + + + + + + + + + + + + diff --git a/agreement_account/views/agreement.xml b/agreement_account/views/agreement.xml index 36104570a..60db881bb 100644 --- a/agreement_account/views/agreement.xml +++ b/agreement_account/views/agreement.xml @@ -1,59 +1,84 @@ - - - + 150 - + Vendor Bills - account.invoice + account.move tree,form - [('type','in', ('in_invoice', 'in_refund')), ('state', 'not in', ('draft', 'cancel'))] - {'default_type': 'in_invoice', 'type': 'in_invoice', 'journal_type': 'purchase'} + [('move_type','in', ('in_invoice', 'in_refund')), ('state', 'not in', ('draft', 'cancel'))] + {'default_type': 'in_invoice', 'move_type': 'in_invoice', 'journal_type': 'purchase'} - - + + tree - - + + - - + + form - - + + invoice.button.agreement.form agreement - +
- - -