-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_payment_sale: migrate from 17 to 18
Now depend on account_payment_base_oca
- Loading branch information
1 parent
ad17ed8
commit 269e06e
Showing
8 changed files
with
117 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
|
||
|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2014-2020 Akretion - Alexis de Lattre | ||
# Copyright 2014-2020 Akretion France (https://www.akretion.com/) | ||
# @author: Alexis de Lattre <[email protected]> | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[email protected]", | ||
"customer_payment_mode_id": cls.payment_mode.id, | ||
"property_inbound_payment_method_line_id": cls.payment_method_line.id, | ||
} | ||
) | ||
cls.products = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
Copyright 2014-2020 Akretion (Alexis de Lattre <[email protected]>) | ||
Copyright 2014-2020 Akretion France (https://www.akretion.com/) | ||
@author: Alexis de Lattre <[email protected]>) | ||
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- | ||
Copyright 2024 Akretion France (https://www.akretion.com/) | ||
@author: Alexis de Lattre <[email protected]> | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters