Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] Move code from donation to donation_direct_debit #122

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions donation/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,13 @@ class AccountJournal(models.Model):
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
"('company_id', '=', company_id), "
"('id', 'not in', (default_account_id, suspense_account_id, "
"payment_credit_account_id, payment_debit_account_id, "
"donation_debit_order_account_id))]",
"payment_credit_account_id, payment_debit_account_id))]",
string="Donation by Credit Transfer Account",
help="Transfer account for donations received by credit transfer. "
"Leave empty if you don't receive donations on this bank account.",
)
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), "
"('user_type_id.type', '=', 'receivable'), "
"('id', 'not in', (default_account_id, suspense_account_id, "
"payment_credit_account_id, payment_debit_account_id, donation_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_account_id", "donation_debit_order_account_id")
@api.constrains("donation_account_id")
def _check_donation_accounts(self):
for journal in self:
if (
Expand All @@ -55,27 +39,3 @@ def _check_donation_accounts(self):
account=journal.donation_account_id.display_name,
)
)
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.user_type_id.type != "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 "
"type '%(account_type)s'.",
journal=journal.display_name,
account=ddo_account.display_name,
account_type=ddo_account.user_type_id.display_name,
)
)
7 changes: 0 additions & 7 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,6 @@ def _prepare_counterpart_move_line(
debit = 0
if self.bank_statement_line_id:
account_id = journal.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 journal.payment_debit_account_id:
raise UserError(
Expand Down
4 changes: 0 additions & 4 deletions donation/views/account_journal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
name="donation_account_id"
attrs="{'invisible': [('type', '!=', 'bank')]}"
/>
<field
name="donation_debit_order_account_id"
attrs="{'invisible': [('type', '!=', 'bank')]}"
/>
</field>
</field>
</record>
Expand Down
1 change: 1 addition & 0 deletions donation_direct_debit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"depends": ["account_banking_sepa_direct_debit", "donation"],
"data": [
"views/donation.xml",
"views/account_journal.xml",
],
"demo": ["demo/donation_demo.xml"],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions donation_direct_debit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import donation
from . import account_journal
54 changes: 54 additions & 0 deletions donation_direct_debit/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

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), "
"('user_type_id.type', '=', 'receivable'), "
"('id', 'not in', (default_account_id, suspense_account_id, "
"payment_credit_account_id, payment_debit_account_id, donation_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):
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.user_type_id.type != "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 "
"type '%(account_type)s'.",
journal=journal.display_name,
account=ddo_account.display_name,
account_type=ddo_account.user_type_id.display_name,
)
)
16 changes: 16 additions & 0 deletions donation_direct_debit/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ def _prepare_payment_order(self):
vals = {"payment_mode_id": self.payment_mode_id.id}
return vals

def _prepare_counterpart_move_line(
self, total_company_cur, total_currency, journal
):
vals = super()._prepare_counterpart_move_line(
total_company_cur, total_currency, journal
)
journal = self.payment_mode_id.fixed_journal_id
if not self.bank_statement_line_id and 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
)
vals["account_id"] = journal.donation_debit_order_account_id.id
return vals

def validate(self):
"""Create Direct debit payment order on donation validation or update
an existing draft Direct Debit pay order"""
Expand Down
19 changes: 19 additions & 0 deletions donation_direct_debit/views/account_journal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>


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


</odoo>
Loading