diff --git a/donation/__manifest__.py b/donation/__manifest__.py
index a568652fb..bd69df5a9 100644
--- a/donation/__manifest__.py
+++ b/donation/__manifest__.py
@@ -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",
diff --git a/donation/models/__init__.py b/donation/models/__init__.py
index 5cac95802..363dc3463 100644
--- a/donation/models/__init__.py
+++ b/donation/models/__init__.py
@@ -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
diff --git a/donation/models/donation.py b/donation/models/donation.py
index f278323a2..f7bc595ef 100644
--- a/donation/models/donation.py
+++ b/donation/models/donation.py
@@ -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(
diff --git a/donation/static/description/index.html b/donation/static/description/index.html
index 6a28043d5..01d4c728e 100644
--- a/donation/static/description/index.html
+++ b/donation/static/description/index.html
@@ -1,4 +1,3 @@
-
diff --git a/donation/views/account_journal.xml b/donation/views/account_journal.xml
deleted file mode 100644
index c6e73748d..000000000
--- a/donation/views/account_journal.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
- donation.account.journal.form
- account.journal
-
-
-
-
-
-
-
-
-
-
diff --git a/donation_direct_debit/__init__.py b/donation_direct_debit/__init__.py
index 0650744f6..aee8895e7 100644
--- a/donation_direct_debit/__init__.py
+++ b/donation_direct_debit/__init__.py
@@ -1 +1,2 @@
from . import models
+from . import wizards
diff --git a/donation_direct_debit/__manifest__.py b/donation_direct_debit/__manifest__.py
index 735a0f682..5774382f7 100644
--- a/donation_direct_debit/__manifest__.py
+++ b/donation_direct_debit/__manifest__.py
@@ -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,
diff --git a/donation_direct_debit/models/__init__.py b/donation_direct_debit/models/__init__.py
index b1847a5ab..a86bcae3c 100644
--- a/donation_direct_debit/models/__init__.py
+++ b/donation_direct_debit/models/__init__.py
@@ -1 +1,2 @@
from . import donation
+from . import res_company
diff --git a/donation_direct_debit/models/donation.py b/donation_direct_debit/models/donation.py
index df7ff0e65..92e3062c5 100644
--- a/donation_direct_debit/models/donation.py
+++ b/donation_direct_debit/models/donation.py
@@ -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(
diff --git a/donation/models/account_journal.py b/donation_direct_debit/models/res_company.py
similarity index 73%
rename from donation/models/account_journal.py
rename to donation_direct_debit/models/res_company.py
index 41138c514..89b4a40a1 100644
--- a/donation/models/account_journal.py
+++ b/donation_direct_debit/models/res_company.py
@@ -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."
@@ -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],
)
diff --git a/donation_direct_debit/static/description/index.html b/donation_direct_debit/static/description/index.html
index a67bb50b1..29f673340 100644
--- a/donation_direct_debit/static/description/index.html
+++ b/donation_direct_debit/static/description/index.html
@@ -1,4 +1,3 @@
-
diff --git a/donation_direct_debit/wizards/__init__.py b/donation_direct_debit/wizards/__init__.py
new file mode 100644
index 000000000..0deb68c46
--- /dev/null
+++ b/donation_direct_debit/wizards/__init__.py
@@ -0,0 +1 @@
+from . import res_config_settings
diff --git a/donation_direct_debit/wizards/res_config_settings.py b/donation_direct_debit/wizards/res_config_settings.py
new file mode 100644
index 000000000..ed1578d0d
--- /dev/null
+++ b/donation_direct_debit/wizards/res_config_settings.py
@@ -0,0 +1,17 @@
+# Copyright 2016-2021 Akretion France (http://www.akretion.com/)
+# @author: Alexis de Lattre
+# 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')]",
+ )
diff --git a/donation_direct_debit/wizards/res_config_settings.xml b/donation_direct_debit/wizards/res_config_settings.xml
new file mode 100644
index 000000000..16e3449c8
--- /dev/null
+++ b/donation_direct_debit/wizards/res_config_settings.xml
@@ -0,0 +1,26 @@
+
+
+
+
+ donation_direct_debit.res.config.settings.form
+ res.config.settings
+
+
+
+
+
+
+