mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[MIG] account_payment_sale: migrate from 17 to 18
Now depend on account_payment_base_oca
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2014-2016 Akretion (http://www.akretion.com)
|
||||
# Copyright 2014-2016 Akretion France (https://www.akretion.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
"summary": "Adds payment mode on sale orders",
|
||||
"author": "Akretion, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/bank-payment",
|
||||
"depends": ["sale", "account_payment_partner"],
|
||||
"data": ["views/sale_order_view.xml", "views/sale_report_templates.xml"],
|
||||
"depends": ["sale", "account_payment_base_oca"],
|
||||
"data": [
|
||||
"views/sale_order.xml",
|
||||
"views/sale_report.xml",
|
||||
"views/sale_report_templates.xml",
|
||||
],
|
||||
"auto_install": True,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Copyright 2014-2020 Akretion - Alexis de Lattre
|
||||
# Copyright 2014-2020 Akretion France (https://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
@@ -7,9 +8,10 @@ from odoo import api, fields, models
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
payment_mode_id = fields.Many2one(
|
||||
comodel_name="account.payment.mode",
|
||||
compute="_compute_payment_mode",
|
||||
payment_method_line_id = fields.Many2one(
|
||||
comodel_name="account.payment.method.line",
|
||||
compute="_compute_payment_method_line_id",
|
||||
string="Payment Mode",
|
||||
store=True,
|
||||
readonly=False,
|
||||
precompute=True,
|
||||
@@ -18,37 +20,37 @@ class SaleOrder(models.Model):
|
||||
)
|
||||
|
||||
@api.depends("partner_id")
|
||||
def _compute_payment_mode(self):
|
||||
def _compute_payment_method_line_id(self):
|
||||
for order in self:
|
||||
if order.partner_id:
|
||||
order.payment_mode_id = order.partner_id.customer_payment_mode_id
|
||||
else:
|
||||
order.payment_mode_id = False
|
||||
payment_method_line = False
|
||||
if order.partner_id and order.company_id:
|
||||
payment_method_line = order.with_company(
|
||||
order.company_id
|
||||
).partner_id.property_inbound_payment_method_line_id
|
||||
order.payment_method_line_id = payment_method_line
|
||||
|
||||
def _get_payment_mode_vals(self, vals):
|
||||
if self.payment_mode_id:
|
||||
vals["payment_mode_id"] = self.payment_mode_id.id
|
||||
def _get_payment_method_line_vals(self, vals):
|
||||
if self.payment_method_line_id:
|
||||
vals["preferred_payment_method_line_id"] = self.payment_method_line_id.id
|
||||
if (
|
||||
self.payment_mode_id.bank_account_link == "fixed"
|
||||
and self.payment_mode_id.payment_method_id.code == "manual"
|
||||
self.payment_method_line_id.bank_account_link == "fixed"
|
||||
and self.payment_method_line_id.payment_method_id.code == "manual"
|
||||
):
|
||||
vals["partner_bank_id"] = (
|
||||
self.payment_mode_id.fixed_journal_id.bank_account_id.id
|
||||
self.payment_method_line_id.journal_id.bank_account_id.id
|
||||
)
|
||||
|
||||
def _prepare_invoice(self):
|
||||
"""Copy bank partner from sale order to invoice"""
|
||||
vals = super()._prepare_invoice()
|
||||
self._get_payment_mode_vals(vals)
|
||||
self._get_payment_method_line_vals(vals)
|
||||
return vals
|
||||
|
||||
@api.model
|
||||
def _get_invoice_grouping_keys(self) -> list:
|
||||
"""
|
||||
When several sale orders are generating invoices,
|
||||
we want to add the payment mode in grouping criteria.
|
||||
"""
|
||||
keys = super()._get_invoice_grouping_keys()
|
||||
if "payment_mode_id" not in keys:
|
||||
keys.append("payment_mode_id")
|
||||
if "preferred_payment_method_line_id" not in keys:
|
||||
keys.append("preferred_payment_method_line_id")
|
||||
return keys
|
||||
|
||||
@@ -8,13 +8,13 @@ from odoo import fields, models
|
||||
class SaleReport(models.Model):
|
||||
_inherit = "sale.report"
|
||||
|
||||
payment_mode_id = fields.Many2one(
|
||||
"account.payment.mode",
|
||||
payment_method_line_id = fields.Many2one(
|
||||
"account.payment.method.line",
|
||||
string="Payment Mode",
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
def _select_additional_fields(self):
|
||||
res = super()._select_additional_fields()
|
||||
res["payment_mode_id"] = "s.payment_mode_id"
|
||||
res["payment_method_line_id"] = "s.payment_method_line_id"
|
||||
return res
|
||||
|
||||
@@ -12,7 +12,10 @@ class CommonTestCase(TransactionCase):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
|
||||
cls.bank = cls.env["res.partner.bank"].create(
|
||||
{"acc_number": "test", "partner_id": cls.env.user.company_id.partner_id.id}
|
||||
{
|
||||
"acc_number": "FR66 1234 5678 1212 6363 3636 098",
|
||||
"partner_id": cls.env.ref("base.main_company").id,
|
||||
}
|
||||
)
|
||||
cls.journal = cls.env["account.journal"].create(
|
||||
{
|
||||
@@ -23,33 +26,31 @@ class CommonTestCase(TransactionCase):
|
||||
"bank_account_id": cls.bank.id,
|
||||
}
|
||||
)
|
||||
cls.payment_mode = cls.env["account.payment.mode"].create(
|
||||
cls.payment_method_line = cls.env["account.payment.method.line"].create(
|
||||
{
|
||||
"name": "test_mode",
|
||||
"active": True,
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_in"
|
||||
).id,
|
||||
"bank_account_link": "fixed",
|
||||
"fixed_journal_id": cls.journal.id,
|
||||
"journal_id": cls.journal.id,
|
||||
}
|
||||
)
|
||||
cls.payment_mode_2 = cls.env["account.payment.mode"].create(
|
||||
cls.payment_method_line_2 = cls.env["account.payment.method.line"].create(
|
||||
{
|
||||
"name": "test_mode_2",
|
||||
"active": True,
|
||||
"payment_method_id": cls.env.ref(
|
||||
"account.account_payment_method_manual_in"
|
||||
).id,
|
||||
"bank_account_link": "fixed",
|
||||
"fixed_journal_id": cls.journal.id,
|
||||
"journal_id": cls.journal.id,
|
||||
}
|
||||
)
|
||||
cls.base_partner = cls.env["res.partner"].create(
|
||||
{
|
||||
"name": "Dummy",
|
||||
"email": "dummy@example.com",
|
||||
"customer_payment_mode_id": cls.payment_mode.id,
|
||||
"property_inbound_payment_method_line_id": cls.payment_method_line.id,
|
||||
}
|
||||
)
|
||||
cls.products = {
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestSaleOrder(CommonTestCase):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
|
||||
|
||||
def create_sale_order(self, payment_mode=None):
|
||||
def create_sale_order(self, payment_method_line=None):
|
||||
with Form(self.env["sale.order"]) as sale_form:
|
||||
sale_form.partner_id = self.base_partner
|
||||
for _, p in self.products.items():
|
||||
@@ -26,62 +26,65 @@ class TestSaleOrder(CommonTestCase):
|
||||
order_line.price_unit = p.list_price
|
||||
sale = sale_form.save()
|
||||
self.assertEqual(
|
||||
sale.payment_mode_id, self.base_partner.customer_payment_mode_id
|
||||
sale.payment_method_line_id,
|
||||
self.base_partner.property_inbound_payment_method_line_id,
|
||||
)
|
||||
sale_form = Form(sale)
|
||||
|
||||
# force payment mode
|
||||
if payment_mode:
|
||||
sale_form.payment_mode_id = payment_mode
|
||||
if payment_method_line:
|
||||
sale_form.payment_method_line_id = payment_method_line
|
||||
return sale_form.save()
|
||||
|
||||
def create_invoice_and_check(
|
||||
self, order, expected_payment_mode, expected_partner_bank
|
||||
self, order, expected_payment_method_line, expected_partner_bank
|
||||
):
|
||||
order.action_confirm()
|
||||
order._create_invoices()
|
||||
invoice = order.invoice_ids
|
||||
self.assertEqual(len(invoice), 1)
|
||||
self.assertEqual(invoice.payment_mode_id, expected_payment_mode)
|
||||
self.assertEqual(
|
||||
invoice.preferred_payment_method_line_id, expected_payment_method_line
|
||||
)
|
||||
self.assertEqual(invoice.partner_bank_id, expected_partner_bank)
|
||||
|
||||
def test_sale_to_invoice_payment_mode(self):
|
||||
def test_sale_to_invoice_payment_method_line(self):
|
||||
"""
|
||||
Data:
|
||||
A partner with a specific payment_mode
|
||||
A sale order created with the payment_mode of the partner
|
||||
A partner with a specific payment_method_line
|
||||
A sale order created with the payment_method_line of the partner
|
||||
Test case:
|
||||
Create the invoice from the sale order
|
||||
Expected result:
|
||||
The invoice must be created with the payment_mode of the partner
|
||||
The invoice must be created with the payment_method_line of the partner
|
||||
"""
|
||||
order = self.create_sale_order()
|
||||
self.create_invoice_and_check(order, self.payment_mode, self.bank)
|
||||
self.create_invoice_and_check(order, self.payment_method_line, self.bank)
|
||||
|
||||
def test_sale_to_invoice_payment_mode_2(self):
|
||||
def test_sale_to_invoice_payment_method_line_2(self):
|
||||
"""
|
||||
Data:
|
||||
A partner with a specific payment_mode
|
||||
A sale order created with an other payment_mode
|
||||
A partner with a specific payment_method_line
|
||||
A sale order created with an other payment_method_line
|
||||
Test case:
|
||||
Create the invoice from the sale order
|
||||
Expected result:
|
||||
The invoice must be created with the specific payment_mode
|
||||
The invoice must be created with the specific payment_method_line
|
||||
"""
|
||||
order = self.create_sale_order(payment_mode=self.payment_mode_2)
|
||||
self.create_invoice_and_check(order, self.payment_mode_2, self.bank)
|
||||
order = self.create_sale_order(payment_method_line=self.payment_method_line_2)
|
||||
self.create_invoice_and_check(order, self.payment_method_line_2, self.bank)
|
||||
|
||||
def test_sale_to_invoice_payment_mode_via_payment(self):
|
||||
def test_sale_to_invoice_payment_method_line_via_payment(self):
|
||||
"""
|
||||
Data:
|
||||
A partner with a specific payment_mode
|
||||
A sale order created with an other payment_mode
|
||||
A partner with a specific payment_method_line
|
||||
A sale order created with an other payment_method_line
|
||||
Test case:
|
||||
Create the invoice from sale.advance.payment.inv
|
||||
Expected result:
|
||||
The invoice must be created with the specific payment_mode
|
||||
The invoice must be created with the specific payment_method_line
|
||||
"""
|
||||
order = self.create_sale_order(payment_mode=self.payment_mode_2)
|
||||
order = self.create_sale_order(payment_method_line=self.payment_method_line_2)
|
||||
context = {
|
||||
"active_model": "sale.order",
|
||||
"active_ids": [order.id],
|
||||
@@ -92,30 +95,33 @@ class TestSaleOrder(CommonTestCase):
|
||||
{
|
||||
"advance_payment_method": "fixed",
|
||||
"fixed_amount": 5,
|
||||
"product_id": self.env.ref("sale.advance_product_0").id,
|
||||
"sale_order_ids": order,
|
||||
}
|
||||
)
|
||||
payment.with_context(**context).create_invoices()
|
||||
invoice = order.invoice_ids
|
||||
self.assertEqual(len(invoice), 1)
|
||||
self.assertEqual(invoice.payment_mode_id, self.payment_mode_2)
|
||||
self.assertFalse(invoice.partner_bank_id)
|
||||
self.assertEqual(
|
||||
invoice.preferred_payment_method_line_id, self.payment_method_line_2
|
||||
)
|
||||
self.assertEqual(
|
||||
invoice.partner_bank_id,
|
||||
self.payment_method_line_2.journal_id.bank_account_id,
|
||||
)
|
||||
|
||||
def test_several_sale_to_invoice_payment_mode(self):
|
||||
def test_several_sale_to_invoice_payment_method_line(self):
|
||||
"""
|
||||
Data:
|
||||
A partner with a specific payment_mode
|
||||
A sale order created with the payment_mode of the partner
|
||||
A partner with a specific payment_method_line
|
||||
A sale order created with the payment_method_line of the partner
|
||||
A sale order created with another payment mode
|
||||
Test case:
|
||||
Create the invoice from the sale orders
|
||||
Expected result:
|
||||
Two invoices should be generated
|
||||
"""
|
||||
payment_mode_2 = self.env.ref("account_payment_mode.payment_mode_outbound_dd1")
|
||||
order_1 = self.create_sale_order()
|
||||
order_2 = self.create_sale_order(payment_mode_2)
|
||||
order_2 = self.create_sale_order(self.payment_method_line_2)
|
||||
orders = order_1 | order_2
|
||||
orders.action_confirm()
|
||||
invoices = orders._create_invoices()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2014-2020 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
Copyright 2014-2020 Akretion France (https://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
@@ -10,10 +11,7 @@
|
||||
<field name="inherit_id" ref="sale.view_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="payment_term_id" position="after">
|
||||
<field
|
||||
name="payment_mode_id"
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
/>
|
||||
<field name="payment_method_line_id" options="{'no_create': True}" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
31
account_payment_sale/views/sale_report.xml
Normal file
31
account_payment_sale/views/sale_report.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2024 Akretion France (https://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
<record id="sale_report_view_tree" model="ir.ui.view">
|
||||
<field name="model">sale.report</field>
|
||||
<field name="inherit_id" ref="sale.sale_report_view_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="pricelist_id" position="after">
|
||||
<field name="payment_method_line_id" optional="hide" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_order_product_search" model="ir.ui.view">
|
||||
<field name="model">sale.report</field>
|
||||
<field name="inherit_id" ref="sale.view_order_product_search" />
|
||||
<field name="arch" type="xml">
|
||||
<filter name="industry_id" position="after">
|
||||
<filter
|
||||
name="payment_method_line_groupby"
|
||||
string="Payment Mode"
|
||||
context="{'group_by': 'payment_method_line_id'}"
|
||||
/>
|
||||
</filter>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -6,11 +6,13 @@
|
||||
position="after"
|
||||
>
|
||||
<p
|
||||
t-if="not is_html_empty(doc.payment_mode_id.note)"
|
||||
id="payment_mode_note"
|
||||
t-if="not is_html_empty(doc.payment_method_line_id.report_description)"
|
||||
id="payment_method_line_desc"
|
||||
>
|
||||
<strong>Payment Mode:</strong>
|
||||
<span t-field="doc.payment_mode_id.note" />
|
||||
<span
|
||||
t-field="doc.payment_method_line_id.report_description"
|
||||
>Here are the instructions for your payment</span>
|
||||
</p>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user