[MIG] contract_payment_mode: Migration to 17.0

This commit is contained in:
sygel
2024-08-11 16:23:26 +02:00
parent 922b0da56a
commit 3f7ba23a4b
8 changed files with 35 additions and 27 deletions

View File

@@ -44,16 +44,15 @@ Your user should be a Sales Manager or Accountant.
Usage Usage
===== =====
1. Go to *Accounting > Sales > Contracts*. 1. Go to *Invoicing > Customers > Customer Contracts*.
2. Create one. 2. Create one.
3. Select a partner to which invoice. 3. Select a partner to which invoice.
4. If the partner has a payment mode, this payment mode is selected 4. If the partner has a payment mode, this payment mode is selected
here. here.
5. If not, or if you want another payment mode, you can change it in the 5. If not, or if you want another payment mode, you can change it in the
corresponding field. corresponding field.
6. Click on **Generate recurring invoices automatically** checkbox. 6. Add a product to invoice.
7. Add a product to invoice. 7. If you create an invoice, new invoice will have the selected payment
8. If you create an invoice, new invoice will have the selected payment
mode. mode.
Bug Tracker Bug Tracker
@@ -86,6 +85,10 @@ Contributors
- Guillermo Llinares <guillermo@studio73.es> - Guillermo Llinares <guillermo@studio73.es>
- Amamr Officewala <aofficewala@opensourceintegrators.com> - Amamr Officewala <aofficewala@opensourceintegrators.com>
- Carolina Fernandez <carolina.fernandez@tecnativa.com> - Carolina Fernandez <carolina.fernandez@tecnativa.com>
- David Jaen david.jaen.revert@gmail.com
- Alberto Martínez <alberto.martinez@sygel.es>
- Harald Panten <harald.panten@sygel.es>
- Valentin Vinagre <valentin.vinagre@sygel.es>
Maintainers Maintainers
----------- -----------

View File

