Skip to content

Commit

Permalink
[FIX] Move code from donation to donation_direct_debit
Browse files Browse the repository at this point in the history
This is a forward-port of PR OCA#122 from 14.0 to 16.0
  • Loading branch information
alexis-via committed May 27, 2024
1 parent cb98666 commit da507f4
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 47 deletions.
1 change: 0 additions & 1 deletion donation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"wizard/res_config_settings.xml",
"data/donation_sequence.xml",
"views/account_payment_mode.xml",
"views/account_journal.xml",
"views/donation_campaign.xml",
"views/donation_thanks_template.xml",
"views/res_users.xml",
Expand Down
1 change: 0 additions & 1 deletion donation/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
7 changes: 0 additions & 7 deletions donation/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,6 @@ 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(
Expand Down
1 change: 0 additions & 1 deletion donation/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
22 changes: 0 additions & 22 deletions donation/views/account_journal.xml

This file was deleted.

1 change: 1 addition & 0 deletions donation_direct_debit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizards
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",
"wizards/res_config_settings.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 res_company
17 changes: 17 additions & 0 deletions donation_direct_debit/models/donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ def donation_partner_direct_debit_change(self):
if mandate:
self.mandate_id = mandate

# Mathod inherited from donation module
# 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
):
vals = super()._prepare_counterpart_move_line(
total_company_cur, total_currency, journal
)
if not self.bank_statement_line_id and self.payment_mode_id.payment_order_ok:
if not self.company_id.donation_debit_order_account_id:
raise UserError(
_("Missing Donation by Debit Order Account on company '%s'.")
% self.company_id.display_name
)
vals["account_id"] = self.company_id.donation_debit_order_account_id.id
return vals

def _prepare_donation_move(self):
vals = super()._prepare_donation_move()
vals.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
from odoo.exceptions import ValidationError


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

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))]",
# domain is in res.config.settings
# 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."
Expand All @@ -31,27 +32,27 @@ def _check_donation_accounts(self):
"account_type"
]["selection"]
)
for journal in self:
ddo_account = journal.donation_debit_order_account_id
for company in self:
ddo_account = company.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 "
"The Donation by Debit Order Account of company "
"'%(company)s' must be reconciliable, but the account "
"'%(account)s' is not reconciliable.",
journal=journal.display_name,
company=company.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, "
"The Donation by Debit Order Account of company "
"'%(company)s' must be a receivable account, "
"but the account '%(account)s' is configured with "
"account type '%(account_type)s'.",
journal=journal.display_name,
company=company.display_name,
account=ddo_account.display_name,
account_type=acc_type2label[ddo_account.account_type],
)
Expand Down
1 change: 0 additions & 1 deletion donation_direct_debit/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
9 changes: 9 additions & 0 deletions donation_direct_debit/tests/test_direct_debit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
class TestDirectDebit(TransactionCase):
def test_direct_debit(self):
donation = self.env.ref("donation_direct_debit.donation6")
account = self.env["account.account"].create(
{
"company_id": donation.company_id.id,
"code": "TESTDD1",
"name": "Test donation by direct debit",
"account_type": "asset_receivable",
}
)
donation.company_id.write({"donation_debit_order_account_id": account.id})
dd_payment_mode = self.env.ref(
"account_banking_sepa_direct_debit.payment_mode_inbound_sepa_dd1"
)
Expand Down
1 change: 1 addition & 0 deletions donation_direct_debit/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
17 changes: 17 additions & 0 deletions donation_direct_debit/wizards/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

donation_debit_order_account_id = fields.Many2one(
related="company_id.donation_debit_order_account_id",
readonly=False,
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
"('company_id', '=', company_id), "
"('account_type', '=', 'asset_receivable')]",
)
26 changes: 26 additions & 0 deletions donation_direct_debit/wizards/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2021 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="res_config_settings_donation" model="ir.ui.view">
<field name="name">donation_direct_debit.res.config.settings.form</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="donation.res_config_settings_donation" />
<field name="arch" type="xml">
<div id="donation-settings" position="inside">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<label for="donation_debit_order_account_id" class="col-md-5" />
<field
name="donation_debit_order_account_id"
context="{'default_reconcile': True, 'default_account_type': 'asset_receivable'}"
/>
</div>
</div>
</field>
</record>

</odoo>

0 comments on commit da507f4

Please sign in to comment.