2016-05-02 43 views
0

我試圖根據company_id獲取每個公司員工的工資數據。Odoo - 如何根據company_id獲取報告數據

這裏是我的代碼:

類hr_wps_report(osv.osv_memory):

_name = 'hr.wps.report' 

_description = 'WPS Report' 

_columns = { 

    'date_from':fields.date("Start Date"), 

    'date_to':fields.date("End Date"), 

    'company_id': fields.many2one('res.company', 'Company', select=True, required=False), 

} 

_defaults = { 

    'date_from': lambda *a: time.strftime('%Y-%m-01'), 

    'date_to': lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10], 

    'company_id': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id, 

} 



def print_report(self, cr, uid, ids, data, context=None): 

    if context is None: 

     context = {} 

    data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'company_id'], context=context)[0] 

    return self.pool['report'].get_action(cr, uid, [], 'hr_wps.report_wpsreport', data=data, context=context) 
在我的報告

在我的嚮導

class wpsreport(report_sxw.rml_parse): 

    def __init__(self, cr, uid, name, context): 

     super(wpsreport, self).__init__(cr, uid, name, context=context) 

     self.localcontext.update({ 

      'time': time, 

      'get_lines': self._get_lines, 

     }) 



    def set_context(self, objects, data, ids, report_type=None): 

     self.date_start = data['form'].get('date_from', time.strftime('%Y-%m-%d')) 

     self.date_end = data['form'].get('date_to', time.strftime('%Y-%m-%d')) 

     self.company_id = data['form'].get('company_id') 



     return super(wpsreport, self).set_context(objects, data, ids, report_type=report_type) 



    def _get_lines(self, form): 

     res = [] 

     self.cr.execute("""SELECT hr_employee.name_related, 

           (SELECT hr_payslip_line.total 

            FROM hr_payslip_line, hr_payslip 

            WHERE hr_employee.id = hr_payslip.employee_id 

             AND hr_payslip_line.slip_id = hr_payslip.id 

             AND hr_payslip_line.code = 'BASIC' 

             AND hr_payslip.date_from BETWEEN %s AND %s) as basic, 

           (SELECT hr_payslip_line.total 

            FROM hr_payslip_line, hr_payslip 

            WHERE hr_employee.id = hr_payslip.employee_id 

             AND hr_payslip_line.slip_id = hr_payslip.id 

             AND hr_payslip_line.code = 'ALLOWANCES' 

             AND hr_payslip.date_from BETWEEN %s AND %s) as total_allowance, 

           (SELECT hr_payslip_line.total 

            FROM hr_payslip_line, hr_payslip 

            WHERE hr_employee.id = hr_payslip.employee_id 

             AND hr_payslip_line.slip_id = hr_payslip.id 

             AND hr_payslip_line.code = 'DEDUCTIONS' 

             AND hr_payslip.date_from BETWEEN %s AND %s) as total_deduction, 

           (SELECT hr_payslip_line.total 

            FROM hr_payslip_line, hr_payslip 

            WHERE hr_employee.id = hr_payslip.employee_id 

             AND hr_payslip_line.slip_id = hr_payslip.id 

             AND hr_payslip_line.code = 'NET' 

             AND hr_payslip.date_from BETWEEN %s AND %s) as total 

         FROM hr_employee, 

          hr_payslip, 

          res_company 

         WHERE hr_payslip.employee_id = hr_employee.id 

         AND hr_payslip.company_id = res_company.id       

         AND hr_payslip.date_from BETWEEN %s AND %s 

         AND hr_payslip.company_id = %s""", (self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.date_start, self.date_end, self.company_id)) 



     employees = self.cr.dictfetchall() 

     for emp in employees: 

      value = {} 

      value['name_related'] = emp['name_related'] 

      value['basic'] = emp['basic'] 

      value['total_allowance'] = emp['total_allowance'] 

      value['total_deduction'] = emp['total_deduction'] 

      value['total'] = emp['total']    

      value['No_working_days'] = 30 

      value['extra_hours'] = 0 

      res.append(value) 

     return res 

但我獲取錯誤:

QWebException:「爲整數無效輸入語法: 「Yourcompany」

AND hr_payslip.company_id = ARRAY [9,'自己公司的]

如何解決此問題?

回答

0

嘗試用:

hr_payslip.company_id.id 
+0

以及問題更換不在hr_payslip.company_id,但在self.company_id,它返回一個字符串值,而不是int ..仍然不知道如何解決它 – youta

0

好,我發現我的問題的答案,並將其固定它

,而不是self.company_id in SQL查詢

self.company_id[0]

相關問題