我们公司根据逐行给出的折扣支付佣金。我试图在我们发送给销售代表的发票副本上显示此佣金金额。
我在 v12.0 中使用 Odoo studio,并创建了一个标记为“佣金金额”的字段 x_studio_field_dakHb,它出现在 account.invoice.line 模型中。
我已经选中了“只读”和“存储”框。在“依赖项”字段中,我有“discount, price_subtotal”。
在“高级属性”部分我有:
def compute_commission_amount(self):
for record in self:
if (discount >= 55.0):
x_studio_field_dakHb = (price_subtotal * .05)
elif (discount >= 45.0):
x_studio_field_dakHb = (price_subtotal * .10)
elif (discount >= 30.0):
x_studio_field_dakHb = (price_subtotal * .15)
elif (discount >= 25.0):
x_studio_field_dakHb = (price_subtotal * .20)
elif (discount >= 0.0):
x_studio_field_dakHb = (price_subtotal * .25)
我没有收到任何错误,但该字段并没有像我预期的那样计算。
我期望的示例如下:
我的代码中是否遗漏了某些内容以使其正确计算?
请您参考如下方法:
您必须使用record 来分配您的值。在一个字段上,您会发现以下有关计算方法的提示:
The field Compute is the Python code to compute the value of the field on a set of records. The value of the field must be assigned to each record with a dictionary-like assignment.
for record in self: record['size'] = len(record.name)
所以你的代码应该是这样的:
def compute_commission_amount(self):
for record in self:
if (record.discount >= 55.0):
record['x_studio_field_dakHb'] = (record.price_subtotal * .05)
elif (record.discount >= 45.0):
record['x_studio_field_dakHb'] = (record.price_subtotal * .10)
elif (record.discount >= 30.0):
record['x_studio_field_dakHb'] = (record.price_subtotal * .15)
elif (record.discount >= 25.0):
record['x_studio_field_dakHb'] = (record.price_subtotal * .20)
elif (record.discount >= 0.0):
record['x_studio_field_dakHb'] = (record.price_subtotal * .25)
编辑:price_subtotal 还有一个错误,它应该从 record 中获取。 Edit2: 和 discount