@@ -10,7 +10,7 @@
{ {
"name": "Contract Payment Mode", "name": "Contract Payment Mode",
"summary": "Payment mode in contracts and their invoices", "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)", "author": "Domatix, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract", "website": "https://github.com/OCA/contract",
"depends": ["contract", "account_payment_partner"], "depends": ["contract", "account_payment_partner"],

View File

@@ -3,14 +3,11 @@
import logging import logging
from odoo import SUPERUSER_ID, api
_logger = logging.getLogger(__name__) _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.""" """Copy payment mode from partner to the new field at contract."""
env = api.Environment(cr, SUPERUSER_ID, {})
m_contract = env["contract.contract"] m_contract = env["contract.contract"]
contracts = m_contract.search([("payment_mode_id", "=", False)]) contracts = m_contract.search([("payment_mode_id", "=", False)])
if contracts: if contracts:

View File

@@ -9,15 +9,19 @@ class ContractContract(models.Model):
string="Payment Mode", string="Payment Mode",
domain=[("payment_type", "=", "inbound")], domain=[("payment_type", "=", "inbound")],
index=True, index=True,
compute="_compute_payment_mode_id",
store=True,
readonly=False,
) )
@api.onchange("partner_id") @api.depends("partner_id", "contract_type")
def on_change_partner_id(self): def _compute_payment_mode_id(self):
partner = self.with_company(self.company_id).partner_id for rec in self:
if self.contract_type == "purchase": partner = rec.with_company(rec.company_id).partner_id
self.payment_mode_id = partner.supplier_payment_mode_id.id if rec.contract_type == "purchase":
rec.payment_mode_id = partner.supplier_payment_mode_id.id
else: else:
self.payment_mode_id = partner.customer_payment_mode_id.id rec.payment_mode_id = partner.customer_payment_mode_id.id
def _prepare_invoice(self, date_invoice, journal=None): def _prepare_invoice(self, date_invoice, journal=None):
invoice_vals = super()._prepare_invoice( invoice_vals = super()._prepare_invoice(

View File

@@ -6,3 +6,7 @@
- Guillermo Llinares \<<guillermo@studio73.es>\> - Guillermo Llinares \<<guillermo@studio73.es>\>
- Amamr Officewala \<<aofficewala@opensourceintegrators.com>\> - Amamr Officewala \<<aofficewala@opensourceintegrators.com>\>
- Carolina Fernandez \<<carolina.fernandez@tecnativa.com>\> - Carolina Fernandez \<<carolina.fernandez@tecnativa.com>\>
- David Jaen <david.jaen.revert@gmail.com>
- Alberto Martínez \<<alberto.martinez@sygel.es>\>
- Harald Panten \<<harald.panten@sygel.es>\>
- Valentin Vinagre \<<valentin.vinagre@sygel.es>\>

View File

@@ -1,11 +1,10 @@
1. Go to *Accounting \> Sales \> Contracts*. 1. Go to *Invoicing \> Customers \> Customer Contracts*.
2. Create one. 2. Create one.
3. Select a partner to which invoice. 3. Select a partner to which invoice.
4. If the partner has a payment mode, this payment mode is selected 4. If the partner has a payment mode, this payment mode is selected
here. here.
5. If not, or if you want another payment mode, you can change it in 5. If not, or if you want another payment mode, you can change it in
the corresponding field. the corresponding field.
6. Click on **Generate recurring invoices automatically** checkbox. 6. Add a product to invoice.
7. Add a product to invoice. 7. If you create an invoice, new invoice will have the selected payment
8. If you create an invoice, new invoice will have the selected payment
mode. mode.

View File

@@ -393,14 +393,13 @@ invoices with this payment mode.</p>
<div class="section" id="usage"> <div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1> <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ol class="arabic simple"> <ol class="arabic simple">
<li>Go to <em>Accounting &gt; Sales &gt; Contracts</em>.</li> <li>Go to <em>Invoicing &gt; Customers &gt; Customer Contracts</em>.</li>
<li>Create one.</li> <li>Create one.</li>
<li>Select a partner to which invoice.</li> <li>Select a partner to which invoice.</li>
<li>If the partner has a payment mode, this payment mode is selected <li>If the partner has a payment mode, this payment mode is selected
here.</li> here.</li>
<li>If not, or if you want another payment mode, you can change it in the <li>If not, or if you want another payment mode, you can change it in the
corresponding field.</li> corresponding field.</li>
<li>Click on <strong>Generate recurring invoices automatically</strong> checkbox.</li>
<li>Add a product to invoice.</li> <li>Add a product to invoice.</li>
<li>If you create an invoice, new invoice will have the selected payment <li>If you create an invoice, new invoice will have the selected payment
mode.</li> mode.</li>
@@ -434,6 +433,10 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Guillermo Llinares &lt;<a class="reference external" href="mailto:guillermo&#64;studio73.es">guillermo&#64;studio73.es</a>&gt;</li> <li>Guillermo Llinares &lt;<a class="reference external" href="mailto:guillermo&#64;studio73.es">guillermo&#64;studio73.es</a>&gt;</li>
<li>Amamr Officewala &lt;<a class="reference external" href="mailto:aofficewala&#64;opensourceintegrators.com">aofficewala&#64;opensourceintegrators.com</a>&gt;</li> <li>Amamr Officewala &lt;<a class="reference external" href="mailto:aofficewala&#64;opensourceintegrators.com">aofficewala&#64;opensourceintegrators.com</a>&gt;</li>
<li>Carolina Fernandez &lt;<a class="reference external" href="mailto:carolina.fernandez&#64;tecnativa.com">carolina.fernandez&#64;tecnativa.com</a>&gt;</li> <li>Carolina Fernandez &lt;<a class="reference external" href="mailto:carolina.fernandez&#64;tecnativa.com">carolina.fernandez&#64;tecnativa.com</a>&gt;</li>
<li>David Jaen <a class="reference external" href="mailto:david.jaen.revert&#64;gmail.com">david.jaen.revert&#64;gmail.com</a></li>
<li>Alberto Martínez &lt;<a class="reference external" href="mailto:alberto.martinez&#64;sygel.es">alberto.martinez&#64;sygel.es</a>&gt;</li>
<li>Harald Panten &lt;<a class="reference external" href="mailto:harald.panten&#64;sygel.es">harald.panten&#64;sygel.es</a>&gt;</li>
<li>Valentin Vinagre &lt;<a class="reference external" href="mailto:valentin.vinagre&#64;sygel.es">valentin.vinagre&#64;sygel.es</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">

View File

@@ -6,8 +6,7 @@
from unittest.mock import patch from unittest.mock import patch
import odoo.tests from odoo.tests import common, tagged
from odoo.tests import tagged
from odoo.addons.account.models.account_payment_method import AccountPaymentMethod 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") @tagged("post_install", "-at_install")
class TestContractPaymentInit(odoo.tests.HttpCase): class TestContractPaymentInit(common.TransactionCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super().setUpClass() super().setUpClass()
@@ -91,12 +90,11 @@ class TestContractPaymentInit(odoo.tests.HttpCase):
contract.payment_mode_id = False contract.payment_mode_id = False
self.assertEqual(contract.payment_mode_id.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) self.assertEqual(contract.payment_mode_id, self.payment_mode)
def test_contract_and_invoices(self): def test_contract_and_invoices(self):
self.contract.write({"partner_id": self.partner.id}) self.contract.write({"partner_id": self.partner.id})
self.contract.on_change_partner_id()
self.assertEqual( self.assertEqual(
self.contract.payment_mode_id, self.contract.payment_mode_id,
self.contract.partner_id.customer_payment_mode_id, self.contract.partner_id.customer_payment_mode_id,