Skip to Content
Menu
This question has been flagged

How do I create a computed field that re-calculates every time the product.name string is changed? I am using Studio in Odoo version 10.0. I successfully created the field with the name "x_studio_field_dZVpy" that appears in the product.template GUI. When I try to edit the product name in the product.template GUI it gives me a Value Error: forbidden opcode(s) in 'lambda'.

I checked the "readonly" and "stored" check boxes. In the "dependencies" field I entered "name". I entered the following into the "compute" field in "Advanced Properties" section of the field.

x_studio_field_dZVpy = fields.Float(compute='compute_product_dimension', store=True)

@api.depends('name')
def compute_product_dimension(self):
    for record in self:
        if name[:2] == 'LG':
            product_specs = product.name.split('-')
            product_dimension = float(product_specs[6])
            product.x_studio_field_dZVpy = product_dimension / 2
        else:
            product.x_studio_field_dZVpy = ""

For example

product.name= LG-611-40M-3UM-95P-8.000

If the first 2 characters of the product.name is “LG” the code splits the string into an array and divides the 6th element in the array by 2. In this example this would divide 8.000 by 2. The "x_studio_field_dZVpy" field should then display 4.000.

Avatar
Discard
Related Posts Replies Views Activity
2
Jul 21
2224
0
Feb 24
1364
1
Apr 20
1742
1
Mar 18
5533
3
Jul 24
1537