Skip to content

Commit fe933ab

Browse files
committedMar 5, 2024
[MIG] account_banking_mandate: Migration to 17.0
1 parent 6de7055 commit fe933ab

9 files changed

+67
-73
lines changed
 

‎account_banking_mandate/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Account Banking Mandate",
99
"summary": "Banking mandates",
10-
"version": "16.0.1.2.1",
10+
"version": "17.0.1.0.0",
1111
"development_status": "Production/Stable",
1212
"license": "AGPL-3",
1313
"author": "Compassion CH, "

‎account_banking_mandate/models/account_move.py

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class AccountMove(models.Model):
1414
ondelete="restrict",
1515
readonly=False,
1616
check_company=True,
17-
states={"draft": [("readonly", False)]},
1817
compute="_compute_mandate_id",
1918
store="True",
2019
)

‎account_banking_mandate/tests/test_invoice_mandate.py

+40-40
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def test_post_invoice_and_refund_02(self):
7575
{
7676
"date": fields.Date.today(),
7777
"reason": "no reason",
78-
"refund_method": "refund",
7978
"journal_id": self.invoice.journal_id.id,
8079
}
8180
)
@@ -191,80 +190,83 @@ def test_invoice_constrains(self):
191190
with self.assertRaises(UserError):
192191
invoice.mandate_id = mandate_2
193192

194-
def _create_res_partner(self, name):
195-
return self.env["res.partner"].create({"name": name})
193+
@classmethod
194+
def _create_res_partner(cls, name):
195+
return cls.env["res.partner"].create({"name": name})
196196

