diff --git a/contract_payment_mode/README.rst b/contract_payment_mode/README.rst index 87b2124c1f..f2ff6d91f9 100644 --- a/contract_payment_mode/README.rst +++ b/contract_payment_mode/README.rst @@ -44,7 +44,7 @@ Your user should be a Sales Manager or Accountant. Usage ===== -1. Go to *Accounting > Sales > Contracts*. +1. Go to *Invoicing > Customers > Customer Contracts*. 2. Create one. 3. Select a partner to which invoice. 4. If the partner has a payment mode, this payment mode is selected @@ -86,6 +86,10 @@ Contributors - Guillermo Llinares - Amamr Officewala - Carolina Fernandez +- David Jaen david.jaen.revert@gmail.com +- Alberto Martínez +- Harald Panten +- Valentin Vinagre Maintainers ----------- diff --git a/contract_payment_mode/__manifest__.py b/contract_payment_mode/__manifest__.py index ec574554df..5983ca4eed 100644 --- a/contract_payment_mode/__manifest__.py +++ b/contract_payment_mode/__manifest__.py @@ -10,7 +10,7 @@ { "name": "Contract Payment Mode", "summary": "Payment mode in contracts and their invoices", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "author": "Domatix, " "Tecnativa, " "Odoo Community Association (OCA)", "website": "https://github.com/OCA/contract", "depends": ["contract", "account_payment_partner"], diff --git a/contract_payment_mode/hooks.py b/contract_payment_mode/hooks.py index 1a2e46cdad..ccb8fad714 100644 --- a/contract_payment_mode/hooks.py +++ b/contract_payment_mode/hooks.py @@ -3,14 +3,11 @@ import logging -from odoo import SUPERUSER_ID, api - _logger = logging.getLogger(__name__) -def post_init_hook(cr, registry): +def post_init_hook(env): """Copy payment mode from partner to the new field at contract.""" - env = api.Environment(cr, SUPERUSER_ID, {}) m_contract = env["contract.contract"] contracts = m_contract.search([("payment_mode_id", "=", False)]) if contracts: diff --git a/contract_payment_mode/models/contract.py b/contract_payment_mode/models/contract.py index fdfca18f4d..0d6504f03b 100644 --- a/contract_payment_mode/models/contract.py +++ b/contract_payment_mode/models/contract.py @@ -9,15 +9,19 @@ class ContractContract(models.Model): string="Payment Mode", domain=[("payment_type", "=", "inbound")], index=True, + compute="_compute_payment_mode_id", + store=True, + readonly=False, ) - @api.onchange("partner_id") - def on_change_partner_id(self): - partner = self.with_company(self.company_id).partner_id - if self.contract_type == "purchase": - self.payment_mode_id = partner.supplier_payment_mode_id.id - else: - self.payment_mode_id = partner.customer_payment_mode_id.id + @api.depends("partner_id") + def _compute_payment_mode_id(self): + for rec in self: + partner = rec.with_company(rec.company_id).partner_id + if rec.contract_type == "purchase": + rec.payment_mode_id = partner.supplier_payment_mode_id.id + else: + rec.payment_mode_id = partner.customer_payment_mode_id.id def _prepare_invoice(self, date_invoice, journal=None): invoice_vals = super()._prepare_invoice( diff --git a/contract_payment_mode/readme/CONTRIBUTORS.md b/contract_payment_mode/readme/CONTRIBUTORS.md index e509eac7bd..461555681c 100644 --- a/contract_payment_mode/readme/CONTRIBUTORS.md +++ b/contract_payment_mode/readme/CONTRIBUTORS.md @@ -6,3 +6,7 @@ - Guillermo Llinares \<\> - Amamr Officewala \<\> - Carolina Fernandez \<\> +- David Jaen +- Alberto Martínez \<\> +- Harald Panten \<\> +- Valentin Vinagre \<\> diff --git a/contract_payment_mode/readme/USAGE.md b/contract_payment_mode/readme/USAGE.md index 23ff045caa..3890430c0b 100644 --- a/contract_payment_mode/readme/USAGE.md +++ b/contract_payment_mode/readme/USAGE.md @@ -1,4 +1,4 @@ -1. Go to *Accounting \> Sales \> Contracts*. +1. Go to *Invoicing \> Customers \> Customer Contracts*. 2. Create one. 3. Select a partner to which invoice. 4. If the partner has a payment mode, this payment mode is selected diff --git a/contract_payment_mode/static/description/index.html b/contract_payment_mode/static/description/index.html index ec6d71b595..c19539afdc 100644 --- a/contract_payment_mode/static/description/index.html +++ b/contract_payment_mode/static/description/index.html @@ -393,7 +393,7 @@

Configuration

Usage

    -
  1. Go to Accounting > Sales > Contracts.
  2. +
  3. Go to Invoicing > Customers > Customer Contracts.
  4. Create one.
  5. Select a partner to which invoice.
  6. If the partner has a payment mode, this payment mode is selected @@ -434,6 +434,10 @@

    Contributors

  7. Guillermo Llinares <guillermo@studio73.es>
  8. Amamr Officewala <aofficewala@opensourceintegrators.com>
  9. Carolina Fernandez <carolina.fernandez@tecnativa.com>
  10. +
  11. David Jaen david.jaen.revert@gmail.com
  12. +
  13. Alberto Martínez <alberto.martinez@sygel.es>
  14. +
  15. Harald Panten <harald.panten@sygel.es>
  16. +
  17. Valentin Vinagre <valentin.vinagre@sygel.es>
diff --git a/contract_payment_mode/tests/test_contract_payment.py b/contract_payment_mode/tests/test_contract_payment.py index 3c91628d74..f8631df9cd 100644 --- a/contract_payment_mode/tests/test_contract_payment.py +++ b/contract_payment_mode/tests/test_contract_payment.py @@ -6,8 +6,7 @@ from unittest.mock import patch -import odoo.tests -from odoo.tests import tagged +from odoo.tests import common, tagged from odoo.addons.account.models.account_payment_method import AccountPaymentMethod @@ -15,7 +14,7 @@ @tagged("post_install", "-at_install") -class TestContractPaymentInit(odoo.tests.HttpCase): +class TestContractPaymentInit(common.TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -91,12 +90,11 @@ def test_post_init_hook(self): contract.payment_mode_id = False self.assertEqual(contract.payment_mode_id.id, False) - post_init_hook(self.cr, self.env) + post_init_hook(self.env) self.assertEqual(contract.payment_mode_id, self.payment_mode) def test_contract_and_invoices(self): self.contract.write({"partner_id": self.partner.id}) - self.contract.on_change_partner_id() self.assertEqual( self.contract.payment_mode_id, self.contract.partner_id.customer_payment_mode_id,