123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- # -*- coding: utf-8 -*-
- from openerp import models, fields, api
- from datetime import datetime
- from pytz import timezone
- DATE_FORMAT = '%Y-%m'
- class HrEmployee(models.Model):
- _inherit = 'hr.employee'
- def get_timezone(self):
- tz_name = self._context.get('tz') or self.env.user.tz
- return timezone(tz_name)
- def get_server_datetime(self):
- return datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
- @api.model
- def getHHRRWidget(self,domain):
- user_store = self.env.user.store_id.id
- domain.append(('store_id','=',user_store))
- HrEmployee = self.env['hr.employee'].search(domain)
- date_server = self.get_server_datetime()
- values = []
- employee_ids = []
- for employee in HrEmployee:
- total = 0
- ipse = 0
- amortized = 0
- faltas = 0
- residual = 0
- HrPayslip = self.env['hr.payslip'].search([('employee_id','=',employee.id),('state','in',['done','paid']),('date_to','like',date_server)])
- for payslip in HrPayslip:
- HrPayslipLine = self.env['hr.payslip.line'].search([('slip_id','=',payslip.id),])
- for line in HrPayslipLine:
- if(line.code in ['BASIC','CMS']):
- total += line.total
- if(line.code in ['IPSE']):
- ipse += (line.total*-1)
- if(line.code in ['ADPER']):
- amortized += (line.total*-1)
- if(line.code in ['FALTAS']):
- faltas += (line.total*-1)
- if(line.code in ['NET']):
- residual += line.total
- values.append({
- 'id': employee.id,
- 'name': employee.name,
- 'identification_id': employee.identification_id,
- 'payslip': total - ipse - faltas,
- 'amortized': amortized,
- 'residual': residual,
- })
- return values
- def get_account_account_ipsc (self, code):
- return self.env['account.account'].search([('code', '=', code)])
- @api.model
- def getPayslipTotalWidget(self,domain):
- HrPayslip = self.env['hr.payslip'].search(domain)
- values = []
- total = 0
- ipse = 0
- ipsc = 0
- faltas = 0
- amortized = 0
- residual = 0
- for payslip in HrPayslip:
- HrPayslipLine = self.env['hr.payslip.line'].search([('slip_id','=',payslip.id)])
- accountIpsC = self.get_account_account_ipsc('245000')
- accountId= accountIpsC.id
- for line in HrPayslipLine:
- if(line.code in ['BASIC','CMS']):
- total += line.total
- if(line.code in ['FALTAS']):
- faltas += (line.total*-1)
- if(line.code in ['IPSE']):
- AccountMoveLine = self.env['account.move.line'].search([('move_id','=',payslip.move_id.id),('partner_id', '=', payslip.employee_id.address_home_id.id),('reconcile_id','=',False),('credit','>',0)])
- if(len(AccountMoveLine) > 0):
- ipse += (line.total*-1)
- if(line.code in ['IPSC']):
- AccountMoveLine = self.env['account.move.line'].search([('move_id','=',payslip.move_id.id),('ref', '=', payslip.number),('reconcile_id', '=',False),('account_id', '=', accountId)])
- if(len(AccountMoveLine) > 0):
- ipsc += line.total
- if(payslip.state == 'done'):
- if(line.code in ['NET']):
- residual += line.total
- amortized = total - ipse - faltas - residual
- values.append({
- 'payslip': total - ipse - faltas,
- 'amortized': amortized,
- 'residual': residual,
- 'ipse': ipse,
- 'ipsc': ipsc,
- })
- return values
|