Hi,
I'm using Odoo studio to add a computed float field to a product page.
From the inventory valuation report I have added a field on the list view that calculates the average value of each unit in stock, like this:
for record in self:
record['x_studio_field_kZ3CY'] = record.stock_value / record.qty_at_date
I've then added that same field to the General Information on the product variant page.
The problem is if the qty_on_hand is 0, then the calculation cannot run and so an error message is returned if I try to open the page of a product with a quantity of 0.
ValueError: <class 'ZeroDivisionError'>: "float division by zero" while evaluating
"for record in self:\n record['x_studio_field_kZ3CY'] = record.stock_value / record.qty_at_date"
Obviously, if there's 0 stock, I just want that field to return a value of 0.
This seems like it should be a fairly simple thing to get around, by saying "if qty=0, skip the formula and return value of 0", but I've practically no experience with coding so don't really know where to start.
Any help would be appreciated.
Thanks.