Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions donation_base/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class ProductTemplate(models.Model):
_inherit = "product.template"

is_donation = fields.Boolean(compute="_compute_is_donation", store=True)
detailed_type = fields.Selection(
selection_add=[
("donation", "Donation"),
Expand All @@ -32,6 +33,11 @@ class ProductTemplate(models.Model):
help="Specify if the product is eligible for a tax receipt",
)

@api.depends("detailed_type")
def _compute_is_donation(self):
for product in self:
product.is_donation = product.detailed_type.startswith("donation")

@api.depends("detailed_type")
def _compute_tax_receipt_ok(self):
for product in self:
Expand Down
6 changes: 3 additions & 3 deletions donation_base/views/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<filter
name="filter_donation"
string="Donation"
domain="[('detailed_type', 'in', ('donation', 'donation_in_kind_consu', 'donation_in_kind_service'))]"
domain="[('is_donation', '=', True)]"
/>
</filter>
<filter name="filter_to_purchase" position="after">
Expand All @@ -33,10 +33,10 @@
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="detailed_type" position="after">
<!-- unfortunately, Odoo doesn't accept 'not like' in attrs -->
<field name="is_donation" invisible="1" />
<field
name="tax_receipt_ok"
attrs="{'invisible': [('detailed_type', 'not in', ('donation', 'donation_in_kind_service', 'donation_in_kind_consu'))]}"
attrs="{'invisible': [('is_donation', '=', False)]}"
/>
</field>
</field>
Expand Down