python - 为什么我的计算域在反面不起作用?

标签 python python-2.7 odoo odoo-10

我有计算字段 x_totalunity,它取决于字段 product_uom_qtyx_unitparcarton

我想要的是能够在 x_totalunity 中写入任何值,并且 product_uom_qty 会因此发生变化(product_uom_qty = x_totalunity/x_unitparcarton).但这不起作用。

这是我的代码:

@api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id',
             'x_unitparcarton'  )
def _compute_amount(self):
"""
compute the amounts of the SO line.
"""
for line in self:
    line.x_totalunity = line.product_uom_qty * line.x_unitparcarton

x_totalunity = fields.Float(compute='_compute_amount', string='Total unitéé',
    readonly=False, store=True ,  required=True, copy=True)

最佳答案

首先,从 @api.depends 中删除 discountprice_unittax_id,因为它们似乎与 x_totalunity 的计算无关。

然后,我认为您正在寻找参数 inverse,以在有人手动修改计算字段的情况下执行一些操作:

@api.multi
@api.depends('product_uom_qty', 'x_unitparcarton')
def _compute_x_totalunity(self):
    """Compute the amounts of the SO line."""
    for line in self:
        line.x_totalunity = line.product_uom_qty * line.x_unitparcarton

@api.multi
def _inverse_x_totalunity(self):
    for line in self:
        line.product_uom_qty = line.x_totalunity / line.x_unitparcarton

x_totalunity = fields.Float(
    compute='_compute_x_totalunity',
    inverse='_inverse_x_totalunity',
    string='Total unitéé',
    required=True,
    readonly=False,
    store=True,
    copy=True,
)

关于python - 为什么我的计算域在反面不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57683417/

相关文章:

python 错误?惰性对象具有隐藏状态

Python - Pandas - 分组数据框中所有列的 value_counts

Python:scrapy教程,导入错误没有名为pywintypes的模块

python - 显示错误: "[object with reference: partner_id - partner.id] " for function return

python - Web2Py 工作目录

python - 在 youtube-dl 中添加自定义 HTTP header 以强制提取到文件的直接链接不打开,但下载

python - Django celery 使用 Ajax 检索任务状态

python - 使用 Python 更新之前打印的行(在 CLI 中)?

python - 使用 python odoo 打印报告

python - 如何在一个多对一字段中连接多个字符字段?