admin管理员组文章数量:1332359
I have these related fields
qty_request = fields.Float('Qty Request')
product_qty = fields.Float('Product Quantity',
digits = 'Product Unit of Measure',
related = "qty_request",
store = True )
Which makes the product_qty automatically filled when the user enter a value on qty_request field. Now I have to make the qty_request editable in the draft state but readonly in the confirm state. While the product_qty is readonly in the draft state but editable in the confirm state.
I coded it like this in my view.xml
<field name="qty_request" readonly="state != 'draft'"/>
<field name="product_qty" string="Quantity" readonly="state != 'confirm'"/>
But the product_qty readonly behavior follows the qty_request field. I'm afraid it's because product_qty is related to qty_request so it also have its behavior. How do I solve this?
I have these related fields
qty_request = fields.Float('Qty Request')
product_qty = fields.Float('Product Quantity',
digits = 'Product Unit of Measure',
related = "qty_request",
store = True )
Which makes the product_qty automatically filled when the user enter a value on qty_request field. Now I have to make the qty_request editable in the draft state but readonly in the confirm state. While the product_qty is readonly in the draft state but editable in the confirm state.
I coded it like this in my view.xml
<field name="qty_request" readonly="state != 'draft'"/>
<field name="product_qty" string="Quantity" readonly="state != 'confirm'"/>
But the product_qty readonly behavior follows the qty_request field. I'm afraid it's because product_qty is related to qty_request so it also have its behavior. How do I solve this?
Share Improve this question edited Nov 21, 2024 at 4:17 Nguyễn Mạnh Cường 6082 silver badges17 bronze badges asked Nov 21, 2024 at 2:52 Osama bin MirzaOsama bin Mirza 32 bronze badges1 Answer
Reset to default 0Just make product_qty
computed instead of related (which is a shortcut computed field).
product_qty = fields.Float(
string="Product Quantity",
digits="Product Unit of Measure",
compute="_compute_product_qty",
store=True,
readonly=True,
@api.depends("state", "qty_request")
def _compute_product_qty(self):
for record in self:
if record.state == "draft":
record.product_qty = record.qty_request
else:
record.product_qty = record.product_qty
本文标签:
版权声明:本文标题:xml - How to make two related fields have different readonly behavior depending on state in odoo 18? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742316843a2451984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论