當我單擊現有按鈕并訪問odoo 13中的該表單或樹時,我想更改欄位的值(例如更改為當天的日期)。
非常感謝。
uj5u.com熱心網友回復:
您可以在檢索表單視圖之前搜索記錄,更新它,然后正常檢索視圖。
我希望這個答案可以對你有所幫助。
2022-02-06 編輯:示例。
def action_your_button(self):
self.ensure_one()
# Define a proper domain to find the target record
domain = [('your_field', '=', 'some_value')]
record = self.env['your.model'].search(domain, limit=1) # limit=1 to ensure update only 1 record
# Update record
record.write({'field_to_update': new_value})
action = {
'name': 'Action Name',
'type': 'ir.actions.act_window',
'res_model': 'your.model',
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('your_module_name.your_view_form_id').id,
'res_id': record.id,
'target': 'new'
}
return action
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425265.html
