Skip to content

Commit c1745ae

Browse files
committed
[FIX] Move code from donation to donation_direct_debit
1 parent cf119ff commit c1745ae

File tree

8 files changed

+92
-51
lines changed

8 files changed

+92
-51
lines changed

donation/models/account_journal.py

+1-40
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,8 @@ class AccountJournal(models.Model):
2323
help="Transfer account for donations received by credit transfer. "
2424
"Leave empty if you don't receive donations on this bank account.",
2525
)
26-
donation_debit_order_account_id = fields.Many2one(
27-
"account.account",
28-
check_company=True,
29-
copy=False,
30-
ondelete="restrict",
31-
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
32-
"('company_id', '=', company_id), "
33-
"('user_type_id.type', '=', 'receivable'), "
34-
"('id', 'not in', (default_account_id, suspense_account_id, "
35-
"payment_credit_account_id, payment_debit_account_id, donation_account_id))]",
36-
string="Donation by Debit Order Account",
37-
help="Transfer account for donations by debit order. "
38-
"Leave empty if you don't handle donations by debit order on this bank account."
39-
"This account must be a receivable account, otherwise the debit order will not work.",
40-
)
4126

42-
@api.constrains("donation_account_id", "donation_debit_order_account_id")
27+
@api.constrains("donation_account_id")
4328
def _check_donation_accounts(self):
4429
for journal in self:
4530
if (
@@ -55,27 +40,3 @@ def _check_donation_accounts(self):
5540
account=journal.donation_account_id.display_name,
5641
)
5742
)
58-
ddo_account = journal.donation_debit_order_account_id
59-
if ddo_account:
60-
if not ddo_account.reconcile:
61-
raise ValidationError(
62-
_(
63-
"The Donation by Debit Order Account of journal "
64-
"'%(journal)s' must be reconciliable, but the account "
65-
"'%(account)s' is not reconciliable.",
66-
journal=journal.display_name,
67-
account=ddo_account.display_name,
68-
)
69-
)
70-
if ddo_account.user_type_id.type != "receivable":
71-
raise ValidationError(
72-
_(
73-
"The Donation by Debit Order Account of journal "
74-
"'%(journal)s' must be a receivable account, "
75-
"but the account '%(account)s' is configured with "
76-
"type '%(account_type)s'.",
77-
journal=journal.display_name,
78-
account=ddo_account.display_name,
79-
account_type=ddo_account.user_type_id.display_name,
80-
)
81-
)

donation/models/donation.py

-7
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,6 @@ def _prepare_counterpart_move_line(
289289
debit = 0
290290
if self.bank_statement_line_id:
291291
account_id = journal.donation_account_id.id
292-
elif self.payment_mode_id.payment_order_ok:
293-
if not journal.donation_debit_order_account_id:
294-
raise UserError(
295-
_("Missing Donation by Debit Order Account on journal '%s'.")
296-
% journal.display_name
297-
)
298-
account_id = journal.donation_debit_order_account_id.id
299292
else:
300293
if not journal.payment_debit_account_id:
301294
raise UserError(

donation/views/account_journal.xml

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
name="donation_account_id"
1313
attrs="{'invisible': [('type', '!=', 'bank')]}"
1414
/>
15-
<field
16-
name="donation_debit_order_account_id"
17-
attrs="{'invisible': [('type', '!=', 'bank')]}"
18-
/>
1915
</field>
2016
</field>
2117
</record>

donation_direct_debit/__manifest__.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"depends": ["account_banking_sepa_direct_debit", "donation"],
1616
"data": [
1717
"views/donation.xml",
18+
"views/account_journal.xml",
1819
],
1920
"demo": ["demo/donation_demo.xml"],
2021
"installable": True,
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import donation
2+
from . import account_journal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2021 Akretion France (http://www.akretion.com/)
2+
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo import _, api, fields, models
6+
from odoo.exceptions import ValidationError
7+
8+
9+
class AccountJournal(models.Model):
10+
_inherit = "account.journal"
11+
12+
donation_debit_order_account_id = fields.Many2one(
13+
"account.account",
14+
check_company=True,
15+
copy=False,
16+
ondelete="restrict",
17+
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
18+
"('company_id', '=', company_id), "
19+
"('user_type_id.type', '=', 'receivable'), "
20+
"('id', 'not in', (default_account_id, suspense_account_id, "
21+
"payment_credit_account_id, payment_debit_account_id, donation_account_id))]",
22+
string="Donation by Debit Order Account",
23+
help="Transfer account for donations by debit order. "
24+
"Leave empty if you don't handle donations by debit order on this bank account."
25+
"This account must be a receivable account, otherwise the debit order will not work.",
26+
)
27+
28+
@api.constrains("donation_debit_order_account_id")
29+
def _check_donation_accounts(self):
30+
for journal in self:
31+
ddo_account = journal.donation_debit_order_account_id
32+
if ddo_account:
33+
if not ddo_account.reconcile:
34+
raise ValidationError(
35+
_(
36+
"The Donation by Debit Order Account of journal "
37+
"'%(journal)s' must be reconciliable, but the account "
38+
"'%(account)s' is not reconciliable.",
39+
journal=journal.display_name,
40+
account=ddo_account.display_name,
41+
)
42+
)
43+
if ddo_account.user_type_id.type != "receivable":
44+
raise ValidationError(
45+
_(
46+
"The Donation by Debit Order Account of journal "
47+
"'%(journal)s' must be a receivable account, "
48+
"but the account '%(account)s' is configured with "
49+
"type '%(account_type)s'.",
50+
journal=journal.display_name,
51+
account=ddo_account.display_name,
52+
account_type=ddo_account.user_type_id.display_name,
53+
)
54+
)

donation_direct_debit/models/donation.py

+16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ def _prepare_payment_order(self):
5757
vals = {"payment_mode_id": self.payment_mode_id.id}
5858
return vals
5959

60+
def _prepare_counterpart_move_line(
61+
self, total_company_cur, total_currency, journal
62+
):
63+
vals = super()._prepare_counterpart_move_line(
64+
total_company_cur, total_currency, journal
65+
)
66+
journal = self.payment_mode_id.fixed_journal_id
67+
if not self.bank_statement_line_id and self.payment_mode_id.payment_order_ok:
68+
if not journal.donation_debit_order_account_id:
69+
raise UserError(
70+
_("Missing Donation by Debit Order Account on journal '%s'.")
71+
% journal.display_name
72+
)
73+
vals["account_id"] = journal.donation_debit_order_account_id.id
74+
return vals
75+
6076
def validate(self):
6177
"""Create Direct debit payment order on donation validation or update
6278
an existing draft Direct Debit pay order"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
4+
5+
<record id="view_account_journal_form" model="ir.ui.view">
6+
<field name="model">account.journal</field>
7+
<field name="inherit_id" ref="donation.view_account_journal_form" />
8+
<field name="arch" type="xml">
9+
<field name="donation_account_id" position="after">
10+
<field
11+
name="donation_debit_order_account_id"
12+
attrs="{'invisible': [('type', '!=', 'bank')]}"
13+
/>
14+
</field>
15+
</field>
16+
</record>
17+
18+
19+
</odoo>

0 commit comments

Comments
 (0)