Skip to content

Commit 99b4186

Browse files
authored
Merge pull request #120 from akretion/16-fix-direct_debit
[16.0][FIX] donation by direct debit
2 parents 18d351a + f3541fc commit 99b4186

File tree

7 files changed

+98
-8
lines changed

7 files changed

+98
-8
lines changed

donation/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Donation
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14
10+
!! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png

donation/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"wizard/res_config_settings.xml",
2323
"data/donation_sequence.xml",
2424
"views/account_payment_mode.xml",
25-
# "views/account_bank_statement.xml",
25+
"views/account_journal.xml",
2626
"views/donation_campaign.xml",
2727
"views/donation_thanks_template.xml",
2828
"views/res_users.xml",

donation/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from . import donation_thanks_template
66
from . import account_bank_statement_line
77
from . import account_analytic_applicability
8+
from . import account_journal
89
from . import res_partner
910
from . import res_users
1011
from . import res_company

donation/models/account_journal.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2023 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).
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+
"('account_type', '=', 'asset_receivable'), "
20+
"('id', 'not in', (default_account_id, suspense_account_id))]",
21+
string="Donation by Debit Order Account",
22+
help="Transfer account for donations by debit order. "
23+
"Leave empty if you don't handle donations by debit order on this bank account."
24+
"This account must be a receivable account, otherwise the debit order will not work.",
25+
)
26+
27+
@api.constrains("donation_debit_order_account_id")
28+
def _check_donation_accounts(self):
29+
acc_type2label = dict(
30+
self.env["account.account"].fields_get("account_type", "selection")[
31+
"account_type"
32+
]["selection"]
33+
)
34+
for journal in self:
35+
ddo_account = journal.donation_debit_order_account_id
36+
if ddo_account:
37+
if not ddo_account.reconcile:
38+
raise ValidationError(
39+
_(
40+
"The Donation by Debit Order Account of journal "
41+
"'%(journal)s' must be reconciliable, but the account "
42+
"'%(account)s' is not reconciliable.",
43+
journal=journal.display_name,
44+
account=ddo_account.display_name,
45+
)
46+
)
47+
if ddo_account.account_type != "asset_receivable":
48+
raise ValidationError(
49+
_(
50+
"The Donation by Debit Order Account of journal "
51+
"'%(journal)s' must be a receivable account, "
52+
"but the account '%(account)s' is configured with "
53+
"account type '%(account_type)s'.",
54+
journal=journal.display_name,
55+
account=ddo_account.display_name,
56+
account_type=acc_type2label[ddo_account.account_type],
57+
)
58+
)

donation/models/donation.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,13 @@ def _prepare_each_tax_receipt(self):
254254
}
255255
return vals
256256

257+
# TODO migration: remove 'journal' argument and use self.payment_mode_id.fixed_journal_id
257258
def _prepare_counterpart_move_line(
258259
self, total_company_cur, total_currency, journal
259260
):
260261
self.ensure_one()
262+
journal = self.payment_mode_id.fixed_journal_id
261263
company = journal.company_id
262-
if not company.account_journal_payment_debit_account_id:
263-
raise UserError(
264-
_("Missing Outstanding Receipts Account on company '%s'.")
265-
% company.display_name
266-
)
267264
if self.company_currency_id.compare_amounts(total_company_cur, 0) > 0:
268265
debit = total_company_cur
269266
credit = 0
@@ -272,7 +269,19 @@ def _prepare_counterpart_move_line(
272269
debit = 0
273270
if self.bank_statement_line_id:
274271
account_id = company.donation_account_id.id
272+
elif self.payment_mode_id.payment_order_ok:
273+
if not journal.donation_debit_order_account_id:
274+
raise UserError(
275+
_("Missing Donation by Debit Order Account on journal '%s'.")
276+
% journal.display_name
277+
)
278+
account_id = journal.donation_debit_order_account_id.id
275279
else:
280+
if not company.account_journal_payment_debit_account_id:
281+
raise UserError(
282+
_("Missing Outstanding Receipts Account on company '%s'.")
283+
% company.display_name
284+
)
276285
payment_method = self.payment_mode_id.payment_method_id
277286
account_id = (
278287
journal.inbound_payment_method_line_ids.filtered(

donation/static/description/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h1 class="title">Donation</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14
370+
!! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/donation/tree/16.0/donation"><img alt="OCA/donation" src="https://img.shields.io/badge/github-OCA%2Fdonation-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/donation-16-0/donation-16-0-donation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/donation&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module handles donations by cash, check or by credit transfer and generate the corresponding journal entries and tax receipts. To fully support donations by credit transfer, if you are using the OCA bank statement reconcile interface, you also need the module <strong>donation_bank_statement_oca</strong>.</p>

donation/views/account_journal.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="name">donation.account.journal.form</field>
7+
<field name="model">account.journal</field>
8+
<field name="inherit_id" ref="account.view_account_journal_form" />
9+
<field name="arch" type="xml">
10+
<field name="loss_account_id" position="after">
11+
<field
12+
name="donation_debit_order_account_id"
13+
groups="account.group_account_readonly"
14+
attrs="{'invisible': [('type', '!=', 'bank')]}"
15+
options="{'no_quick_create': True}"
16+
/>
17+
</field>
18+
</field>
19+
</record>
20+
21+
22+
</odoo>

0 commit comments

Comments
 (0)