gpt4 book ai didi

model - 如何在odoo模型中保存只读/可编辑错误字段的值?

转载 作者:行者123 更新时间:2023-12-01 07:09:46 24 4
gpt4 key购买 nike

我有一个字段,我想在更改时计算它的值,但我不希望用户可以修改它。

如果我将该字段设置为 readonly=1 或 editable=0,则不会存储该值。

我正在尝试为发票设置全局折扣

class account_invoice(models.Model):
_inherit = "account.invoice"

global_discount_p = fields.Float('Descuento porcentaje')
global_discount = fields.Float('Descuento')
neto = fields.Float('Neto')

@api.one
@api.depends('invoice_line.price_subtotal', 'tax_line.amount','global_discount_p')
def _compute_amount(self):
ret = super(account_invoice,self)._compute_amount()
if self.type == 'in_invoice':
self.neto = self.amount_untaxed
discount = self.global_discount_p/100
self.global_discount = self.neto * discount
self.amount_untaxed = self.neto - self.global_discount

for line in self.tax_line:
line.base = self.amount_untaxed
line.amount = line.amount - (line.amount * discount)

self.amount_tax = sum(line.amount for line in self.tax_line)
self.amount_total = self.amount_untaxed + self.amount_tax

return ret

在布局中:
<xpath expr="//field[@name='amount_untaxed']" position="before">
<field name="neto" readonly="1"/>
<field name="global_discount_p" onchange="_compute_amount"/>
<field name="global_discount" readonly="1"/>
</xpath>

它工作得很好,如果我从字段中删除 readonly="1"attrs

最佳答案

odoo11您可以使用 force_save="1"在 xml 文件中

希望能帮到你!!

关于model - 如何在odoo模型中保存只读/可编辑错误字段的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33946981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com