Skip to content

Commit

Permalink
[MIG] contract_payment_mode: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tisho99 committed Aug 11, 2024
1 parent 850fd78 commit 369a627
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
6 changes: 5 additions & 1 deletion contract_payment_mode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +86,10 @@ Contributors
- Guillermo Llinares <[email protected]>
- Amamr Officewala <[email protected]>
- Carolina Fernandez <[email protected]>
- David Jaen [email protected]
- Alberto Martínez <[email protected]>
- Harald Panten <[email protected]>
- Valentin Vinagre <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion contract_payment_mode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
5 changes: 1 addition & 4 deletions contract_payment_mode/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 11 additions & 7 deletions contract_payment_mode/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 22 in contract_payment_mode/models/contract.py

View check run for this annotation

Codecov / codecov/patch

contract_payment_mode/models/contract.py#L22

Added line #L22 was not covered by tests
else:
rec.payment_mode_id = partner.customer_payment_mode_id.id

def _prepare_invoice(self, date_invoice, journal=None):
invoice_vals = super()._prepare_invoice(
Expand Down
4 changes: 4 additions & 0 deletions contract_payment_mode/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
- Guillermo Llinares \<<[email protected]>\>
- Amamr Officewala \<<[email protected]>\>
- Carolina Fernandez \<<[email protected]>\>
- David Jaen <[email protected]>
- Alberto Martínez \<<[email protected]>\>
- Harald Panten \<<[email protected]>\>
- Valentin Vinagre \<<[email protected]>\>
2 changes: 1 addition & 1 deletion contract_payment_mode/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion contract_payment_mode/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<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>Select a partner to which invoice.</li>
<li>If the partner has a payment mode, this payment mode is selected
Expand Down Expand Up @@ -434,6 +434,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<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>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>
</div>
<div class="section" id="maintainers">
Expand Down
8 changes: 3 additions & 5 deletions contract_payment_mode/tests/test_contract_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

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

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()
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 369a627

Please sign in to comment.