model - 如何制作字段取决于 product.product 的 lst_price 但可以编辑

标签 model field product odoo-10

我想在同一个模型中制作字段product.product
假设 A 取决于 lst_price of product.product .

如果用户未设置 A 的值,则取 lst_price 但如果用户将设置 A 的值,则按原样设置。
变体价格集上的字段值也发生了变化。

amount=fields.Float(compute="_compute_amount",inverse="_set_amount",store=True)


@api.depends('lst_price')
def _compute_amount(self):            
    for product in self:
        if product.amount<product.lst_price:
            product.amount = product.lst_price

@api.one            
def _set_amount(self):
    return True

最佳答案

假设您想在 product.product 中创建字段,该字段将在 lst_price 更改时填充,也可以由用户更改。

你可以像这样实现它。

A = fields.AnyType(compute="get_value_on_lst_price", inverse="set_value_by_user",store=True)

@api.depends('lst_price')
def get_value_on_lst_price(self):
    for product in self:
        product.A = Any_Calculation_Using_lst_price

@api.one
def set_value_by_user(self):
    return True

关于model - 如何制作字段取决于 product.product 的 lst_price 但可以编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46336331/

相关文章:

qt - QML 中 ItemSelectionModel 的目的和用法

awk - 使用 awk 检查字段长度

wpf - 保持模型与 View 模型同步

asp.net-mvc - Glass Mapper未加载的模型

html - 是否可以在表单域中放置标签?

dataset - 如何将自定义指标从 App Insights 导入到 Power BI?

php - 在 WooCommerce 中按产品 ID 显示带有短代码的产品价格

php - 通过 WP_Query 中的自定义分类术语值获取 Woocommerce 产品

php - Woocommerce 产品选项卡的不同状态

R:在 nlme 函数中使用因子变量