Skip to content

Commit

Permalink
[IMP] donation & donation_base: res.partner filters
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
norlinhenrik committed Mar 7, 2024
1 parent 2fa5cf2 commit 2f75062
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
17 changes: 17 additions & 0 deletions donation/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <field>
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()
Expand Down
21 changes: 21 additions & 0 deletions donation/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@
</xpath>
</field>
</record>
<record id="res_partner_view_form_donation_send_thanks" model="ir.ui.view">
<field name="name">res.partner.view.form.donation.send.thanks</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="donation_base.view_partner_property_form" />
<field name="groups_id" eval="[(4, ref('donation.group_donation_viewer'))]" />
<field name="arch" type="xml">
<field name="tax_receipt_send" position="after">
<field name="donation_send_thanks" />
</field>
</field>
</record>
<record id="res_partner_view_search" model="ir.ui.view">
<field name="name">res.partner.view.search.donation</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="donation_base.res_partner_view_search" />
<field name="arch" type="xml">
<search position="inside">
<field name="donation_send_thanks" />
</search>
</field>
</record>
</odoo>
17 changes: 17 additions & 0 deletions donation_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <field>
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
Expand All @@ -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")
Expand Down
21 changes: 14 additions & 7 deletions donation_base/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
name="tax_receipt_option"
attrs="{'invisible': [('parent_id', '!=', False)]}"
/>
<field
name="tax_receipt_send"
attrs="{'invisible': [('parent_id', '!=', False)]}"
/>
<field name="donor_rank" invisible="1" />
</field>
<xpath expr="//div[@name='button_box']" position="inside">
Expand All @@ -44,19 +48,22 @@
</button>
</xpath>
</field>
</record>
</record>
<record id="res_partner_view_search" model="ir.ui.view">
<field name="name">donation.res.partner.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.res_partner_view_search" />
<field name="arch" type="xml">
<filter name="supplier" position="after">
<filter
string="Donors"
name="donor"
domain="[('donor_rank','>', 0)]"
/>
<filter name="supplier" position="after">
<filter
string="Donors"
name="donor"
domain="[('donor_rank','>', 0)]"
/>
</filter>
<search position="inside">
<field name="tax_receipt_send" />
</search>
</field>
</record>
<record id="res_partner_action_donor" model="ir.actions.act_window">
Expand Down

0 comments on commit 2f75062

Please sign in to comment.