mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
account_banking_mandate_sale: improve migration to v16
Remove inherit of sale.advance.payment.inv: no need to inherit _prepare_invoice_values() because it calls _prepare_invoice() from the sale.order object
This commit is contained in:
@@ -1,2 +1 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -14,10 +14,12 @@ class SaleOrder(models.Model):
|
||||
)
|
||||
mandate_id = fields.Many2one(
|
||||
"account.banking.mandate",
|
||||
compute="_compute_mandate_id",
|
||||
string="Direct Debit Mandate",
|
||||
ondelete="restrict",
|
||||
check_company=True,
|
||||
readonly=False,
|
||||
store=True,
|
||||
domain="[('partner_id', '=', commercial_invoice_partner_id), "
|
||||
"('state', 'in', ('draft', 'valid')), "
|
||||
"('company_id', '=', company_id)]",
|
||||
@@ -33,13 +35,16 @@ class SaleOrder(models.Model):
|
||||
vals["mandate_id"] = self.mandate_id.id
|
||||
return vals
|
||||
|
||||
@api.depends("partner_invoice_id")
|
||||
def _compute_payment_mode(self):
|
||||
@api.depends("partner_invoice_id", "payment_mode_id")
|
||||
def _compute_mandate_id(self):
|
||||
"""Select by default the first valid mandate of the invoicing partner"""
|
||||
res = super()._compute_payment_mode()
|
||||
abm_obj = self.env["account.banking.mandate"]
|
||||
for order in self:
|
||||
if order.mandate_required and order.partner_invoice_id:
|
||||
if (
|
||||
order.partner_invoice_id
|
||||
and order.payment_mode_id
|
||||
and order.payment_mode_id.payment_method_id.mandate_required
|
||||
):
|
||||
mandate = abm_obj.search(
|
||||
[
|
||||
("state", "=", "valid"),
|
||||
@@ -55,4 +60,3 @@ class SaleOrder(models.Model):
|
||||
order.mandate_id = mandate or False
|
||||
else:
|
||||
order.mandate_id = False
|
||||
return res
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from . import sale_make_invoice_advance
|
||||
@@ -1,15 +0,0 @@
|
||||
# Copyright 2016-2022 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class SaleAdvancePaymentInv(models.TransientModel):
|
||||
_inherit = "sale.advance.payment.inv"
|
||||
|
||||
def _prepare_invoice_values(self, order, so_line):
|
||||
"""Copy mandate from sale order to invoice"""
|
||||
vals = super()._prepare_invoice_values(order, so_line)
|
||||
if order.mandate_id:
|
||||
vals["mandate_id"] = order.mandate_id.id
|
||||
return vals
|
||||
Reference in New Issue
Block a user