197-
def _create_res_bank(self, name, bic, city, country):
198-
return self.env["res.bank"].create(
197+
@classmethod
198+
def _create_res_bank(cls, name, bic, city, country):
199+
return cls.env["res.bank"].create(
199200
{"name": name, "bic": bic, "city": city, "country": country.id}
200201
)
201202

202-
def setUp(self):
203-
res = super(TestInvoiceMandate, self).setUp()
204-
self.company = self.env.ref("base.main_company")
203+
@classmethod
204+
def setUpClass(cls):
205+
super().setUpClass()
206+
cls.company = cls.env.ref("base.main_company")
205207

206-
self.partner = self._create_res_partner("Peter with ACME Bank")
207-
self.acme_bank = self._create_res_bank(
208-
"ACME Bank", "GEBABEBB03B", "Charleroi", self.env.ref("base.be")
208+
cls.partner = cls._create_res_partner("Peter with ACME Bank")
209+
cls.acme_bank = cls._create_res_bank(
210+
"ACME Bank", "GEBABEBB03B", "Charleroi", cls.env.ref("base.be")
209211
)
210212

211-
bank_account = self.env["res.partner.bank"].create(
213+
bank_account = cls.env["res.partner.bank"].create(
212214
{
213215
"acc_number": "0023032234211123",
214-
"partner_id": self.partner.id,
215-
"bank_id": self.acme_bank.id,
216-
"company_id": self.company.id,
216+
"partner_id": cls.partner.id,
217+
"bank_id": cls.acme_bank.id,
218+
"company_id": cls.company.id,
217219
}
218220
)
219221

220-
self.company_2 = self.env["res.company"].create({"name": "Company 2"})
222+
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
221223

222-
self.mandate = self.env["account.banking.mandate"].create(
224+
cls.mandate = cls.env["account.banking.mandate"].create(
223225
{
224226
"partner_bank_id": bank_account.id,
225227
"signature_date": "2015-01-01",
226-
"company_id": self.company.id,
228+
"company_id": cls.company.id,
227229
}
228230
)
229231

230-
self.mandate.validate()
232+
cls.mandate.validate()
231233

232-
self.mode_inbound_acme = self.env["account.payment.mode"].create(
234+
cls.mode_inbound_acme = cls.env["account.payment.mode"].create(
233235
{
234236
"name": "Inbound Credit ACME Bank",
235-
"company_id": self.company.id,
237+
"company_id": cls.company.id,
236238
"bank_account_link": "variable",
237-
"payment_method_id": self.env.ref(
239+
"payment_method_id": cls.env.ref(
238240
"account.account_payment_method_manual_in"
239241
).id,
240242
}
241243
)
242-
bank_journal = self.env["account.journal"].search(
244+
bank_journal = cls.env["account.journal"].search(
243245
[
244246
("type", "=", "bank"),
245-
("company_id", "=", self.company.id),
247+
("company_id", "=", cls.company.id),
246248
],
247249
limit=1,
248250
)
249-
self.mode_inbound_acme.variable_journal_ids = bank_journal
250-
self.mode_inbound_acme.payment_method_id.mandate_required = True
251-
self.mode_inbound_acme.payment_order_ok = True
251+
cls.mode_inbound_acme.variable_journal_ids = bank_journal
252+
cls.mode_inbound_acme.payment_method_id.mandate_required = True
253+
cls.mode_inbound_acme.payment_order_ok = True
252254

253-
self.partner.customer_payment_mode_id = self.mode_inbound_acme
255+
cls.partner.customer_payment_mode_id = cls.mode_inbound_acme
254256

255-
self.invoice_account = self.env["account.account"].search(
257+
cls.invoice_account = cls.env["account.account"].search(
256258
[
257259
("account_type", "=", "asset_receivable"),
258-
("company_id", "=", self.company.id),
260+
("company_id", "=", cls.company.id),
259261
],
260262
limit=1,
261263
)
262264
invoice_line_account = (
263-
self.env["account.account"]
265+
cls.env["account.account"]
264266
.search(
265267
[
266268
("account_type", "=", "expense"),
267-
("company_id", "=", self.company.id),
269+
("company_id", "=", cls.company.id),
268270
],
269271
limit=1,
270272
)
@@ -276,27 +278,25 @@ def setUp(self):
276278
0,
277279
0,
278280
{
279-
"product_id": self.env.ref("product.product_product_4").id,
281+
"product_id": cls.env.ref("product.product_product_4").id,
280282
"quantity": 1.0,
281283
"account_id": invoice_line_account,
282284
"price_unit": 200.00,
283285
},
284286
)
285287
]
286288

287-
self.invoice = self.env["account.move"].create(
289+
cls.invoice = cls.env["account.move"].create(
288290
{
289-
"partner_id": self.partner.id,
291+
"partner_id": cls.partner.id,
290292
"move_type": "out_invoice",
291-
"company_id": self.company.id,
292-
"journal_id": self.env["account.journal"]
293+
"company_id": cls.company.id,
294+
"journal_id": cls.env["account.journal"]
293295
.search(
294-
[("type", "=", "sale"), ("company_id", "=", self.company.id)],
296+
[("type", "=", "sale"), ("company_id", "=", cls.company.id)],
295297
limit=1,
296298
)
297299
.id,
298300
"invoice_line_ids": invoice_vals,
299301
}
300302
)
301-
302-
return res

‎account_banking_mandate/tests/test_mandate.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010

1111
class TestMandate(TransactionCase):
12-
def setUp(self):
13-
super(TestMandate, self).setUp()
14-
self.company = self.env.company
15-
self.company_2 = self.env["res.company"].create({"name": "company 2"})
16-
self.company_2.partner_id.company_id = self.company_2.id
17-
self.bank_account = self.env.ref("account_payment_mode.res_partner_12_iban")
18-
self.bank_account.partner_id.company_id = self.company.id
19-
self.mandate = self.env["account.banking.mandate"].create(
12+
@classmethod
13+
def setUpClass(cls):
14+
super().setUpClass()
15+
cls.company = cls.env.company
16+
cls.company_2 = cls.env["res.company"].create({"name": "company 2"})
17+
cls.company_2.partner_id.company_id = cls.company_2.id
18+
cls.bank_account = cls.env.ref("account_payment_mode.res_partner_12_iban")
19+
cls.bank_account.partner_id.company_id = cls.company.id
20+
cls.mandate = cls.env["account.banking.mandate"].create(
2021
{
21-
"partner_bank_id": self.bank_account.id,
22+
"partner_bank_id": cls.bank_account.id,
2223
"signature_date": "2015-01-01",
23-
"company_id": self.company.id,
24+
"company_id": cls.company.id,
2425
}
2526
)
2627

‎account_banking_mandate/views/account_banking_mandate_view.xml

+7-9
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,25 @@
1414
name="validate"
1515
type="object"
1616
string="Validate"
17-
states="draft"
1817
class="btn-primary"
19-
invisible="context.get('mandate_bank_partner_view')"
18+
invisible="context.get('mandate_bank_partner_view') or state != 'draft'"
2019
groups="account_payment_order.group_account_payment"
2120
/>
2221
<button
2322
name="cancel"
2423
type="object"
2524
string="Cancel"
26-
states="draft,valid"
2725
confirm="Are you sure you want to cancel this mandate?"
28-
invisible="context.get('mandate_bank_partner_view')"
26+
invisible="context.get('mandate_bank_partner_view') or state not in ('draft', 'valid')"
2927
groups="account_payment_order.group_account_payment"
3028
/>
3129
<button
3230
name="back2draft"
3331
type="object"
3432
string="Back to Draft"
35-
states="cancel"
3633
groups="account_payment_order.group_account_payment"
3734
confirm="You should set a mandate back to draft only if you cancelled it by mistake. Do you want to continue?"
38-
invisible="context.get('mandate_bank_partner_view')"
35+
invisible="context.get('mandate_bank_partner_view') or state != 'cancel'"
3936
/>
4037
<field
4138
name="state"
@@ -50,12 +47,13 @@
5047
<field
5148
name="unique_mandate_reference"
5249
class="oe_inline"
53-
attrs="{'readonly': [('id', '!=', False)]}"
50+
readonly="id"
5451
/>
5552
</h1>
5653
</div>
5754
<group name="main">
5855
<field name="company_id" groups="base.group_multi_company" />
56+
<field name="company_id" invisible="1" />
5957
<field name="format" string="Format" />
6058
<field name="type" string="Type" />
6159
<field
@@ -139,7 +137,7 @@
139137
icon="fa-check"
140138
string="Validate"
141139
groups="account_payment_order.group_account_payment"
142-
attrs="{'invisible': ['|', ('id', '=', False), ('state', '!=', 'draft')]}"
140+
invisible="not id or state != 'draft'"
143141
/>
144142
<!-- Removed cancel button in tree view. Too dangerous.
145143
'confirm' attribute doesn't work in tree view. -->
@@ -149,7 +147,7 @@
149147
icon="fa-undo"
150148
string="Draft"
151149
groups="account_payment_order.group_account_payment"
152-
attrs="{'invisible': ['|', ('id', '=', False), ('state', '!=', 'cancel')]}"
150+
invisible="not id or state != 'cancel'"
153151
/>
154152
<field
155153
name="state"

‎account_banking_mandate/views/account_move_view.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<field
1414
name="mandate_id"
1515
domain="[('partner_id', '=', commercial_partner_id), ('state', '=', 'valid')]"
16-
attrs="{'required': [('mandate_required', '=', True),('move_type', 'in', ('out_invoice', 'out_refund'))],
17-
'invisible': ['|', ('mandate_required', '=', False),('move_type', 'not in', ('out_invoice', 'out_refund'))]}"
16+
required="mandate_required and move_type in ('out_invoice', 'out_refund')"
17+
invisible="not mandate_required or move_type not in ('out_invoice', 'out_refund')"
18+
readonly="state != 'draft'"
1819
/>
1920
<field name="mandate_required" invisible="1" />
2021
</field>

‎account_banking_mandate/views/account_payment_line.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<field
1818
name="mandate_id"
1919
domain="[('partner_bank_id', '=', partner_bank_id), ('state', '=', 'valid')]"
20-
attrs="{'invisible': [('payment_type', '!=', 'inbound')], 'required': [('mandate_required', '=', True)]}"
20+
required="mandate_required"
21+
invisible="payment_type != 'inbound'"
2122
context="{'default_partner_bank_id': partner_bank_id}"
2223
/>
2324
</field>

‎account_banking_mandate/views/account_payment_method.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
/>
1010
<field name="arch" type="xml">
1111
<field name="bank_account_required" position="after">
12-
<field
13-
name="mandate_required"
14-
attrs="{'invisible': [('payment_type', '!=', 'inbound')]}"
15-
/>
12+
<field name="mandate_required" invisible="payment_type != 'inbound'" />
1613
</field>
1714
</field>
1815
</record>

‎account_banking_mandate/views/res_partner.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
<field name="model">res.partner</field>
1010
<field name="inherit_id" ref="account.view_partner_property_form" />
1111
<field name="arch" type="xml">
12-
<xpath
13-
expr="//button[@name='%(base.action_res_partner_bank_account_form)d']"
14-
position="after"
15-
>
12+
<xpath expr="//group[@name='banks']" position="inside">
1613
<button
1714
type="action"
1815
class="btn-link"
1916
name="%(account_banking_mandate.mandate_action)d"
20-
context="{'search_default_partner_id': active_id, 'default_partner_id': active_id}"
17+
context="{'search_default_partner_id': id, 'default_partner_id': id}"
2118
>
2219
<field string="Mandate(s)" name="mandate_count" widget="statinfo" />
2320
</button>

0 commit comments

Comments
 (0)