Skip to content

Commit 269e06e

Browse files
committed
[MIG] account_payment_sale: migrate from 17 to 18
Now depend on account_payment_base_oca
1 parent ad17ed8 commit 269e06e

File tree

8 files changed

+117
-73
lines changed

8 files changed

+117
-73
lines changed

account_payment_sale/__manifest__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2016 Akretion (http://www.akretion.com)
1+
# Copyright 2014-2016 Akretion France (https://www.akretion.com)
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
# @author Alexis de Lattre <[email protected]>
44

@@ -10,7 +10,11 @@
1010
"summary": "Adds payment mode on sale orders",
1111
"author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)",
1212
"website": "https://github.com/OCA/bank-payment",
13-
"depends": ["sale", "account_payment_partner"],
14-
"data": ["views/sale_order_view.xml", "views/sale_report_templates.xml"],
13+
"depends": ["sale", "account_payment_base_oca"],
14+
"data": [
15+
"views/sale_order.xml",
16+
"views/sale_report.xml",
17+
"views/sale_report_templates.xml",
18+
],
1519
"auto_install": True,
1620
}
+23-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Copyright 2014-2020 Akretion - Alexis de Lattre
1+
# Copyright 2014-2020 Akretion France (https://www.akretion.com/)
2+
# @author: Alexis de Lattre <[email protected]>
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
34

45
from odoo import api, fields, models
@@ -7,9 +8,10 @@
78
class SaleOrder(models.Model):
89
_inherit = "sale.order"
910

