[MIG] account_banking_mandate: Migration to 17.0

This commit is contained in:
David Ramia
2024-03-02 12:05:55 +01:00
parent 6de70555f5
commit fe933abe05
9 changed files with 67 additions and 73 deletions

View File

@@ -7,7 +7,7 @@
{
"name": "Account Banking Mandate",
"summary": "Banking mandates",
"version": "16.0.1.2.1",
"version": "17.0.1.0.0",
"development_status": "Production/Stable",
"license": "AGPL-3",
"author": "Compassion CH, "

View File

@@ -14,7 +14,6 @@ class AccountMove(models.Model):
ondelete="restrict",
readonly=False,
check_company=True,
states={"draft": [("readonly", False)]},
compute="_compute_mandate_id",
store="True",
)

View File

@@ -75,7 +75,6 @@ class TestInvoiceMandate(TransactionCase):
{
"date": fields.Date.today(),
"reason": "no reason",
"refund_method": "refund",
"journal_id": self.invoice.journal_id.id,
}
)
@@ -191,80 +190,83 @@ class TestInvoiceMandate(TransactionCase):
with self.assertRaises(UserError):
invoice.mandate_id = mandate_2
def _create_res_partner(self, name):
return self.env["res.partner"].create({"name": name})
@classmethod
def _create_res_partner(cls, name):
return cls.env["res.partner"].create({"name": name})
def _create_res_bank(self, name, bic, city, country):
return self.env["res.bank"].create(
@classmethod
def _create_res_bank(cls, name, bic, city, country):
return cls.env["res.bank"].create(
{"name": name, "bic": bic, "city": city, "country": country.id}
)
def setUp(self):
res = super(TestInvoiceMandate, self).setUp()
self.company = self.env.ref("base.main_company")
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env.ref("base.main_company")
self.partner = self._create_res_partner("Peter with ACME Bank")
self.acme_bank = self._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", self.env.ref("base.be")
cls.partner = cls._create_res_partner("Peter with ACME Bank")
cls.acme_bank = cls._create_res_bank(
"ACME Bank", "GEBABEBB03B", "Charleroi", cls.env.ref("base.be")
)
bank_account = self.env["res.partner.bank"].create(
bank_account = cls.env["res.partner.bank"].create(
{
"acc_number": "0023032234211123",
"partner_id": self.partner.id,
"bank_id": self.acme_bank.id,
"company_id": self.company.id,
"partner_id": cls.partner.id,
"bank_id": cls.acme_bank.id,
"company_id": cls.company.id,
}
)
self.company_2 = self.env["res.company"].create({"name": "Company 2"})
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
self.mandate = self.env["account.banking.mandate"].create(
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)
self.mandate.validate()
cls.mandate.validate()
self.mode_inbound_acme = self.env["account.payment.mode"].create(
cls.mode_inbound_acme = cls.env["account.payment.mode"].create(
{
"name": "Inbound Credit ACME Bank",
"company_id": self.company.id,
"company_id": cls.company.id,
"bank_account_link": "variable",
"payment_method_id": self.env.ref(
"payment_method_id": cls.env.ref(
"account.account_payment_method_manual_in"
).id,
}
)
bank_journal = self.env["account.journal"].search(
bank_journal = cls.env["account.journal"].search(
[
("type", "=", "bank"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
self.mode_inbound_acme.variable_journal_ids = bank_journal
self.mode_inbound_acme.payment_method_id.mandate_required = True
self.mode_inbound_acme.payment_order_ok = True
cls.mode_inbound_acme.variable_journal_ids = bank_journal
cls.mode_inbound_acme.payment_method_id.mandate_required = True
cls.mode_inbound_acme.payment_order_ok = True
self.partner.customer_payment_mode_id = self.mode_inbound_acme
cls.partner.customer_payment_mode_id = cls.mode_inbound_acme
self.invoice_account = self.env["account.account"].search(
cls.invoice_account = cls.env["account.account"].search(
[
("account_type", "=", "asset_receivable"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
invoice_line_account = (
self.env["account.account"]
cls.env["account.account"]
.search(
[
("account_type", "=", "expense"),
("company_id", "=", self.company.id),
("company_id", "=", cls.company.id),
],
limit=1,
)
@@ -276,7 +278,7 @@ class TestInvoiceMandate(TransactionCase):
0,
0,
{
"product_id": self.env.ref("product.product_product_4").id,
"product_id": cls.env.ref("product.product_product_4").id,
"quantity": 1.0,
"account_id": invoice_line_account,
"price_unit": 200.00,
@@ -284,19 +286,17 @@ class TestInvoiceMandate(TransactionCase):
)
]
self.invoice = self.env["account.move"].create(
cls.invoice = cls.env["account.move"].create(
{
"partner_id": self.partner.id,
"partner_id": cls.partner.id,
"move_type": "out_invoice",
"company_id": self.company.id,
"journal_id": self.env["account.journal"]
"company_id": cls.company.id,
"journal_id": cls.env["account.journal"]
.search(
[("type", "=", "sale"), ("company_id", "=", self.company.id)],
[("type", "=", "sale"), ("company_id", "=", cls.company.id)],
limit=1,
)
.id,
"invoice_line_ids": invoice_vals,
}
)
return res

View File

@@ -9,18 +9,19 @@ from odoo.tests.common import TransactionCase
class TestMandate(TransactionCase):
def setUp(self):
super(TestMandate, self).setUp()
self.company = self.env.company
self.company_2 = self.env["res.company"].create({"name": "company 2"})
self.company_2.partner_id.company_id = self.company_2.id
self.bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
self.bank_account.partner_id.company_id = self.company.id
self.mandate = self.env["account.banking.mandate"].create(
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env.company
cls.company_2 = cls.env["res.company"].create({"name": "company 2"})
cls.company_2.partner_id.company_id = cls.company_2.id
cls.bank_account = cls.env.ref("account_payment_mode.res_partner_12_iban")
cls.bank_account.partner_id.company_id = cls.company.id
cls.mandate = cls.env["account.banking.mandate"].create(
{
"partner_bank_id": self.bank_account.id,
"partner_bank_id": cls.bank_account.id,
"signature_date": "2015-01-01",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)

View File

@@ -14,28 +14,25 @@
name="validate"
type="object"
string="Validate"
states="draft"
class="btn-primary"
invisible="context.get('mandate_bank_partner_view')"
invisible="context.get('mandate_bank_partner_view') or state != 'draft'"
groups="account_payment_order.group_account_payment"
/>
<button
name="cancel"
type="object"
string="Cancel"
states="draft,valid"
confirm="Are you sure you want to cancel this mandate?"
invisible="context.get('mandate_bank_partner_view')"
invisible="context.get('mandate_bank_partner_view') or state not in ('draft', 'valid')"
groups="account_payment_order.group_account_payment"
/>
<button
name="back2draft"
type="object"
string="Back to Draft"
states="cancel"
groups="account_payment_order.group_account_payment"
confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue?"
invisible="context.get('mandate_bank_partner_view')"
invisible="context.get('mandate_bank_partner_view') or state != 'cancel'"
/>
<field
name="state"
@@ -50,12 +47,13 @@
<field
name="unique_mandate_reference"
class="oe_inline"
attrs="{'readonly': [('id', '!=', False)]}"
readonly="id"
/>
</h1>
</div>
<group name="main">
<field name="company_id" groups="base.group_multi_company" />
<field name="company_id" invisible="1" />
<field name="format" string="Format" />
<field name="type" string="Type" />
<field
@@ -139,7 +137,7 @@
icon="fa-check"
string="Validate"
groups="account_payment_order.group_account_payment"
attrs="{'invisible': ['|', ('id', '=', False), ('state', '!=', 'draft')]}"
invisible="not id or state != 'draft'"
/>
<!-- Removed cancel button in tree view. Too dangerous.
'confirm' attribute doesn't work in tree view. -->
@@ -149,7 +147,7 @@
icon="fa-undo"
string="Draft"
groups="account_payment_order.group_account_payment"
attrs="{'invisible': ['|', ('id', '=', False), ('state', '!=', 'cancel')]}"
invisible="not id or state != 'cancel'"
/>
<field
name="state"

View File

@@ -13,8 +13,9 @@
<field
name="mandate_id"
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
attrs="{'required': [('mandate_required', '=', True),('move_type', 'in', ('out_invoice', 'out_refund'))],
'invisible': ['|', ('mandate_required', '=', False),('move_type', 'not in', ('out_invoice', 'out_refund'))]}"
required="mandate_required and move_type in ('out_invoice', 'out_refund')"
invisible="not mandate_required or move_type not in ('out_invoice', 'out_refund')"
readonly="state != 'draft'"
/>
<field name="mandate_required" invisible="1" />
</field>

View File

@@ -17,7 +17,8 @@
<field
name="mandate_id"
domain="[('partner_bank_id', '=', partner_bank_id), ('state', '=', 'valid')]"
attrs="{'invisible': [('payment_type', '!=', 'inbound')], 'required': [('mandate_required', '=', True)]}"
required="mandate_required"
invisible="payment_type != 'inbound'"
context="{'default_partner_bank_id': partner_bank_id}"
/>
</field>

View File

@@ -9,10 +9,7 @@
/>
<field name="arch" type="xml">
<field name="bank_account_required" position="after">
<field
name="mandate_required"
attrs="{'invisible': [('payment_type', '!=', 'inbound')]}"
/>
<field name="mandate_required" invisible="payment_type != 'inbound'" />
</field>
</field>
</record>

View File

@@ -9,15 +9,12 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.view_partner_property_form" />
<field name="arch" type="xml">
<xpath
expr="//button[@name='%(base.action_res_partner_bank_account_form)d']"
position="after"
>
<xpath expr="//group[@name='banks']" position="inside">
<button
type="action"
class="btn-link"
name="%(account_banking_mandate.mandate_action)d"
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}"
context="{'search_default_partner_id': id, 'default_partner_id': id}"
>
<field string="Mandate(s)" name="mandate_count" widget="statinfo" />
</button>