【问题标题】:calculate new price_unit in sale order line在销售订单行中计算新的 price_unit
【发布时间】:2021-02-15 15:26:07
【问题描述】:

我创建了一个新的自定义模块,将产品的宽度和长度作为具有自定义值的属性包含在内,我需要使用当前单价乘以 (lenght*witdh) 值来更新销售订单行的 price_unit ,所以我可以在产品卡中获得每表面单位的价格,在销售订单行中获得每总表面的价格。 我使用产品配置器,这是我的代码:

from odoo import models, fields, api


# import pymsgbox

class aurea_calculated_field_line(models.Model):
    _inherit = 'sale.order.line'
    field_superficie = fields.Float('Superficie')
    field_alto = fields.Integer('Alto')
    field_ancho = fields.Integer('Ancho')

    @api.onchange('field_alto', 'field_ancho', 'product_uom_qty', 'quantity')
    def _value_pc5(self):
        for record in self:
            record.field_superficie = record.field_ancho * record.field_alto
            self.price_unit = float(self.field_superficie) * self.product_id.lst_price

    @api.onchange('product_id')
    def _value_pc4(self):
        if not self.product_custom_attribute_value_ids and not self.product_no_variant_attribute_value_ids:
            return ""
        for pacv in self.product_custom_attribute_value_ids:
            if pacv.custom_product_template_attribute_value_id.display_name == 'Largo: Largo':
                self.field_alto = pacv.custom_value
            if pacv.custom_product_template_attribute_value_id.display_name == 'Ancho: Ancho':
                self.field_ancho = pacv.custom_value

它工作正常,但问题是当我更改产品数量时,单价会重置为产品价目表价格。 有什么建议吗?

提前致谢

【问题讨论】:

  • 你不应该更新数量而不是单位价格吗?您的计量单位 (UoM) 类似于 m²,因此更改宽度和长度会改变您拥有的单位数量,而不是价格。
  • 这是最后一个选项,因为如果我更新数量,报价数据会有点混乱。例如,该项目是促销画布,它们有每平方厘米的价格,因此根据画布的大小,系统应计算最终价格。如果我的画布价格为 0.10 欧元/平方厘米,尺寸为 50x100 厘米=5000 平方厘米,则最终价格应为每张帆布 500 欧元,如果客户要求 2 或 3 或任何数量,则单价相同。
  • 问题是如果我更新数量,我的新数量应该是50x100x数量的物品,所以如果客户需要2张画布,数量将是50x100x2=10.000,如果他们需要3,那么15.000 ,但客户购买的宣传画布不是 cm2
  • 您已经为订单行创建了新字段。如果您使用这些字段来计算行总和怎么办。那么您的单价将是 $/m²,数量多少 Canvas 并且每行都有独特的画布尺寸。这条线的总价格是 unit_price * qty * height* width。

标签: odoo odoo-13


【解决方案1】:

我看了一点。我没有重现该问题,但您可能可以使用以下方法。

在 Odoo13 源代码中,文件 addons/sale/models/sale.py 的第 1614 行是一种导致您遇到问题的行为的方法:

    @api.onchange('product_uom', 'product_uom_qty')
    def product_uom_change(self):
        if not self.product_uom or not self.product_id:
            self.price_unit = 0.0
            return
        if self.order_id.pricelist_id and self.order_id.partner_id:
            product = self.product_id.with_context(
                lang=self.order_id.partner_id.lang,
                partner=self.order_id.partner_id,
                quantity=self.product_uom_qty,
                date=self.order_id.date_order,
                pricelist=self.order_id.pricelist_id.id,
                uom=self.product_uom.id,
                fiscal_position=self.env.context.get('fiscal_position')
            )
            self.price_unit = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)

这会在产品数量发生变化时重新计算单价。您必须在代码中覆盖此方法。最简单的方法是将其添加到您的aurea_calculated_field_line-class。


def product_uom_change(self):
    return

但这需要进行大量测试,以确保其他一些功能不会因此而中断。

【讨论】:

  • 宾果游戏。非常感谢
  • 很高兴听到这是否有帮助。如果您认为这是正确的答案,您可以接受它作为您问题的答案。这就是 SO 信誉积分系统的工作方式。每个人都想要他们的虚拟宠物:)
猜你喜欢
  • 2019-10-09
  • 2016-10-14
  • 2020-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多