From 269e06ec2a2a44b420caacce7b412cd5474ea854 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 13 Dec 2024 23:10:35 +0100 Subject: [PATCH] [MIG] account_payment_sale: migrate from 17 to 18 Now depend on account_payment_base_oca --- account_payment_sale/__manifest__.py | 10 ++- account_payment_sale/models/sale_order.py | 44 +++++++------ account_payment_sale/models/sale_report.py | 6 +- account_payment_sale/tests/common.py | 17 ++--- account_payment_sale/tests/test_sale_order.py | 66 ++++++++++--------- .../{sale_order_view.xml => sale_order.xml} | 8 +-- account_payment_sale/views/sale_report.xml | 31 +++++++++ .../views/sale_report_templates.xml | 8 ++- 8 files changed, 117 insertions(+), 73 deletions(-) rename account_payment_sale/views/{sale_order_view.xml => sale_order.xml} (68%) create mode 100644 account_payment_sale/views/sale_report.xml diff --git a/account_payment_sale/__manifest__.py b/account_payment_sale/__manifest__.py index fb83ea75bbe..f3f458626cb 100644 --- a/account_payment_sale/__manifest__.py +++ b/account_payment_sale/__manifest__.py @@ -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 @@ -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, } diff --git a/account_payment_sale/models/sale_order.py b/account_payment_sale/models/sale_order.py index 50d83c70be0..64a69631023 100644 --- a/account_payment_sale/models/sale_order.py +++ b/account_payment_sale/models/sale_order.py @@ -1,4 +1,5 @@ -# Copyright 2014-2020 Akretion - Alexis de Lattre +# Copyright 2014-2020 Akretion France (https://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models @@ -7,9 +8,10 @@ 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 - - def _get_payment_mode_vals(self, vals): - if self.payment_mode_id: - vals["payment_mode_id"] = self.payment_mode_id.id + 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_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 diff --git a/account_payment_sale/models/sale_report.py b/account_payment_sale/models/sale_report.py index 4f80ff456b0..796d12f6268 100644 --- a/account_payment_sale/models/sale_report.py +++ b/account_payment_sale/models/sale_report.py @@ -8,13 +8,13 @@ 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 diff --git a/account_payment_sale/tests/common.py b/account_payment_sale/tests/common.py index e49c8c7bd6c..958379499b1 100644 --- a/account_payment_sale/tests/common.py +++ b/account_payment_sale/tests/common.py @@ -12,7 +12,10 @@ def setUpClass(cls): 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 @@ def setUpClass(cls): "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 = { diff --git a/account_payment_sale/tests/test_sale_order.py b/account_payment_sale/tests/test_sale_order.py index 69f44beddbb..3b03ad1bdc9 100644 --- a/account_payment_sale/tests/test_sale_order.py +++ b/account_payment_sale/tests/test_sale_order.py @@ -14,7 +14,7 @@ def setUpClass(cls): 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 @@ def create_sale_order(self, payment_mode=None): 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 @@ def test_sale_to_invoice_payment_mode_via_payment(self): { "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() diff --git a/account_payment_sale/views/sale_order_view.xml b/account_payment_sale/views/sale_order.xml similarity index 68% rename from account_payment_sale/views/sale_order_view.xml rename to account_payment_sale/views/sale_order.xml index 5696df10485..90ed03d0c17 100644 --- a/account_payment_sale/views/sale_order_view.xml +++ b/account_payment_sale/views/sale_order.xml @@ -1,6 +1,7 @@ @@ -10,10 +11,7 @@ - + diff --git a/account_payment_sale/views/sale_report.xml b/account_payment_sale/views/sale_report.xml new file mode 100644 index 00000000000..f1654ced2cb --- /dev/null +++ b/account_payment_sale/views/sale_report.xml @@ -0,0 +1,31 @@ + + + + + sale.report + + + + + + + + + + sale.report + + + + + + + + diff --git a/account_payment_sale/views/sale_report_templates.xml b/account_payment_sale/views/sale_report_templates.xml index d9e2f8271dc..668ff4807a0 100644 --- a/account_payment_sale/views/sale_report_templates.xml +++ b/account_payment_sale/views/sale_report_templates.xml @@ -6,11 +6,13 @@ position="after" >

Payment Mode: - + Here are the instructions for your payment