Hello, I'm trying to show the number of days (0 day, -2 days, 3 days etc) for the Integer field "Days Left". The problem here(again) is that the result is not showing in the list view when "Days Left" is equal to 0. It's working fine in the form view.
View Name : product.template.product.list
====================================
Product Name. Expiry Date. Days Left
Product 1. 14 Jun 2025(Today) 1
Product 2. 13 Jun 2025 (empty)
Product 3. 12 Jun 2025 -1
====================================
class Drug(models.Model):
_inherit = "product.template"
expiry_date = fields.Date(string="Expiry Date")
due = fields.Integer(string="Days Left", compute="_compute_due")
def _compute_due(self):
for record in self:
if record.expiry_date:
today_date = date.today()
# No need to convert to string and back
delta_days = (record.expiry_date - today_date).days
record.due = delta_days
else:
record.due = 0
<record id="view_drug_view_list" model="ir.ui.view">
<field name="name">drug.view.list.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="expiry_date"/>
<field name="due"
decoration-danger = "due <= 0"
decoration-warning = "due <= 30"
decoration-info = "due > 30"
widget="badge"/>
</xpath>
</field>
</record>
Thanks for your suggestions.