Skip to content

Commit 06ecac5

Browse files
[MIG] account_payment_partner: Migration to version 18.0
1 parent f2423e4 commit 06ecac5

6 files changed

Lines changed: 39 additions & 43 deletions

File tree

account_payment_partner/demo/partner_demo.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
<function
44
model="ir.default"
55
name="set"
6-
eval="('res.partner', 'supplier_payment_mode_id', ref('account_payment_mode.payment_mode_outbound_ct1'))"
6+
eval="(
7+
'res.partner',
8+
'supplier_payment_mode_id',
9+
ref('account_payment_mode.payment_mode_outbound_ct1'),
10+
False,
11+
ref('base.main_company')
12+
)"
713
/>
814
<function
915
model="ir.default"
1016
name="set"
11-
eval="('res.partner', 'customer_payment_mode_id', ref('account_payment_mode.payment_mode_inbound_ct1'))"
17+
eval="(
18+
'res.partner',
19+
'customer_payment_mode_id',
20+
ref('account_payment_mode.payment_mode_inbound_ct1'),
21+
False,
22+
ref('base.main_company')
23+
)"
1224
/>
1325
</odoo>

account_payment_partner/models/account_move.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,13 @@ class AccountMove(models.Model):
2121
store=True,
2222
ondelete="restrict",
2323
readonly=False,
24+
precompute=True,
2425
check_company=True,
2526
tracking=True,
2627
)
2728
bank_account_required = fields.Boolean(
2829
related="payment_mode_id.payment_method_id.bank_account_required", readonly=True
2930
)
30-
partner_bank_id = fields.Many2one(
31-
compute="_compute_partner_bank_id",
32-
store=True,
33-
ondelete="restrict",
34-
readonly=False,
35-
)
3631
has_reconciled_items = fields.Boolean(
3732
help="Technical field for supporting the editability of the payment mode",
3833
compute="_compute_has_reconciled_items",
@@ -160,6 +155,7 @@ def partner_banks_to_show(self):
160155
return self.payment_mode_id.variable_journal_ids.mapped(
161156
"bank_account_id"
162157
)
158+
# TODO: move this code to the account_banking_mandate module
163159
if (
164160
self.payment_mode_id.payment_method_id.code == "sepa_direct_debit"
165161
): # pragma: no cover
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Copyright 2021 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import fields, models
4+
from odoo import api, fields, models
5+
from odoo.tools import SQL
56

67

78
class AccountInvoiceReport(models.Model):
@@ -13,6 +14,6 @@ class AccountInvoiceReport(models.Model):
1314
readonly=True,
1415
)
1516

16-
def _select(self):
17-
select_str = super()._select()
18-
return self.env._("%s, move.payment_mode_id AS payment_mode_id") % select_str
17+
@api.model
18+
def _select(self) -> SQL:
19+
return SQL("%s, move.payment_mode_id AS payment_mode_id", super()._select())

account_payment_partner/tests/test_account_payment_partner.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,25 @@
22
# Copyright 2021 Tecnativa - Víctor Martínez
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
44

5-
from odoo import _, fields
5+
from odoo import Command, _, fields
66
from odoo.exceptions import UserError, ValidationError
7-
from odoo.fields import Date
8-
from odoo.tests import Form, TransactionCase, tagged
7+
from odoo.tests import Form, tagged
98

10-
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
9+
from odoo.addons.base.tests.common import BaseCommon
1110

1211

