Skip to Content
Menu
This question has been flagged
1 Reply
13422 Views

PS:tree view multi edit function was enabled(<tree multi_edit="1">)
While I try to batch modificate the "calculate_start date" of three employees in tree view,will pop up the belew error infomation:
Traceback (most recent call last):
File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20191110-py3.7.egg/odoo/models.py", line 4956, in ensure_one
_id, = self._ids
ValueError: too many values to unpack (expected 1)

File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20191110-py3.7.egg/odoo/models.py", line 4959, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: hr.employee(28, 29, 30)

############

hr_employee_base.py
hire_date = fields.Date(string="Hire Date", default=fields.Date.today)
calculate_start = fields.Date(string="Start Date", default=fields.Date.today, store=True, compute='_get_calculate_date', inverse='_write_calculate_date')

@api.onchange('hire_date')
def _get_calcuate_date(self):
    if self.hire_date > self.calculate_start:
      self.calculate_start = self.hire_date

def _write_calculate_date(self):
     if self.hire_date > self.calculate_start:
     self.calculate_start = self.hire_date

########

hr_employee_view.xml
In Form and Tree view
<field name="hire_date"/>
<field name="calculate_start"/>

Avatar
Discard
Best Answer

Hi,

try to re-write the two functions that you defined like below

@api.onchange('hire_date')
def _get_calcuate_date(self):
for hr_employee_id in self:
if hr_employee_id.hire_date > hr_employee_id.calculate_start:
hr_employee_id.calculate_start = hr_employee_id.hire_date

def _write_calculate_date(self):
for hr_employee_id in self:
if hr_employee_id.hire_date > hr_employee_id.calculate_start:
hr_employee_id.calculate_start = hr_employee_id.hire_date

Regards

Avatar
Discard
Author

Thank you very much,it works now.If you dont mind,one more question please,how to set the specific date like "2022-12-31" as default,not the default date as today?