问题
I want to update a field by another field
for example when I select an employee I want to update his coordinates after the states done
class Hr_transf_employee(models.Model):
_name = 'hr.employee.transfer'
_rec_name = 'employee_id'
@api.multi
def transfert(self):
self.date_cration == "date_transfer"
if self.region_new :
self.state_work_id = self.region_new.id
if self.country_work_id_new :
self.country_work_id = self.country_work_id_new.id
date_cration = fields.Date(string='Date order', required=True, default=datetime.today())
date_transfer = fields.Date(string='Date transfer')
employee_id = fields.Many2one('hr.employee',string='Employee', required=True)
job_id_new = fields.Many2one('hr.job',string='Job title', required=True)
country_work_id_new = fields.Many2one('res.country', 'Country work new')
state = fields.Selection([
('draft', 'Draft'),
('accept', 'Accept'),
('done', 'Done'),
('cancel', 'Cancel'),
], string='Order Status', readonly=True, copy=False, store=True, default='draft')
I want to update region_new by *state_work_id * and country_work_id_new by *country_work_id * in the model hr.employee if the date_cration >= date_transfer
i try to add in function self.date_cration >= "date_transfer" but it's not apply with date
回答1:
Do you know @api.onchange and @api.depends decorators ?
来源:https://stackoverflow.com/questions/52261821/update-fields-from-other-fields-after-date-odoo