Skip to content

Commit

Permalink
Merge pull request #120 from akretion/16-fix-direct_debit
Browse files Browse the repository at this point in the history
[16.0][FIX] donation by direct debit
  • Loading branch information
alexis-via authored Jan 24, 2024
2 parents 18d351a + f3541fc commit 99b4186
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 8 deletions.
2 changes: 1 addition & 1 deletion donation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Donation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14
!! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion donation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"wizard/res_config_settings.xml",
"data/donation_sequence.xml",
"views/account_payment_mode.xml",
# "views/account_bank_statement.xml",
"views/account_journal.xml",
"views/donation_campaign.xml",
"views/donation_thanks_template.xml",
"views/res_users.xml",
Expand Down
1 change: 1 addition & 0 deletions donation/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import donation_thanks_template
from . import account_bank_statement_line
from . import account_analytic_applicability
from . import account_journal
from . import res_partner
from . import res_users
from . import res_company
58 changes: 58 additions & 0 deletions donation/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class AccountJournal(models.Model):
_inherit = "account.journal"

donation_debit_order_account_id = fields.Many2one(
"account.account",
check_company=True,
copy=False,
ondelete="restrict",
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
"('company_id', '=', company_id), "
"('account_type', '=', 'asset_receivable'), "
"('id', 'not in', (default_account_id, suspense_account_id))]",
string="Donation by Debit Order Account",
help="Transfer account for donations by debit order. "
"Leave empty if you don't handle donations by debit order on this bank account."
"This account must be a receivable account, otherwise the debit order will not work.",
)

@api.constrains("donation_debit_order_account_id")
def _check_donation_accounts(self):
acc_type2label = dict(
self.env["account.account"].fields_get("account_type", "selection")[
"account_type"
]["selection"]
)
for journal in self:
ddo_account = journal.donation_debit_order_account_id
if ddo_account:
if not ddo_account.reconcile:
raise ValidationError(
_(
"The Donation by Debit Order Account of journal "
"'%(journal)s' must be reconciliable, but the account "
"'%(account)s' is not reconciliable.",
journal=journal.display_name,
account=ddo_account.display_name,
)
)
if ddo_account.account_type != "asset_receivable":
raise ValidationError(
_(
"The Donation by Debit Order Account of journal "
"'%(journal)s' must be a receivable account, "
"but the account '%(account)s' is configured with "
"account type '%(account_type)s'.",
journal=journal.display_name,
account=ddo_account.display_name,
account_type=acc_type2label[ddo_account.account_type],
)
)
19 changes: 14 additions & 5 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,13 @@ def _prepare_each_tax_receipt(self):
}
return vals

# TODO migration: remove 'journal' argument and use self.payment_mode_id.fixed_journal_id
def _prepare_counterpart_move_line(
self, total_company_cur, total_currency, journal
):
self.ensure_one()
journal = self.payment_mode_id.fixed_journal_id
company = journal.company_id
if not company.account_journal_payment_debit_account_id:
raise UserError(
_("Missing Outstanding Receipts Account on company '%s'.")
% company.display_name
)
if self.company_currency_id.compare_amounts(total_company_cur, 0) > 0:
debit = total_company_cur
credit = 0
Expand All @@ -272,7 +269,19 @@ def _prepare_counterpart_move_line(
debit = 0
if self.bank_statement_line_id:
account_id = company.donation_account_id.id
elif self.payment_mode_id.payment_order_ok:
if not journal.donation_debit_order_account_id:
raise UserError(
_("Missing Donation by Debit Order Account on journal '%s'.")
% journal.display_name
)
account_id = journal.donation_debit_order_account_id.id
else:
if not company.account_journal_payment_debit_account_id:
raise UserError(
_("Missing Outstanding Receipts Account on company '%s'.")
% company.display_name
)
payment_method = self.payment_mode_id.payment_method_id
account_id = (
journal.inbound_payment_method_line_ids.filtered(
Expand Down
2 changes: 1 addition & 1 deletion donation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Donation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b932b192fe69bb056a35cdb5ff3bd65bc235cbd0e76f5e21e570401b8f778b14
!! source digest: sha256:2293e7e2e2c085acf9a1787db4ce3e599d8579af9d329b7a506b67f300566cec
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<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>
Expand Down
22 changes: 22 additions & 0 deletions donation/views/account_journal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>


<record id="view_account_journal_form" model="ir.ui.view">
<field name="name">donation.account.journal.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<field name="loss_account_id" position="after">
<field
name="donation_debit_order_account_id"
groups="account.group_account_readonly"
attrs="{'invisible': [('type', '!=', 'bank')]}"
options="{'no_quick_create': True}"
/>
</field>
</field>
</record>


</odoo>

0 comments on commit 99b4186

Please sign in to comment.