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 ad66f99
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
4 changes: 4 additions & 0 deletions contract_payment_mode/README.rst
Original file line number Diff line number Diff line change
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
7 changes: 5 additions & 2 deletions contract_payment_mode/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ 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):
@api.depends("partner_id")
def _compute_payment_mode_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
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]>\>
4 changes: 4 additions & 0 deletions contract_payment_mode/static/description/index.html
Original file line number Diff line number Diff line change
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
7 changes: 3 additions & 4 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,7 +90,7 @@ 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):
Expand Down

0 comments on commit ad66f99

Please sign in to comment.