Skip to content

Commit 5a79fb2

Browse files
committed
[IMP] donation_base: compute is_donation
Add a new field 'is_donation' so that we can easily filter which products are donation and which are not without listing all the values for 'detailed_type'.
1 parent 40a79a0 commit 5a79fb2

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

donation_base/models/product.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
class ProductTemplate(models.Model):
1111
_inherit = "product.template"
1212

13+
is_donation = fields.Boolean(compute="_compute_is_donation",
14+
store=True)
1315
detailed_type = fields.Selection(
1416
selection_add=[
1517
("donation", "Donation"),
@@ -32,6 +34,11 @@ class ProductTemplate(models.Model):
3234
help="Specify if the product is eligible for a tax receipt",
3335
)
3436

37+
@api.depends("detailed_type")
38+
def _compute_is_donation(self):
39+
for product in self:
40+
product.is_donation = product.detailed_type.startswith("donation")
41+
3542
@api.depends("detailed_type")
3643
def _compute_tax_receipt_ok(self):
3744
for product in self:

donation_base/views/product.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<filter
1616
name="filter_donation"
1717
string="Donation"
18-
domain="[('detailed_type', 'in', ('donation', 'donation_in_kind_consu', 'donation_in_kind_service'))]"
18+
domain="[('is_donation', '=', True)]"
1919
/>
2020
</filter>
2121
<filter name="filter_to_purchase" position="after">
@@ -33,10 +33,10 @@
3333
<field name="inherit_id" ref="product.product_template_form_view" />
3434
<field name="arch" type="xml">
3535
<field name="detailed_type" position="after">
36-
<!-- unfortunately, Odoo doesn't accept 'not like' in attrs -->
36+
<field name="is_donation" invisible="1" />
3737
<field
3838
name="tax_receipt_ok"
39-
attrs="{'invisible': [('detailed_type', 'not in', ('donation', 'donation_in_kind_service', 'donation_in_kind_consu'))]}"
39+
attrs="{'invisible': [('is_donation', '=', False)]}"
4040
/>
4141
</field>
4242
</field>

0 commit comments

Comments
 (0)