diff --git a/account_banking_mandate/data/mandate_reference_sequence.xml b/account_banking_mandate/data/mandate_reference_sequence.xml
index 6a83bb8b9..34454eb34 100644
--- a/account_banking_mandate/data/mandate_reference_sequence.xml
+++ b/account_banking_mandate/data/mandate_reference_sequence.xml
@@ -5,5 +5,6 @@
account.banking.mandate
BM
+
diff --git a/account_banking_mandate/models/account_banking_mandate.py b/account_banking_mandate/models/account_banking_mandate.py
index 4cf2f2098..2dad0d48a 100644
--- a/account_banking_mandate/models/account_banking_mandate.py
+++ b/account_banking_mandate/models/account_banking_mandate.py
@@ -61,7 +61,7 @@ class AccountBankingMandate(models.Model):
default=lambda self: self.env.company,
)
unique_mandate_reference = fields.Char(
- string="Unique Mandate Reference", tracking=10, copy=False
+ string="Unique Mandate Reference", tracking=10, copy=False, default="/"
)
signature_date = fields.Date(
string="Date of Signature of the Mandate",
@@ -175,14 +175,16 @@ class AccountBankingMandate(models.Model):
% mandate.unique_mandate_reference
)
- @api.model
- def create(self, vals=None):
- unique_mandate_reference = vals.get("unique_mandate_reference")
- if not unique_mandate_reference or unique_mandate_reference == "New":
- vals["unique_mandate_reference"] = (
- self.env["ir.sequence"].next_by_code("account.banking.mandate") or "New"
- )
- return super().create(vals)
+ @api.model_create_multi
+ def create(self, vals_list):
+ for vals in vals_list:
+ unique_mandate_reference = vals.get("unique_mandate_reference", "/")
+ if unique_mandate_reference == "/":
+ vals["unique_mandate_reference"] = (
+ self.env["ir.sequence"].next_by_code("account.banking.mandate")
+ or "New"
+ )
+ return super().create(vals_list)
@api.onchange("partner_bank_id")
def mandate_partner_bank_change(self):
diff --git a/account_banking_mandate/models/account_move.py b/account_banking_mandate/models/account_move.py
index 8af23c772..999b22e6f 100644
--- a/account_banking_mandate/models/account_move.py
+++ b/account_banking_mandate/models/account_move.py
@@ -20,25 +20,26 @@ class AccountMove(models.Model):
related="payment_mode_id.payment_method_id.mandate_required", readonly=True
)
- @api.model
- def create(self, vals):
+ @api.model_create_multi
+ def create(self, vals_list):
"""Fill the mandate_id from the partner if none is provided on
creation, using same method as upstream."""
onchanges = {
"_onchange_partner_id": ["mandate_id"],
"_onchange_payment_mode_id": ["mandate_id"],
}
- for onchange_method, changed_fields in list(onchanges.items()):
- if any(f not in vals for f in changed_fields):
- move = self.new(vals)
- move = move.with_company(move.company_id.id)
- getattr(move, onchange_method)()
- for field in changed_fields:
- if field not in vals and move[field]:
- vals[field] = move._fields[field].convert_to_write(
- move[field], move
- )
- return super().create(vals)
+ for vals in vals_list:
+ for onchange_method, changed_fields in list(onchanges.items()):
+ if any(f not in vals for f in changed_fields):
+ move = self.new(vals)
+ move = move.with_company(move.company_id.id)
+ getattr(move, onchange_method)()
+ for field in changed_fields:
+ if field not in vals and move[field]:
+ vals[field] = move._fields[field].convert_to_write(
+ move[field], move
+ )
+ return super().create(vals_list)
def set_mandate(self):
if self.payment_mode_id.payment_method_id.mandate_required:
diff --git a/account_banking_mandate/tests/test_mandate.py b/account_banking_mandate/tests/test_mandate.py
index b6d6ca796..61ec6e8fd 100644
--- a/account_banking_mandate/tests/test_mandate.py
+++ b/account_banking_mandate/tests/test_mandate.py
@@ -175,9 +175,8 @@ class TestMandate(TransactionCase):
def test_mandate_reference_03(self):
"""
- Test case: create a mandate with "New" as reference
- Expected result: the reference of the created mandate is not empty and
- is not "New"
+ Test case: create a mandate with "TEST" as reference
+ Expected result: the reference of the created mandate is "TEST"
"""
bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
mandate = self.env["account.banking.mandate"].create(
@@ -185,15 +184,32 @@ class TestMandate(TransactionCase):
"partner_bank_id": bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
- "unique_mandate_reference": "New",
+ "unique_mandate_reference": "TEST",
}
)
self.assertTrue(mandate.unique_mandate_reference)
- self.assertNotEqual(mandate.unique_mandate_reference, "New")
+ self.assertEqual(mandate.unique_mandate_reference, "TEST")
+
+ def test_mandate_reference_04(self):
+ """
+ Test case: create a mandate with "/" as reference
+ Expected result: the reference of the created mandate is not "/"
+ """
+ bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
+ mandate = self.env["account.banking.mandate"].create(
+ {
+ "partner_bank_id": bank_account.id,
+ "signature_date": "2015-01-01",
+ "company_id": self.company.id,
+ "unique_mandate_reference": "/",
+ }
+ )
+ self.assertTrue(mandate.unique_mandate_reference)
+ self.assertNotEqual(mandate.unique_mandate_reference, "/")
def test_mandate_reference_05(self):
"""
- Test case: create a mandate with False as reference
+ Test case: create a mandate without reference
Expected result: the reference of the created mandate is not empty
"""
bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
@@ -202,23 +218,6 @@ class TestMandate(TransactionCase):
"partner_bank_id": bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
- "unique_mandate_reference": False,
- }
- )
- self.assertTrue(mandate.unique_mandate_reference)
-
- def test_mandate_reference_06(self):
- """
- Test case: create a mandate with a empty string as reference
- Expected result: the reference of the created mandate is not empty
- """
- bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
- mandate = self.env["account.banking.mandate"].create(
- {
- "partner_bank_id": bank_account.id,
- "signature_date": "2015-01-01",
- "company_id": self.company.id,
- "unique_mandate_reference": "",
}
)
self.assertTrue(mandate.unique_mandate_reference)
diff --git a/account_banking_mandate/views/account_banking_mandate_view.xml b/account_banking_mandate/views/account_banking_mandate_view.xml
index 820808a21..b9f97e7a0 100644
--- a/account_banking_mandate/views/account_banking_mandate_view.xml
+++ b/account_banking_mandate/views/account_banking_mandate_view.xml
@@ -50,7 +50,7 @@