From 2f75062157d7aafa95f9910428c70ec0f151e4ca Mon Sep 17 00:00:00 2001 From: Henrik Norlin Date: Thu, 7 Mar 2024 06:39:05 +0100 Subject: [PATCH] [IMP] donation & donation_base: res.partner filters * New Tax Receipt (tax_receipt_send) * New Donation (donation_send_thanks) We send these documents together with a newsletter. So we need to filter contacts with newsletter AND (not) extra document. --- donation/models/res_partner.py | 17 +++++++++++++++++ donation/views/res_partner.xml | 21 +++++++++++++++++++++ donation_base/models/res_partner.py | 17 +++++++++++++++++ donation_base/views/res_partner.xml | 21 ++++++++++++++------- 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/donation/models/res_partner.py b/donation/models/res_partner.py index aef3696f4..a790f84a0 100644 --- a/donation/models/res_partner.py +++ b/donation/models/res_partner.py @@ -20,12 +20,29 @@ def _compute_donation_count(self): for partner in self: partner.donation_count = mapped_data.get(partner.id, 0) + @api.depends("donation_ids.thanks_printed") + def _compute_donation_send_thanks(self): + for partner in self: + if partner.donation_ids.filtered(lambda d: not d.thanks_printed): + partner.donation_send_thanks = "Yes" + else: + partner.donation_send_thanks = "No" + donation_ids = fields.One2many( "donation.donation", "partner_id", string="Donations", readonly=True ) donation_count = fields.Integer( compute="_compute_donation_count", string="# of Donations", compute_sudo=True ) + # Stored selection to search on the + donation_send_thanks = fields.Selection( + string="Send Donation Thanks", + selection=[("yes", "Yes"), ("no", "No")], + compute="_compute_donation_send_thanks", + store=True, + help="Filter on donors who (don't) need a thanks.\n" \ + "Send it e.g. together with a newsletter.", + ) def _prepare_donor_rank(self): rank = super()._prepare_donor_rank() diff --git a/donation/views/res_partner.xml b/donation/views/res_partner.xml index 7226eb405..e3cc15cbc 100644 --- a/donation/views/res_partner.xml +++ b/donation/views/res_partner.xml @@ -29,4 +29,25 @@ + + res.partner.view.form.donation.send.thanks + res.partner + + + + + + + + + + res.partner.view.search.donation + res.partner + + + + + + + diff --git a/donation_base/models/res_partner.py b/donation_base/models/res_partner.py index 7a84d793d..0378bf8df 100644 --- a/donation_base/models/res_partner.py +++ b/donation_base/models/res_partner.py @@ -25,6 +25,15 @@ class ResPartner(models.Model): tax_receipt_count = fields.Integer( compute="_compute_tax_receipt_count", string="# of Tax Receipts", readonly=True ) + # Stored selection to search on the + tax_receipt_send = fields.Selection( + string="Send Donation Tax Receipt", + selection=[("yes", "Yes"), ("no", "No")], + compute="_compute_tax_receipt_send", + store=True, + help="Filter on donors who (don't) need a tax receipt.\n" \ + "Send it e.g. together with a newsletter.", + ) donor_rank = fields.Integer(default=0) # I don't want to sync tax_receipt_option between parent and child @@ -36,6 +45,14 @@ def _compute_tax_receipt_count(self): for partner in self: partner.tax_receipt_count = len(partner.tax_receipt_ids.ids) + @api.depends("tax_receipt_ids.print_date") + def _compute_tax_receipt_send(self): + for partner in self: + if partner.tax_receipt_ids.filtered(lambda d: not d.print_date): + partner.tax_receipt_send = "Yes" + else: + partner.tax_receipt_send = "No" + @api.model_create_multi def create(self, vals_list): search_partner_mode = self.env.context.get("res_partner_search_mode") diff --git a/donation_base/views/res_partner.xml b/donation_base/views/res_partner.xml index 03a1fb069..d9a679082 100644 --- a/donation_base/views/res_partner.xml +++ b/donation_base/views/res_partner.xml @@ -26,6 +26,10 @@ name="tax_receipt_option" attrs="{'invisible': [('parent_id', '!=', False)]}" /> + @@ -44,19 +48,22 @@ - + donation.res.partner.search res.partner - - + + + + +