diff --git a/donation/models/donation.py b/donation/models/donation.py
index f7bc595ef..f388ef0fb 100644
--- a/donation/models/donation.py
+++ b/donation/models/donation.py
@@ -447,6 +447,18 @@ def validate(self):
)
% donation.display_name
)
+
+ mixed_in_kind = any([line.in_kind for line in donation.line_ids]) and any(
+ [not line.in_kind for line in donation.line_ids]
+ )
+ if mixed_in_kind:
+ raise UserError(
+ _(
+ "Donation %s has a mix of in-kind and non in-kind "
+ "donation lines. Please separate them into two donations."
+ )
+ % donation.display_name
+ )
vals = {"state": "done"}
if full_in_kind and donation.payment_mode_id:
diff --git a/donation/models/donation_tax_receipt.py b/donation/models/donation_tax_receipt.py
index 22d9cf24a..a12911a09 100644
--- a/donation/models/donation_tax_receipt.py
+++ b/donation/models/donation_tax_receipt.py
@@ -15,7 +15,7 @@ class DonationTaxReceipt(models.Model):
@api.model
def update_tax_receipt_annual_dict(
- self, tax_receipt_annual_dict, start_date, end_date, company
+ self, tax_receipt_annual_dict, start_date, end_date, company, split_payment_method=False
):
res = super().update_tax_receipt_annual_dict(
tax_receipt_annual_dict, start_date, end_date, company
@@ -36,15 +36,22 @@ def update_tax_receipt_annual_dict(
tax_receipt_amount = donation.tax_receipt_total
if company.currency_id.is_zero(tax_receipt_amount):
continue
- partner = donation.commercial_partner_id
- if partner not in tax_receipt_annual_dict:
- tax_receipt_annual_dict[partner] = {
+ partner = donation.commercial_partner_id
+ payment_mode = donation.payment_mode_id
+
+ if split_payment_method:
+ key = (partner,payment_mode)
+ else:
+ key = (partner,)
+
+ if key not in tax_receipt_annual_dict:
+ tax_receipt_annual_dict[key] = {
"amount": tax_receipt_amount,
"extra_vals": {"donation_ids": [(6, 0, [donation.id])]},
}
else:
- tax_receipt_annual_dict[partner]["amount"] += tax_receipt_amount
- tax_receipt_annual_dict[partner]["extra_vals"]["donation_ids"][0][
+ tax_receipt_annual_dict[key]["amount"] += tax_receipt_amount
+ tax_receipt_annual_dict[key]["extra_vals"]["donation_ids"][0][
2
].append(donation.id)
return res
diff --git a/donation/wizard/res_config_settings.xml b/donation/wizard/res_config_settings.xml
index 9c75bb5e5..54cd83810 100644
--- a/donation/wizard/res_config_settings.xml
+++ b/donation/wizard/res_config_settings.xml
@@ -46,7 +46,7 @@
/>
-
@@ -57,6 +57,14 @@
+
diff --git a/donation_base/models/__init__.py b/donation_base/models/__init__.py
index 0067d6e8d..d2fbee258 100644
--- a/donation_base/models/__init__.py
+++ b/donation_base/models/__init__.py
@@ -1,3 +1,5 @@
from . import product
from . import res_partner
from . import donation_tax_receipt
+from . import res_config_settings
+from . import res_company
diff --git a/donation_base/models/donation_tax_receipt.py b/donation_base/models/donation_tax_receipt.py
index 6bb19b148..862a9c4e4 100644
--- a/donation_base/models/donation_tax_receipt.py
+++ b/donation_base/models/donation_tax_receipt.py
@@ -52,6 +52,11 @@ class DonationTaxReceipt(models.Model):
required=True,
tracking=True,
)
+ payment_mode_id = fields.Many2one(
+ "account.payment.mode",
+ string="Payment Mode",
+ tracking=True,
+ )
@api.model_create_multi
def create(self, vals_list):
@@ -67,7 +72,7 @@ def create(self, vals_list):
@api.model
def update_tax_receipt_annual_dict(
- self, tax_receipt_annual_dict, start_date, end_date, company
+ self, tax_receipt_annual_dict, start_date, end_date, company, split_payment_method=False
):
"""This method is inherited in donation and donation_sale
It is called by the tax.receipt.annual.create wizard"""
diff --git a/donation_base/models/res_company.py b/donation_base/models/res_company.py
new file mode 100644
index 000000000..6dd658969
--- /dev/null
+++ b/donation_base/models/res_company.py
@@ -0,0 +1,15 @@
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import _, api, fields, models
+from odoo.exceptions import ValidationError
+
+
+class ResCompany(models.Model):
+ _inherit = "res.company"
+
+ donation_receipt_split_by_payment_mode = fields.Boolean(
+ string="Split Donation Receipts by Payment Mode",
+ help="If enabled, annual donation tax receipts will be split by payment mode. "
+ "If disabled, one annual donation tax receipt will be generated per donor, "
+ "regardless of the payment mode used.",
+ )
\ No newline at end of file
diff --git a/donation_base/models/res_config_settings.py b/donation_base/models/res_config_settings.py
new file mode 100644
index 000000000..05220f98d
--- /dev/null
+++ b/donation_base/models/res_config_settings.py
@@ -0,0 +1,12 @@
+# -*- coding: utf-8 -*-
+
+from odoo import api, fields, models, _
+
+
+class ResConfigSettings(models.TransientModel):
+ _inherit = 'res.config.settings'
+
+ split_by_payment_mode = fields.Boolean(
+ string="Split Donation Receipts by Payment Mode",
+ related="company_id.donation_receipt_split_by_payment_mode",
+ readonly=False)
\ No newline at end of file
diff --git a/donation_base/views/donation_tax_receipt.xml b/donation_base/views/donation_tax_receipt.xml
index 30fcc8399..707b2ea01 100644
--- a/donation_base/views/donation_tax_receipt.xml
+++ b/donation_base/views/donation_tax_receipt.xml
@@ -40,6 +40,7 @@
+
diff --git a/donation_base/wizard/tax_receipt_annual_create.py b/donation_base/wizard/tax_receipt_annual_create.py
index 670ce76fa..cdee74f9c 100644
--- a/donation_base/wizard/tax_receipt_annual_create.py
+++ b/donation_base/wizard/tax_receipt_annual_create.py
@@ -37,16 +37,18 @@ def _default_start_date(self):
)
@api.model
- def _prepare_annual_tax_receipt(self, partner, partner_dict):
+ def _prepare_annual_tax_receipt(self, key_table, partner_dict, split_payment_method=False):
vals = {
"company_id": self.company_id.id,
"currency_id": self.company_id.currency_id.id,
"amount": partner_dict["amount"],
"type": "annual",
- "partner_id": partner.id,
+ "partner_id": key_table[0].id,
"date": self.end_date,
"donation_date": self.end_date,
}
+ if split_payment_method:
+ vals["payment_mode_id"] = key_table[1].id
# designed to add add O2M fields donation_ids and invoice_ids
vals.update(partner_dict["extra_vals"])
return vals
@@ -58,10 +60,11 @@ def generate_annual_receipts(self):
self.start_date,
self.end_date,
)
+ split_by_payment_mode = self.company_id.donation_receipt_split_by_payment_mode
dtro = self.env["donation.tax.receipt"]
tax_receipt_annual_dict = {}
self.env["donation.tax.receipt"].update_tax_receipt_annual_dict(
- tax_receipt_annual_dict, self.start_date, self.end_date, self.company_id
+ tax_receipt_annual_dict, self.start_date, self.end_date, self.company_id, split_payment_method=split_by_payment_mode
)
tax_receipt_ids = []
existing_annual_receipts = dtro.search(
@@ -74,22 +77,26 @@ def generate_annual_receipts(self):
)
existing_annual_receipts_dict = {}
for receipt in existing_annual_receipts:
- existing_annual_receipts_dict[receipt.partner_id] = receipt
+ if split_by_payment_mode and receipt.payment_mode_id:
+ key = (receipt.partner_id, receipt.payment_mode_id.id)
+ else:
+ key = (receipt.partner_id,)
+ existing_annual_receipts_dict[key] = receipt
- for partner, partner_dict in tax_receipt_annual_dict.items():
+ for key_table, partner_dict in tax_receipt_annual_dict.items():
# Block if the partner already has an annual tax receipt
- if partner in existing_annual_receipts_dict:
- existing_receipt = existing_annual_receipts_dict[partner]
+ if key_table in existing_annual_receipts_dict:
+ existing_receipt = existing_annual_receipts_dict[key_table]
raise UserError(
_(
"The Donor '%(partner)s' already has an annual tax receipt "
"in this timeframe: %(receipt)s dated %(number)s.",
- partner=partner.display_name,
+ partner=key_table[0].display_name,
receipt=existing_receipt.number,
date=format_date(self.env, existing_receipt.date),
)
)
- vals = self._prepare_annual_tax_receipt(partner, partner_dict)
+ vals = self._prepare_annual_tax_receipt(key_table, partner_dict, split_payment_method=split_by_payment_mode)
tax_receipt = dtro.create(vals)
tax_receipt_ids.append(tax_receipt.id)
logger.info("Tax receipt %s generated", tax_receipt.number)