電平變化中的自包含虛擬對象當你改變值數據庫層上 沒有發生。 (相對於依賴計算域)
但是原始值在self._origin中傳遞。
@api.onchange('state')
def handed(self):
if self.state == "delivery_success":
# first try this if it work
self._origin.shoes.handed = True
# if not working then you need to fetch the recorod
# from the database first.
shoes = self.env['shoes.order'].search[('id', '=', self.shoes.id)]
shoes.handed = True
但在onchange事件這樣做可能會導致一些問題,成像用戶具有 改變了主意,點擊取消(更改discared),但shoes.handed是 人準備COMMITED數據庫。
我對你的支持是使用相關領域。
class pos_quotation(models.Model):
_inherit = "pos.quotation"
# i'm assuming that your m2o field is shoes
# don't make readonly because you need to save it's changed value
# when you hit save.
handed = fields.Boolean(related="shoes.handed")
@api.onchange('state')
def handed(self):
if self.state == "delivery_success":
self.handed = True
不要忘了這個字段添加到表單視圖,並確保它是無形的 所以用戶不更新值手動
<field name="handed" invisible="1"/>
希望你有這個想法。