From 3f7ba23a4b6b8a67e1dd17ebf6a07c49f4beb0dc Mon Sep 17 00:00:00 2001
From: sygel
Date: Sun, 11 Aug 2024 16:23:26 +0200
Subject: [PATCH] [MIG] contract_payment_mode: Migration to 17.0
---
contract_payment_mode/README.rst | 11 +++++++----
contract_payment_mode/__manifest__.py | 2 +-
contract_payment_mode/hooks.py | 5 +----
contract_payment_mode/models/contract.py | 18 +++++++++++-------
contract_payment_mode/readme/CONTRIBUTORS.md | 4 ++++
contract_payment_mode/readme/USAGE.md | 7 +++----
.../static/description/index.html | 7 +++++--
.../tests/test_contract_payment.py | 8 +++-----
8 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/contract_payment_mode/README.rst b/contract_payment_mode/README.rst
index 87b2124c1..41b8718f4 100644
--- a/contract_payment_mode/README.rst
+++ b/contract_payment_mode/README.rst
@@ -44,16 +44,15 @@ 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
here.
5. If not, or if you want another payment mode, you can change it in the
corresponding field.
-6. Click on **Generate recurring invoices automatically** checkbox.
-7. Add a product to invoice.
-8. If you create an invoice, new invoice will have the selected payment
+6. Add a product to invoice.
+7. If you create an invoice, new invoice will have the selected payment
mode.
Bug Tracker
@@ -86,6 +85,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 ec574554d..5983ca4ee 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 1a2e46cda..ccb8fad71 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 fdfca18f4..51dd190a2 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", "contract_type")
+ 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 e509eac7b..461555681 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 23ff045ca..f7a48b903 100644
--- a/contract_payment_mode/readme/USAGE.md
+++ b/contract_payment_mode/readme/USAGE.md
@@ -1,11 +1,10 @@
-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
here.
5. If not, or if you want another payment mode, you can change it in
the corresponding field.
-6. Click on **Generate recurring invoices automatically** checkbox.
-7. Add a product to invoice.
-8. If you create an invoice, new invoice will have the selected payment
+6. Add a product to invoice.
+7. If you create an invoice, new invoice will have the selected payment
mode.
diff --git a/contract_payment_mode/static/description/index.html b/contract_payment_mode/static/description/index.html
index ec6d71b59..554c037ac 100644
--- a/contract_payment_mode/static/description/index.html
+++ b/contract_payment_mode/static/description/index.html
@@ -393,14 +393,13 @@ invoices with this payment mode.
diff --git a/contract_payment_mode/tests/test_contract_payment.py b/contract_payment_mode/tests/test_contract_payment.py
index 3c91628d7..f8631df9c 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 @@ from ..hooks import post_init_hook
@tagged("post_install", "-at_install")
-class TestContractPaymentInit(odoo.tests.HttpCase):
+class TestContractPaymentInit(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -91,12 +90,11 @@ class TestContractPaymentInit(odoo.tests.HttpCase):
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,