Skip to Content
Menu
This question has been flagged

Hello,


I would like to add a field in the product form that defauld uses the sales price and the costprice to calculate the margin. However only when the salesprice and the costprice are set (>0). In that case the Margin field should be read only. So far so good. I got that far by setting the next script:

for record in self:
if record['list_price'] > 0 and record['standard_price']>0: 
record['x_studio_marge'] = (record['list_price'] - record['standard_price']) / record['standard_price']

However next I also want to be able to compute the sales price if the margin and the costprice are set. In which case the salesprice should be readonly and the margin should be writeable. This so users can deside if the salesprice should be fixed or the margin.

Like this:

for record in self:    
if record['x_studio_marge'] > 0 and record['standard_price']>0:
  record['list_price'] = record['standard_price'] * (1 + record['x_studio_marge'])

However when I try to remove the readonly check box from my new margin field. Odoo places it back. When I try to add a filter to the readonly property of the Margin field I get an error:

Error on validating view near:


                
Field 'standard_price' used in attrs ({"readonly": ["&",["list_price",">",0],["standard_price",">",0]]}) is restricted to the group(s) base.group_user.

Is what I want possible in Odoo studio or is backend editing mandotary in this case?

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 20
1741
1
Mar 18
5530
2
Jun 23
2154
1
Sep 24
685
1
Sep 24
138