diff --git a/account_payment_mode_default_account/README.rst b/account_payment_mode_default_account/README.rst index f0144bef1ee..d66fffaa1fd 100644 --- a/account_payment_mode_default_account/README.rst +++ b/account_payment_mode_default_account/README.rst @@ -10,20 +10,20 @@ Account Payment Mode Default Account !! source digest: sha256:5e6b935d02be3e279b161f28ed160f6a00ed4275cf053a5165a1e72435bbc874 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status - :alt: Alpha + :alt: Beta .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--payment-lightgray.png?logo=github - :target: https://github.com/OCA/bank-payment/tree/14.0/account_payment_mode_default_account + :target: https://github.com/OCA/bank-payment/tree/16.0/account_payment_mode_default_account :alt: OCA/bank-payment .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/bank-payment-14-0/bank-payment-14-0-account_payment_mode_default_account + :target: https://translation.odoo-community.org/projects/bank-payment-16-0/bank-payment-16-0-account_payment_mode_default_account :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/bank-payment&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -32,11 +32,6 @@ This module allows to define default receivable and payable accounts on payment mode to override the account selected on the customer when computing payment terms lines on invoices. -.. IMPORTANT:: - This is an alpha version, the data model and design can change at any time without warning. - Only for development or testing purpose, do not use in production. - `More details on development status `_ - **Table of contents** .. contents:: @@ -48,7 +43,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -78,6 +73,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/bank-payment `_ project on GitHub. +This module is part of the `OCA/bank-payment `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_payment_mode_default_account/__manifest__.py b/account_payment_mode_default_account/__manifest__.py index 7497592c99f..8a73946c7b2 100644 --- a/account_payment_mode_default_account/__manifest__.py +++ b/account_payment_mode_default_account/__manifest__.py @@ -3,8 +3,7 @@ { "name": "Account Payment Mode Default Account", "summary": "Set Receivable or Payable account according to payment mode", - "version": "14.0.1.0.0", - "development_status": "Alpha", + "version": "16.0.1.0.0", "category": "Accounting/Accounting", "website": "https://github.com/OCA/bank-payment", "author": "Camptocamp, Odoo Community Association (OCA)", diff --git a/account_payment_mode_default_account/models/account_move.py b/account_payment_mode_default_account/models/account_move.py index e0bedca9c92..9f8e24485d2 100644 --- a/account_payment_mode_default_account/models/account_move.py +++ b/account_payment_mode_default_account/models/account_move.py @@ -1,5 +1,8 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from contextlib import contextmanager + from odoo import api, models @@ -7,32 +10,50 @@ class AccountMove(models.Model): _inherit = "account.move" - def _recompute_payment_terms_lines(self): - if self.payment_mode_id: - return super( - AccountMove, - self.with_context( - _partner_property_account_payment_mode=self.payment_mode_id.id - ), - )._recompute_payment_terms_lines() - else: - return super()._recompute_payment_terms_lines() - def _get_payment_term_lines(self): self.ensure_one() return self.line_ids.filtered( - lambda line: line.account_id.user_type_id.type in ("receivable", "payable") + lambda line: line.account_id.account_type + in ("asset_receivable", "liability_payable") ) + def _change_account_on_lines(self): + self.ensure_one() + payment_term_lines = self._get_payment_term_lines() + payment_mode_id = self.payment_mode_id.id + partner = self.partner_id.with_context( + _partner_property_account_payment_mode=payment_mode_id + ) + if self.is_sale_document(include_receipts=True): + payment_term_lines.account_id = partner.property_account_receivable_id + else: + payment_term_lines.account_id = partner.property_account_payable_id + + @contextmanager + def _sync_dynamic_line( + self, + existing_key_fname, + needed_vals_fname, + needed_dirty_fname, + line_type, + container, + ): + with super()._sync_dynamic_line( + existing_key_fname, + needed_vals_fname, + needed_dirty_fname, + line_type, + container, + ): + yield + if line_type == "payment_term": + invoices = container.get("records") + invoices = invoices.filtered(lambda invoice: invoice.state == "draft") + for inv in invoices: + inv._change_account_on_lines() + @api.onchange("payment_mode_id") def _onchange_payment_mode_id(self): if self.payment_mode_id and self.partner_id: - payment_term_lines = self._get_payment_term_lines() - partner = self.partner_id.with_context( - _partner_property_account_payment_mode=self.payment_mode_id.id - ) - # Retrieve account from partner. - if self.is_sale_document(include_receipts=True): - payment_term_lines.account_id = partner.property_account_receivable_id - else: - payment_term_lines.account_id = partner.property_account_payable_id + if self.state == "draft": + self._change_account_on_lines() diff --git a/account_payment_mode_default_account/models/account_payment_mode.py b/account_payment_mode_default_account/models/account_payment_mode.py index e6899765e3c..3d8bb81e304 100644 --- a/account_payment_mode_default_account/models/account_payment_mode.py +++ b/account_payment_mode_default_account/models/account_payment_mode.py @@ -1,5 +1,6 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + from odoo import fields, models @@ -9,11 +10,11 @@ class AccountPaymentMode(models.Model): default_receivable_account_id = fields.Many2one( "account.account", - domain="[('deprecated', '=', False),('company_id', '=', company_id),('user_type_id.type', '=', 'receivable')]", # noqa + domain="[('deprecated', '=', False),('company_id', '=', company_id),('account_type', '=', 'asset_receivable')]", # noqa help="This account will be used instead of the default one as the receivable account on invoices using this payment mode", # noqa ) default_payable_account_id = fields.Many2one( "account.account", - domain="[('deprecated', '=', False), ('company_id', '=', company_id),('user_type_id.type', '=', 'payable')]", # noqa + domain="[('deprecated', '=', False), ('company_id', '=', company_id),('account_type', '=', 'liability_payable')]", # noqa help="This account will be used instead of the default one as the payable account on invoices using this payment mode", # noqa ) diff --git a/account_payment_mode_default_account/models/chart_template.py b/account_payment_mode_default_account/models/chart_template.py index d8b1e14f628..c6dc6062645 100644 --- a/account_payment_mode_default_account/models/chart_template.py +++ b/account_payment_mode_default_account/models/chart_template.py @@ -8,7 +8,7 @@ class AccountChartTemplate(models.Model): _inherit = "account.chart.template" def generate_properties(self, acc_template_ref, company): - super().generate_properties(acc_template_ref, company) + res = super().generate_properties(acc_template_ref, company) # Make sure a property with stored in its name is created as default for the company # so that _get_multi would fetch it if the partner does not have a property itself PropertyObj = self.env["ir.property"] @@ -26,6 +26,7 @@ def generate_properties(self, acc_template_ref, company): ] for chart_field, partner_field, model in todo_list: account = self[chart_field] - value = acc_template_ref[account.id] if account else False + value = acc_template_ref[account].id if account else False if value: PropertyObj._set_default(partner_field, model, value, company=company) + return res diff --git a/account_payment_mode_default_account/models/res_partner.py b/account_payment_mode_default_account/models/res_partner.py index 265282c9bb6..bd1a7551435 100644 --- a/account_payment_mode_default_account/models/res_partner.py +++ b/account_payment_mode_default_account/models/res_partner.py @@ -1,5 +1,6 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + from odoo import api, fields, models @@ -29,7 +30,7 @@ class ResPartner(models.Model): property_stored_account_payable_id = fields.Many2one( "account.account", company_dependent=True, - string="Account payable", + string="Account Payable", domain="[('internal_type', '=', 'payable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", # noqa ) diff --git a/account_payment_mode_default_account/static/description/index.html b/account_payment_mode_default_account/static/description/index.html index 4c17e59a71a..c41fa0283a3 100644 --- a/account_payment_mode_default_account/static/description/index.html +++ b/account_payment_mode_default_account/static/description/index.html @@ -1,4 +1,3 @@ - @@ -369,16 +368,10 @@

