[MIG]account_banking_mandate: Migration to 15.0

This commit is contained in:
manu
2022-04-07 12:06:29 +02:00
parent 57cc353440
commit 6688e65aec
9 changed files with 49 additions and 63 deletions

View File

@@ -7,7 +7,7 @@
{
"name": "Account Banking Mandate",
"summary": "Banking mandates",
"version": "14.0.1.2.0",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "Compassion CH, "
"Tecnativa, "

View File

@@ -1,31 +0,0 @@
# Copyright 2021 Opener B.V. - Stefan Rijnhart <stefan@opener.amsterdam>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from odoo.tools.sql import column_exists
def migrate(cr, version):
logger = logging.getLogger(
"odoo.addons.account_banking_mandate.migrations.14.0.1.0.0"
)
if not column_exists(cr, "account_move_line", "mandate_id"):
logger.warning(
"Column account_move_line.mandate_id not found when "
"populating account_move.mandate_id"
)
return
logger.info(
"Populating account_move.mandate_id from obsolete "
"account_move_line.mandate_id"
)
cr.execute(
"""
UPDATE account_move am
SET mandate_id = aml.mandate_id
FROM account_move_line aml
WHERE aml.mandate_id IS NOT NULL
AND am.mandate_id IS NULL
AND am.id=aml.move_id
"""
)

View File

@@ -60,9 +60,7 @@ class AccountBankingMandate(models.Model):
required=True,
default=lambda self: self.env.company,
)
unique_mandate_reference = fields.Char(
string="Unique Mandate Reference", tracking=10, copy=False
)
unique_mandate_reference = fields.Char(tracking=10, copy=False)
signature_date = fields.Date(
string="Date of Signature of the Mandate",
tracking=50,

View File

@@ -30,15 +30,16 @@ class AccountPaymentLine(models.Model):
):
raise ValidationError(
_(
"The payment line number %s has the bank account "
"'%s' which is not attached to the mandate '%s' (this "
"mandate is attached to the bank account '%s')."
)
% (
pline.name,
pline.partner_bank_id.acc_number,
pline.mandate_id.unique_mandate_reference,
pline.mandate_id.partner_bank_id.acc_number,
"The payment line number {line_number} has "
"the bank account '{line_bank_account}' which "
"is not attached to the mandate '{mandate_ref}' "
"(this mandate is attached to the bank account "
"'{mandate_bank_account}')."
).format(
line_number=pline.name,
line_bank_account=pline.partner_bank_id.acc_number,
mandate_ref=pline.mandate_id.unique_mandate_reference,
mandate_bank_account=pline.mandate_id.partner_bank_id.acc_number,
)
)
@@ -51,10 +52,11 @@ class AccountPaymentLine(models.Model):
):
raise ValidationError(
_(
"The payment line number %s a different company than "
"that of the linked mandate %s)."
"The payment line number {line_number} a different "
"company than that of the linked mandate {mandate})."
).format(
line_number=pline.name, mandate=pline.mandate_id.display_name
)
% (pline.name, pline.mandate_id.display_name)
)
def draft2open_payment_line_check(self):

View File

@@ -8,7 +8,6 @@ class AccountPaymentMethod(models.Model):
_inherit = "account.payment.method"
mandate_required = fields.Boolean(
string="Mandate Required",
help="Activate this option if this payment method requires your "
"customer to sign a direct debit mandate with your company.",
)

View File

@@ -31,11 +31,6 @@ class ResPartner(models.Model):
def _compute_valid_mandate_id(self):
# Dict for reducing the duplicated searches on parent/child partners
company_id = self.env.company.id
if company_id:
company = self.env["res.company"].browse(company_id)
else:
company = self.env.company
mandates_dic = {}
for partner in self:
commercial_partner_id = partner.commercial_partner_id.id
@@ -44,7 +39,9 @@ class ResPartner(models.Model):
else:
mandates = partner.commercial_partner_id.bank_ids.mapped(
"mandate_ids"
).filtered(lambda x: x.state == "valid" and x.company_id == company)
).filtered(
lambda x: x.state == "valid" and x.company_id.id == company_id
)
first_valid_mandate_id = mandates[:1].id
partner.valid_mandate_id = first_valid_mandate_id
mandates_dic[commercial_partner_id] = first_valid_mandate_id

View File

@@ -7,3 +7,4 @@
* Carlos Dauden <carlos.dauden@tecnativa.com>
* Marçal Isern <marsal.isern@qubiq.es>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Manuel Regidor <manuel.regidor@sygel.es>

View File

@@ -1,10 +1,14 @@
# Copyright 2017 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from unittest.mock import patch
from odoo import fields
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
from odoo.addons.account.models.account_payment_method import AccountPaymentMethod
class TestInvoiceMandate(TransactionCase):
def test_post_invoice_01(self):
@@ -76,6 +80,7 @@ class TestInvoiceMandate(TransactionCase):
"date": fields.Date.today(),
"reason": "no reason",
"refund_method": "refund",
"journal_id": self.invoice.journal_id.id,
}
)
)
@@ -117,6 +122,16 @@ class TestInvoiceMandate(TransactionCase):
self.assertEqual(invoice.mandate_id, mandate_2)
def test_onchange_payment_mode(self):
Method_get_payment_method_information = (
AccountPaymentMethod._get_payment_method_information
)
def _get_payment_method_information(self):
res = Method_get_payment_method_information(self)
res["test"] = {"mode": "multi", "domain": [("type", "=", "bank")]}
return res
invoice = self.env["account.move"].new(
{
"partner_id": self.partner.id,
@@ -126,14 +141,19 @@ class TestInvoiceMandate(TransactionCase):
)
invoice._onchange_partner_id()
pay_method_test = self.env["account.payment.method"].create(
{
"name": "Test",
"code": "test",
"payment_type": "inbound",
"mandate_required": False,
}
)
with patch.object(
AccountPaymentMethod,
"_get_payment_method_information",
_get_payment_method_information,
):
pay_method_test = self.env["account.payment.method"].create(
{
"name": "Test",
"code": "test",
"payment_type": "inbound",
"mandate_required": False,
}
)
mode_inbound_acme_2 = self.env["account.payment.mode"].create(
{
"name": "Inbound Credit ACME Bank 2",

View File

@@ -114,7 +114,7 @@
<field name="name">view.mandate.tree</field>
<field name="model">account.banking.mandate</field>
<field name="arch" type="xml">
<tree string="Banking Mandate">
<tree>
<field name="id" invisible="1" />
<field name="unique_mandate_reference" string="Reference" />
<field