Skip to content

Commit 206852f

Browse files
committed
[FIX] Move code from donation to donation_direct_debit
This is a forward-port of PR OCA#122 from 14.0 to 16.0
1 parent cb98666 commit 206852f

File tree

14 files changed

+79
-47
lines changed

14 files changed

+79
-47
lines changed

donation/__manifest__.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"wizard/res_config_settings.xml",
2323
"data/donation_sequence.xml",
2424
"views/account_payment_mode.xml",
25-
"views/account_journal.xml",
2625
"views/donation_campaign.xml",
2726
"views/donation_thanks_template.xml",
2827
"views/res_users.xml",

donation/models/__init__.py

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

donation/models/donation.py

-7
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,6 @@ def _prepare_counterpart_move_line(
269269
debit = 0
270270
if self.bank_statement_line_id:
271271
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
279272
else:
280273
if not company.account_journal_payment_debit_account_id:
281274
raise UserError(

donation/static/description/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>

donation/views/account_journal.xml

-22
This file was deleted.

donation_direct_debit/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import models
2+
from . import wizards

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+
"wizards/res_config_settings.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 res_company

donation_direct_debit/models/donation.py

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ def donation_partner_direct_debit_change(self):
4343
if mandate:
4444
self.mandate_id = mandate
4545

46+
# Mathod inherited from donation module
47+
# TODO migration: remove 'journal' argument and use self.payment_mode_id.fixed_journal_id
48+
def _prepare_counterpart_move_line(
49+
self, total_company_cur, total_currency, journal
50+
):
51+
vals = super()._prepare_counterpart_move_line(
52+
total_company_cur, total_currency, journal
53+
)
54+
if not self.bank_statement_line_id and self.payment_mode_id.payment_order_ok:
55+
if not self.company_id.donation_debit_order_account_id:
56+
raise UserError(
57+
_("Missing Donation by Debit Order Account on company '%s'.")
58+
% self.company_id.display_name
59+
)
60+
vals["account_id"] = self.company_id.donation_debit_order_account_id.id
61+
return vals
62+
4663
def _prepare_donation_move(self):
4764
vals = super()._prepare_donation_move()
4865
vals.update(

donation/models/account_journal.py donation_direct_debit/models/res_company.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
from odoo.exceptions import ValidationError
77

88

9-
class AccountJournal(models.Model):
10-
_inherit = "account.journal"
9+
class ResCompany(models.Model):
10+
_inherit = "res.company"
1111

1212
donation_debit_order_account_id = fields.Many2one(
1313
"account.account",
1414
check_company=True,
1515
copy=False,
1616
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))]",
17+
# domain is in res.config.settings
18+
# domain="[('reconcile', '=', True), ('deprecated', '=', False), "
19+
# "('company_id', '=', company_id), "
20+
# "('account_type', '=', 'asset_receivable'), "
21+
# "('id', 'not in', (default_account_id, suspense_account_id))]",
2122
string="Donation by Debit Order Account",
2223
help="Transfer account for donations by debit order. "
2324
"Leave empty if you don't handle donations by debit order on this bank account."
@@ -31,27 +32,27 @@ def _check_donation_accounts(self):
3132
"account_type"
3233
]["selection"]
3334
)
34-
for journal in self:
35-
ddo_account = journal.donation_debit_order_account_id
35+
for company in self:
36+
ddo_account = company.donation_debit_order_account_id
3637
if ddo_account:
3738
if not ddo_account.reconcile:
3839
raise ValidationError(
3940
_(
40-
"The Donation by Debit Order Account of journal "
41-
"'%(journal)s' must be reconciliable, but the account "
41+
"The Donation by Debit Order Account of company "
42+
"'%(company)s' must be reconciliable, but the account "
4243
"'%(account)s' is not reconciliable.",
43-
journal=journal.display_name,
44+
company=company.display_name,
4445
account=ddo_account.display_name,
4546
)
4647
)
4748
if ddo_account.account_type != "asset_receivable":
4849
raise ValidationError(
4950
_(
50-
"The Donation by Debit Order Account of journal "
51-
"'%(journal)s' must be a receivable account, "
51+
"The Donation by Debit Order Account of company "
52+
"'%(company)s' must be a receivable account, "
5253
"but the account '%(account)s' is configured with "
5354
"account type '%(account_type)s'.",
54-
journal=journal.display_name,
55+
company=company.display_name,
5556
account=ddo_account.display_name,
5657
account_type=acc_type2label[ddo_account.account_type],
5758
)

donation_direct_debit/static/description/index.html

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import res_config_settings
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2016-2021 Akretion France (http://www.akretion.com/)
2+
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo import fields, models
6+
7+
8+
class ResConfigSettings(models.TransientModel):
9+
_inherit = "res.config.settings"
10+
11+
donation_debit_order_account_id = fields.Many2one(
12+
related="company_id.donation_debit_order_account_id",
13+
readonly=False,
14+
domain="[('reconcile', '=', True), ('deprecated', '=', False), "
15+
"('company_id', '=', company_id), "
16+
"('account_type', '=', 'asset_receivable')]",
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
Copyright 2021 Akretion France (http://www.akretion.com/)
4+
@author: Alexis de Lattre <alexis.delattre@akretion.com>
5+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
6+
-->
7+
<odoo>
8+
<record id="res_config_settings_donation" model="ir.ui.view">
9+
<field name="name">donation_direct_debit.res.config.settings.form</field>
10+
<field name="model">res.config.settings</field>
11+
<field name="inherit_id" ref="donation.res_config_settings_donation" />
12+
<field name="arch" type="xml">
13+
<div id="donation-settings" position="inside">
14+
<div class="o_setting_left_pane" />
15+
<div class="o_setting_right_pane">
16+
<label for="donation_debit_order_account_id" class="col-md-5" />
17+
<field
18+
name="donation_debit_order_account_id"
19+
context="{'default_reconcile': True, 'default_account_type': 'asset_receivable'}"
20+
/>
21+
</div>
22+
</div>
23+
</field>
24+
</record>
25+
26+
</odoo>

0 commit comments

Comments
 (0)