Account Payment Mode Default Account

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:5e6b935d02be3e279b161f28ed160f6a00ed4275cf053a5165a1e72435bbc874 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Alpha License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/bank-payment Translate me on Weblate Try me on Runboat

This module allows to define default receivable and payable accounts on payment mode to override the account selected on the customer when computing payment terms lines on invoices.

-
-

Important

-

This is an alpha version, the data model and design can change at any time without warning. -Only for development or testing purpose, do not use in production. -More details on development status

-

Table of contents

    @@ -396,7 +389,7 @@

    Bug Tracker

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

@@ -420,7 +413,7 @@

Maintainers

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/bank-payment project on GitHub.

+

This module is part of the OCA/bank-payment project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py b/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py index b8500d59756..56942271c65 100644 --- a/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py +++ b/account_payment_mode_default_account/tests/test_account_payment_mode_default_account.py @@ -1,9 +1,11 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) -from odoo.tests import Form, SavepointCase +from odoo.tests import Form +from odoo.tests.common import TransactionCase -class TestAccountPaymentModeDefaultAccount(SavepointCase): + +class TestAccountPaymentModeDefaultAccount(TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -13,7 +15,7 @@ def setUpClass(cls): cls.receivable_account = cls.env["account.account"].search( [ ("company_id", "=", cls.env.company.id), - ("user_type_id.type", "=", "receivable"), + ("account_type", "=", "asset_receivable"), ("code", "=like", receivable_code + "%"), ], limit=1, @@ -21,7 +23,7 @@ def setUpClass(cls): cls.payable_account = cls.env["account.account"].search( [ ("company_id", "=", cls.env.company.id), - ("user_type_id.type", "=", "payable"), + ("account_type", "=", "liability_payable"), ], limit=1, ) diff --git a/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account b/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account new file mode 120000 index 00000000000..ba233810d69 --- /dev/null +++ b/setup/account_payment_mode_default_account/odoo/addons/account_payment_mode_default_account @@ -0,0 +1 @@ +../../../../account_payment_mode_default_account \ No newline at end of file diff --git a/setup/account_payment_mode_default_account/setup.py b/setup/account_payment_mode_default_account/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/account_payment_mode_default_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)