1312
@tagged("-at_install", "post_install")
14-
class TestAccountPaymentPartner(TransactionCase):
13+
class TestAccountPaymentPartner(BaseCommon):
1514
@classmethod
1615
def setUpClass(cls):
1716
super().setUpClass()
18-
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
19-
2017
cls.res_users_model = cls.env["res.users"]
2118
cls.move_model = cls.env["account.move"]
2219
cls.journal_model = cls.env["account.journal"]
2320
cls.payment_mode_model = cls.env["account.payment.mode"]
2421
cls.partner_bank_model = cls.env["res.partner.bank"]
25-
2622
# Refs
2723
cls.company = cls.env.ref("base.main_company")
28-
2924
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
3025
chart = cls.env["account.chart.template"]._guess_chart_template(
3126
cls.company.country_id
@@ -41,7 +36,6 @@ def setUpClass(cls):
4136
cls.manual_out = cls.env.ref("account.account_payment_method_manual_out")
4237
cls.manual_out.bank_account_required = True
4338
cls.manual_in = cls.env.ref("account.account_payment_method_manual_in")
44-
4539
cls.journal_sale = cls.env["account.journal"].create(
4640
{
4741
"name": "Test Sales Journal",
@@ -50,7 +44,6 @@ def setUpClass(cls):
5044
"company_id": cls.company.id,
5145
}
5246
)
53-
5447
cls.journal_purchase = cls.env["account.journal"].create(
5548
{
5649
"name": "Test Purchases Journal",
@@ -59,7 +52,6 @@ def setUpClass(cls):
5952
"company_id": cls.company.id,
6053
}
6154
)
62-
6355
cls.journal_c1 = cls.journal_model.create(
6456
{
6557
"name": "J1",
@@ -69,7 +61,6 @@ def setUpClass(cls):
6961
"bank_acc_number": "123456",
7062
}
7163
)
72-
7364
cls.journal_c2 = cls.journal_model.create(
7465
{
7566
"name": "J2",
@@ -79,7 +70,6 @@ def setUpClass(cls):
7970
"bank_acc_number": "552344",
8071
}
8172
)
82-
8373
cls.supplier_payment_mode = cls.payment_mode_model.create(
8474
{
8575
"name": "Suppliers Bank 1",
@@ -91,7 +81,6 @@ def setUpClass(cls):
9181
"variable_journal_ids": [(6, 0, [cls.journal_c1.id])],
9282
}
9383
)
94-
9584
cls.supplier_payment_mode_c2 = cls.payment_mode_model.create(
9685
{
9786
"name": "Suppliers Bank 2",
@@ -102,7 +91,6 @@ def setUpClass(cls):
10291
"variable_journal_ids": [(6, 0, [cls.journal_c2.id])],
10392
}
10493
)
105-
10694
cls.customer_payment_mode = cls.payment_mode_model.create(
10795
{
10896
"name": "Customers to Bank 1",
@@ -117,7 +105,6 @@ def setUpClass(cls):
117105
cls.supplier_payment_mode.write(
118106
{"refund_payment_mode_id": cls.customer_payment_mode.id}
119107
)
120-
121108
cls.customer = (
122109
cls.env["res.partner"]
123110
.with_company(cls.company.id)
@@ -128,7 +115,6 @@ def setUpClass(cls):
128115
}
129116
)
130117
)
131-
132118
cls.supplier = (
133119
cls.env["res.partner"]
134120
.with_company(cls.company.id)
@@ -148,18 +134,17 @@ def setUpClass(cls):
148134
cls.supplier.with_company(
149135
cls.company_2.id
150136
).supplier_payment_mode_id = cls.supplier_payment_mode_c2
151-
152137
cls.invoice_account = cls.env["account.account"].search(
153138
[
154139
("account_type", "=", "liability_payable"),
155-
("company_id", "in", cls.company.id),
140+
("company_ids", "in", cls.company.ids),
156141
],
157142
limit=1,
158143
)
159144
cls.invoice_line_account = cls.env["account.account"].search(
160145
[
161146
("account_type", "=", "expense"),
162-
("company_id", "in", cls.company.id),
147+
("company_ids", "in", cls.company.ids),
163148
],
164149
limit=1,
165150
)
@@ -212,7 +197,7 @@ def _create_invoice(self, default_move_type, partner):
212197
self.env["account.move"].with_context(default_move_type=default_move_type)
213198
)
214199
move_form.partner_id = partner
215-
move_form.invoice_date = Date.today()
200+
move_form.invoice_date = fields.Date.today()
216201
with move_form.invoice_line_ids.new() as line_form:
217202
line_form.product_id = self.product
218203
line_form.name = "product that cost 100"
@@ -351,9 +336,7 @@ def test_payment_mode_constrains_02(self):
351336
"ref": "reference",
352337
"state": "draft",
353338
"invoice_line_ids": [
354-
(
355-
0,
356-
0,
339+
Command.create(
357340
{
358341
"account_id": self.invoice_account.id,
359342
"credit": 1000,
@@ -362,9 +345,7 @@ def test_payment_mode_constrains_02(self):
362345
"ref": "reference",
363346
},
364347
),
365-
(
366-
0,
367-
0,
348+
Command.create(
368349
{
369350
"account_id": self.invoice_line_account.id,
370351
"credit": 0,

account_payment_partner/views/account_move_line.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
name="payment_mode_id"
3232
optional="hide"
3333
force_save="1"
34-
invisible="account_type not in ['asset_receivable', 'liability_payable']"
34+
column_invisible="account_type not in ['asset_receivable', 'liability_payable']"
3535
readonly="account_type not in ['asset_receivable', 'liability_payable'] or reconciled"
3636
/>
3737
</field>

account_payment_partner/views/res_partner_view.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
<field name="inherit_id" ref="account.view_partner_property_form" />
1111
<field name="arch" type="xml">
1212
<field name="property_payment_term_id" position="after">
13-
<field name="customer_payment_mode_id" widget="selection" />
13+
<field
14+
name="customer_payment_mode_id"
15+
options="{'no_open': True, 'no_create': True}"
16+
/>
1417
</field>
1518
<field name="property_supplier_payment_term_id" position="after">
16-
<field name="supplier_payment_mode_id" widget="selection" />
19+
<field
20+
name="supplier_payment_mode_id"
21+
options="{'no_open': True, 'no_create': True}"
22+
/>
1723
</field>
1824
</field>
1925
</record>

0 commit comments

Comments
 (0)