无法在ODOO V8中将计算字段的结果视为普通用户

时间:2017-04-07 04:09:37

标签: python openerp odoo-8

我有一个问题,我有2个浮点计算字段。如果我以管理员身份登录,可以看到他们的结果和价值,但如果我以普通用户身份登录,则无法看到。即使我在我的模块中设置安全性,这里是字段:

class overtime_details(models.Model):
    _name='overtime.overtime_details'

    ovrtm = fields.Float(compute=attd_check, string='Overtime Hour(s)')
    ttalmtp = fields.Float(compute=overtype_count, string='Total Multiplier')

这是我以普通用户身份登录时的图片: enter image description here

然后这是我以管理员身份登录时的图片: enter image description here

这是我的安全权限csv:

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
overtime_formsec,overtime_formsec,model_overtime_overtime,,1,1,1,1
overtime_employee_list,overtime_employee_list,model_overtime_overtime_details,,1,1,1,1
overtime_type_list,overtime_type_list,model_overtime_type_overtime,,1,1,1,1
overtime_type_hours,overtime_type_hours,model_overtime_hour_overtime,,1,1,1,1

这是attd_check函数:

@api.model
    def attd_check(self):
        #import pdb;pdb.set_trace()
        for attds in self:
            if attds.id:
                ov = 0.0
                attd = self.env['hr.attendance']
                paratime = (datetime.strptime(attds.overtime_id.start_date, "%Y-%m-%d %H:%M:%S") - relativedelta(days=1, hours=7)).strftime("%Y-%m-%d 23:59:59")
                signin = attd.search([('name','<=',attds.overtime_id.start_date),
                        ('name','>',paratime),
                         ('employee_id','=',attds.employee_id.id), ('action','=','sign_in')])
                signout = attd.search([('name','>=',attds.overtime_id.end_date), 
                        ('employee_id','=',attds.employee_id.id), ('action','=','sign_out')])
                signout2 = attd.search([('name','<',attds.overtime_id.end_date), ('name','>',attds.overtime_id.start_date),
                            ('employee_id','=',attds.employee_id.id), ('action','=','sign_out')])
                if signin:
                    if signout:
                        ov = attds.env['overtime.overtime'].calc_overtime(attds.overtime_id.start_date, attds.overtime_id.end_date)
                    elif signout2:
                        paramtole = datetime.strptime(signout2.name, "%Y-%m-%d %H:%M:%S").strftime("%M:%S")
                        tolerate = datetime.strptime("15:00", "%M:%S").strftime("%M:%S")
                        tolerate2 = datetime.strptime(str(attds.overtime_id.tolerance), "%M.%S").strftime("%M:%S")
                        if paramtole >= tolerate2 :
                            ov = attds.env['vit_overtime.overtime'].calc_overtime(attds.overtime_id.start_date, signout2.name) + 1
                        elif paramtole < tolerate :
                            ov = attds.env['overtime.overtime'].calc_overtime(attds.overtime_id.start_date, signout2.name)
                        else :
                            ov = attds.env['overtime.overtime'].calc_overtime(attds.overtime_id.start_date, signout2.name)
                    else:
                        ov = 0.0
                else:
                    ov = 0.0

                attds.ovrtm = ov

改写计数功能:

@api.model
    def overtype_count(self):
        #import pdb;pdb.set_trace()
        for det in self:
            if det.id:
                check = self.env['overtime.hour_overtime'].search([('hour_id.code','=',det.overtime_id.overtimetype_id.code)])
                if check:
                    if det.overtime_id.state == 'done':
                        ovt=0
                        counter = 1
                        for hou in check:
                            if det.ovrtm <= 0:
                                det.ovrtm = ovt
                            elif counter <= det.ovrtm:
                                ttal = ovt + hou.calc
                                ovt = ttal
                                counter = counter + 1
                            else :
                                det.ttalmtp = ovt
                    else :
                        det.ttalmtp = 0

我应该怎么做才能解决这个问题,谢谢之前:)

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,所以我在搜索之前添加了sudo()或浏览了我的函数, 例如:

之前:

signin = attd.search([('name','<=',attds.overtime_id.start_date),
                        ('name','>',paratime),
                         ('employee_id','=',attds.employee_id.id), ('action','=','sign_in')])
添加sudo()之后

signin = attd.sudo().search([('name','<=',attds.overtime_id.start_date),
                        ('name','>',paratime),
                         ('employee_id','=',attds.employee_id.id), ('action','=','sign_in')])