10-
payment_mode_id = fields.Many2one(
11-
comodel_name="account.payment.mode",
12-
compute="_compute_payment_mode",
11+
payment_method_line_id = fields.Many2one(
12+
comodel_name="account.payment.method.line",
13+
compute="_compute_payment_method_line_id",
14+
string="Payment Mode",
1315
store=True,
1416
readonly=False,
1517
precompute=True,
@@ -18,37 +20,37 @@ class SaleOrder(models.Model):
1820
)
1921

2022
@api.depends("partner_id")
21-
def _compute_payment_mode(self):
23+
def _compute_payment_method_line_id(self):
2224
for order in self:
23-
if order.partner_id:
24-
order.payment_mode_id = order.partner_id.customer_payment_mode_id
25-
else:
26-
order.payment_mode_id = False
27-
28-
def _get_payment_mode_vals(self, vals):
29-
if self.payment_mode_id:
30-
vals["payment_mode_id"] = self.payment_mode_id.id
25+
payment_method_line = False
26+
if order.partner_id and order.company_id:
27+
payment_method_line = order.with_company(
28+
order.company_id
29+
).partner_id.property_inbound_payment_method_line_id
30+
order.payment_method_line_id = payment_method_line
31+
32+
def _get_payment_method_line_vals(self, vals):
33+
if self.payment_method_line_id:
34+
vals["preferred_payment_method_line_id"] = self.payment_method_line_id.id
3135
if (
32-
self.payment_mode_id.bank_account_link == "fixed"
33-
and self.payment_mode_id.payment_method_id.code == "manual"
36+
self.payment_method_line_id.bank_account_link == "fixed"
37+
and self.payment_method_line_id.payment_method_id.code == "manual"
3438
):
3539
vals["partner_bank_id"] = (
36-
self.payment_mode_id.fixed_journal_id.bank_account_id.id
40+
self.payment_method_line_id.journal_id.bank_account_id.id
3741
)
3842

3943
def _prepare_invoice(self):
40-
"""Copy bank partner from sale order to invoice"""
4144
vals = super()._prepare_invoice()
42-
self._get_payment_mode_vals(vals)
45+
self._get_payment_method_line_vals(vals)
4346
return vals
4447

45-
@api.model
4648
def _get_invoice_grouping_keys(self) -> list:
4749
"""
4850
When several sale orders are generating invoices,
4951
we want to add the payment mode in grouping criteria.
5052
"""
5153
keys = super()._get_invoice_grouping_keys()
52-
if "payment_mode_id" not in keys:
53-
keys.append("payment_mode_id")
54+
if "preferred_payment_method_line_id" not in keys:
55+
keys.append("preferred_payment_method_line_id")
5456
return keys

account_payment_sale/models/sale_report.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class SaleReport(models.Model):
99
_inherit = "sale.report"
1010

11-
payment_mode_id = fields.Many2one(
12-
"account.payment.mode",
11+
payment_method_line_id = fields.Many2one(
12+
"account.payment.method.line",
1313
string="Payment Mode",
1414
readonly=True,
1515
)
1616

1717
def _select_additional_fields(self):
1818
res = super()._select_additional_fields()
19-
res["payment_mode_id"] = "s.payment_mode_id"
19+
res["payment_method_line_id"] = "s.payment_method_line_id"
2020
return res

account_payment_sale/tests/common.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ def setUpClass(cls):
1212
super().setUpClass()
1313
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
1414
cls.bank = cls.env["res.partner.bank"].create(
15-
{"acc_number": "test", "partner_id": cls.env.user.company_id.partner_id.id}
15+
{
16+
"acc_number": "FR66 1234 5678 1212 6363 3636 098",
17+
"partner_id": cls.env.ref("base.main_company").id,
18+
}
1619
)
1720
cls.journal = cls.env["account.journal"].create(
1821
{
@@ -23,33 +26,31 @@ def setUpClass(cls):
2326
"bank_account_id": cls.bank.id,
2427
}
2528
)
26-
cls.payment_mode = cls.env["account.payment.mode"].create(
29+
cls.payment_method_line = cls.env["account.payment.method.line"].create(
2730
{
2831
"name": "test_mode",
29-
"active": True,
3032
"payment_method_id": cls.env.ref(
3133
"account.account_payment_method_manual_in"
3234
).id,
3335
"bank_account_link": "fixed",
34-
"fixed_journal_id": cls.journal.id,
36+
"journal_id": cls.journal.id,
3537
}
3638
)
37-
cls.payment_mode_2 = cls.env["account.payment.mode"].create(
39+
cls.payment_method_line_2 = cls.env["account.payment.method.line"].create(
3840
{
3941
"name": "test_mode_2",
40-
"active": True,
4142
"payment_method_id": cls.env.ref(
4243
"account.account_payment_method_manual_in"
4344
).id,
4445
"bank_account_link": "fixed",
45-
"fixed_journal_id": cls.journal.id,
46+
"journal_id": cls.journal.id,
4647
}
4748
)
4849
cls.base_partner = cls.env["res.partner"].create(
4950
{
5051
"name": "Dummy",
5152
"email": "[email protected]",
52-
"customer_payment_mode_id": cls.payment_mode.id,
53+
"property_inbound_payment_method_line_id": cls.payment_method_line.id,
5354
}
5455
)
5556
cls.products = {

account_payment_sale/tests/test_sale_order.py

+36-30
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def setUpClass(cls):
1414
super().setUpClass()
1515
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
1616

17-
def create_sale_order(self, payment_mode=None):
17+
def create_sale_order(self, payment_method_line=None):
1818
with Form(self.env["sale.order"]) as sale_form:
1919
sale_form.partner_id = self.base_partner
2020
for _, p in self.products.items():
@@ -26,62 +26,65 @@ def create_sale_order(self, payment_mode=None):
2626
order_line.price_unit = p.list_price
2727
sale = sale_form.save()
2828
self.assertEqual(
29-
sale.payment_mode_id, self.base_partner.customer_payment_mode_id
29+
sale.payment_method_line_id,
30+
self.base_partner.property_inbound_payment_method_line_id,
3031
)
3132
sale_form = Form(sale)
3233

3334
# force payment mode
34-
if payment_mode:
35-
sale_form.payment_mode_id = payment_mode
35+
if payment_method_line:
36+
sale_form.payment_method_line_id = payment_method_line
3637
return sale_form.save()
3738

3839
def create_invoice_and_check(
39-
self, order, expected_payment_mode, expected_partner_bank
40+
self, order, expected_payment_method_line, expected_partner_bank
4041
):
4142
order.action_confirm()
4243
order._create_invoices()
4344
invoice = order.invoice_ids
4445
self.assertEqual(len(invoice), 1)
45-
self.assertEqual(invoice.payment_mode_id, expected_payment_mode)
46+
self.assertEqual(
47+
invoice.preferred_payment_method_line_id, expected_payment_method_line
48+
)
4649
self.assertEqual(invoice.partner_bank_id, expected_partner_bank)
4750

48-
def test_sale_to_invoice_payment_mode(self):
51+
def test_sale_to_invoice_payment_method_line(self):
4952
"""
5053
Data:
51-
A partner with a specific payment_mode
52-
A sale order created with the payment_mode of the partner
54+
A partner with a specific payment_method_line
55+
A sale order created with the payment_method_line of the partner
5356
Test case:
5457
Create the invoice from the sale order
5558
Expected result:
56-
The invoice must be created with the payment_mode of the partner
59+
The invoice must be created with the payment_method_line of the partner
5760
"""
5861
order = self.create_sale_order()
59-
self.create_invoice_and_check(order, self.payment_mode, self.bank)
62+
self.create_invoice_and_check(order, self.payment_method_line, self.bank)
6063

61-
def test_sale_to_invoice_payment_mode_2(self):
64+
def test_sale_to_invoice_payment_method_line_2(self):
6265
"""
6366
Data:
64-
A partner with a specific payment_mode
65-
A sale order created with an other payment_mode
67+
A partner with a specific payment_method_line
68+
A sale order created with an other payment_method_line
6669
Test case:
6770
Create the invoice from the sale order
6871
Expected result:
69-
The invoice must be created with the specific payment_mode
72+
The invoice must be created with the specific payment_method_line
7073
"""
71-
order = self.create_sale_order(payment_mode=self.payment_mode_2)
72-
self.create_invoice_and_check(order, self.payment_mode_2, self.bank)
74+
order = self.create_sale_order(payment_method_line=self.payment_method_line_2)
75+
self.create_invoice_and_check(order, self.payment_method_line_2, self.bank)
7376

74-
def test_sale_to_invoice_payment_mode_via_payment(self):
77+
def test_sale_to_invoice_payment_method_line_via_payment(self):
7578
"""
7679
Data:
77-
A partner with a specific payment_mode
78-
A sale order created with an other payment_mode
80+
A partner with a specific payment_method_line
81+
A sale order created with an other payment_method_line
7982
Test case:
8083
Create the invoice from sale.advance.payment.inv
8184
Expected result:
82-
The invoice must be created with the specific payment_mode
85+
The invoice must be created with the specific payment_method_line
8386
"""
84-
order = self.create_sale_order(payment_mode=self.payment_mode_2)
87+
order = self.create_sale_order(payment_method_line=self.payment_method_line_2)
8588
context = {
8689
"active_model": "sale.order",
8790
"active_ids": [order.id],
@@ -92,30 +95,33 @@ def test_sale_to_invoice_payment_mode_via_payment(self):
9295
{
9396
"advance_payment_method": "fixed",
9497
"fixed_amount": 5,
95-
"product_id": self.env.ref("sale.advance_product_0").id,
9698
"sale_order_ids": order,
9799
}
98100
)
99101
payment.with_context(**context).create_invoices()
100102
invoice = order.invoice_ids
101103
self.assertEqual(len(invoice), 1)
102-
self.assertEqual(invoice.payment_mode_id, self.payment_mode_2)
103-
self.assertFalse(invoice.partner_bank_id)
104+
self.assertEqual(
105+
invoice.preferred_payment_method_line_id, self.payment_method_line_2
106+
)
107+
self.assertEqual(
108+
invoice.partner_bank_id,
109+
self.payment_method_line_2.journal_id.bank_account_id,
110+
)
104111

105-
def test_several_sale_to_invoice_payment_mode(self):
112+
def test_several_sale_to_invoice_payment_method_line(self):
106113
"""
107114
Data:
108-
A partner with a specific payment_mode
109-
A sale order created with the payment_mode of the partner
115+
A partner with a specific payment_method_line
116+
A sale order created with the payment_method_line of the partner
110117
A sale order created with another payment mode
111118
Test case:
112119
Create the invoice from the sale orders
113120
Expected result:
114121
Two invoices should be generated
115122
"""
116-
payment_mode_2 = self.env.ref("account_payment_mode.payment_mode_outbound_dd1")
117123
order_1 = self.create_sale_order()
118-
order_2 = self.create_sale_order(payment_mode_2)
124+
order_2 = self.create_sale_order(self.payment_method_line_2)
119125
orders = order_1 | order_2
120126
orders.action_confirm()
121127
invoices = orders._create_invoices()

account_payment_sale/views/sale_order_view.xml renamed to account_payment_sale/views/sale_order.xml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<!--
3-
Copyright 2014-2020 Akretion (Alexis de Lattre <[email protected]>)
3+
Copyright 2014-2020 Akretion France (https://www.akretion.com/)
4+
@author: Alexis de Lattre <[email protected]>)
45
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
56
-->
67
<odoo>
@@ -10,10 +11,7 @@
1011
<field name="inherit_id" ref="sale.view_order_form" />
1112
<field name="arch" type="xml">
1213
<field name="payment_term_id" position="after">
13-
<field
14-
name="payment_mode_id"
15-
options="{'no_open': True, 'no_create': True}"
16-
/>
14+
<field name="payment_method_line_id" options="{'no_create': True}" />
1715
</field>
1816
</field>
1917
</record>
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
Copyright 2024 Akretion France (https://www.akretion.com/)
4+
@author: Alexis de Lattre <[email protected]>
5+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
6+
-->
7+
<odoo>
8+
<record id="sale_report_view_tree" model="ir.ui.view">
9+
<field name="model">sale.report</field>
10+
<field name="inherit_id" ref="sale.sale_report_view_tree" />
11+
<field name="arch" type="xml">
12+
<field name="pricelist_id" position="after">
13+
<field name="payment_method_line_id" optional="hide" />
14+
</field>
15+
</field>
16+
</record>
17+
18+
<record id="view_order_product_search" model="ir.ui.view">
19+
<field name="model">sale.report</field>
20+
<field name="inherit_id" ref="sale.view_order_product_search" />
21+
<field name="arch" type="xml">
22+
<filter name="industry_id" position="after">
23+
<filter
24+
name="payment_method_line_groupby"
25+
string="Payment Mode"
26+
context="{'group_by': 'payment_method_line_id'}"
27+
/>
28+
</filter>
29+
</field>
30+
</record>
31+
</odoo>

account_payment_sale/views/sale_report_templates.xml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
position="after"
77
>
88
<p
9-
t-if="not is_html_empty(doc.payment_mode_id.note)"
10-
id="payment_mode_note"
9+
t-if="not is_html_empty(doc.payment_method_line_id.report_description)"
10+
id="payment_method_line_desc"
1111
>
1212
<strong>Payment Mode:</strong>
13-
<span t-field="doc.payment_mode_id.note" />
13+
<span
14+
t-field="doc.payment_method_line_id.report_description"
15+
>Here are the instructions for your payment</span>
1416
</p>
1517
</xpath>
1618
</template>

0 commit comments

Comments
 (0)