问题描述
我已经尝试过向导的报告,但它不起作用,因为 return 语句打破了循环...... 然后我尝试创建单独的树视图和表单视图,使用 obj.create 传递值,但在此我无法将字典值发送到 odoo 字段。 类出勤报告向导预(models.TransientModel): _name = "出席.report.wizard"
select_all_employees = fields.Boolean(string="Select All Employees")
person_ids = fields.Many2many('hr.employee',string="Employees")
date_from = fields.Date(string="From")
date_to = fields.Date(string="To")
employee_id = fields.Many2one('hr.employee')
data = fields.Binary(compute="generate_report")
@api.onchange('select_all_employees')
def select_employees(self):
if self.select_all_employees:
# print(type(self.person_ids))
var = self.env['hr.employee'].search([('id','>',0)])
# print(type(var))
list = []
for rec in var:
list.append(rec.id)
self.person_ids = list
else:
self.person_ids = [(6,[])] # for clearing the selected employees
def generate_report(self):
user_tz = pytz.timezone(self.env.context.get('tz')) or self.env.user.tz
for employee in self.person_ids:
if self.env["attendance.report.wizard"].search([('employee_id','=',employee.id)]):
break
else:
data = {
'model': 'attendance.report.wizard.pre','form': self.read()[0]
}
selected_person = employee
attendances = self.env['hr.attendance'].search([('employee_id',selected_person.id),('check_in','>=',self.date_from),'<=',self.date_to)])
attendances_list = []
for att in attendances:
vals = {
'employee_code': att.x_employee_code,'person_id': att.employee_id.name,'check_in': pytz.utc.localize(att.check_in).astimezone(user_tz),'check_out': pytz.utc.localize(att.check_out).astimezone(user_tz),'shift_name': att.employee_id.resource_calendar_id.name,'worked_hours': int(att.worked_hours)
}
attendances_list.append(vals)
data['attendances'] = attendances_list
var_obj = self.env['attendance.report.wizard']
var_obj.create({
'employee_id': employee.id,'date_from': self.date_from,'date_to': self.date_to,'data': data,})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)