【问题标题】:Calculate freight total in a computed field on Invoice - Odoo在发票的计算字段中计算运费总额 - Odoo
【发布时间】:2019-07-30 14:51:25
【问题描述】:

我正在尝试在我的发票底部显示运费总额。我在会计模块中创建了一个名为“Freight Total”的新字段 (x_studio_freight_total)。对于“产品”(product_id)=“FREIGHT”的任何实例,我想获得“小计”(price_subtotal)的总和。

对于字段 x_studio_freight_total,我将依赖项设置为:“invoice_line_ids.price_subtotal, invoice_line_ids.product_id”

我将 Compute 属性设置为:

for record in self:
  if(record.invoice_line_ids.product_id == "FREIGHT):
    record['x_studio_freight_total'] = sum(record.invoice_line_ids.price_subtotal)

如果发票显示一行包含名为“FREIGHT”的“产品”和“12.75”的“小计”,我希望我的“运费总计”字段显示“12.75”。

如果发票有两行名为“FREIGHT”的“产品”,一行的“小计”为“12.75”,另一行的“小计”为“7.50”,我希望显示“运费总计”字段“20.25”。 但它目前没有显示任何内容,只是“0.00”

【问题讨论】:

    标签: sum odoo invoice odoo-12 computed-field


    【解决方案1】:

    尝试使用此代码

    for record in self:
     record['x_studio_freight_total'] = 0
     for line in record.invoice_line_ids:
         if(line.product_id.name == "FREIGHT): #product_id.name to search product name
             record['x_studio_freight_total'] += line.price_subtotal`
    

    【讨论】:

    • 我注意到您的代码中有一些错误,但知道您要做什么,不幸的是它仍然返回 0.00 作为我的值。
    • 如果您使用 pycharm 添加断点检查值或使用 raise Usererror 检查您的条件是否有效,则可以使用 python 调试器检查值。
    猜你喜欢
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多