Skip to main content
 首页 » 编程设计

python之如何使用 Python 代码在 Odoo Studio 中创建计算字段

2025年02月15日10langtianya

我正在使用 Studio in Odoo version 10.0 .我成功创建了名为 x_studio_field_dZVpy 的字段出现在 product.template 中图形用户界面。

当我尝试在 product.template 中编辑产品名称时GUI 它给了我一个 Value Error: forbidden opcode(s) in 'lambda' .

我选中了“只读”和“存储”复选框。在“依赖项”字段中,我输入了“名称”。我在该字段的“高级属性”部分的“计算”字段中输入了以下内容。

我在“高级属性”部分的“计算”字段中输入了以下内容。

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

例如

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

如果 product.name 的前 2 个字符是“LG”,代码会将字符串拆分为一个数组,并将数组中的第 6 个元素除以 2。在本例中,这应该除以 8.000按 2。“x_studio_field_dZVpy”字段应显示 4.000。

请您参考如下方法:

代替:

for record in self: 
    if name[:2] == 'LG': 

尝试:

for product in self: 
    if product.name[:2] == 'LG':