Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4576 Ansichten
  1. The code will compare if the dates from attendance fit the date_to and date_from of payslip and sum their lates, undertime and overtime.
  2.  
  3. class awb_hr_payslip_extension(osv.osv):
  4.     _name = 'hr.payslip'
  5.     _inherit = 'hr.payslip'
  6.     
  7.     def create(self, cr, uid, vals, context=None):
  8.         # get other input model
  9.         attendance_model = self.pool.get('hr.attendance')
  10.         payslip_model = self.pool.get('hr.payslip')
  11.         #payslip = payslip_model.browse(cr, uid, vals['payslip_id'].id, context=context)
  12.         
  13.         # convert date_to
  14.         date_to = vals['date_to'] + " 23:59:59"
  15.         # filtering / get records depending on filter: name, date from, date to
  16.         # 'name' is datetime field from attendance model
  17.         # vals['field name from hr.payslip']
  18.         attendance_ids = attendance_model.search(cr, uid, [('employee_id', '=', vals['employee_id']), ('name', '>=', vals['date_from']), ('name', "<=", date_to)], count=False)
  19.         
  20.         records_list = attendance_model.browse(cr, uid, attendance_ids)
  21.         total_late = 0
  22.         total_undertime = 0
  23.         total_overtime = 0
  24.         for record in records_list:
  25.             total_late = total_late + record.late
  26.             total_undertime = total_undertime + record.undertime
  27.             total_overtime = total_overtime + record.overtime
  28.         # insert to Other Inputs
  29.         other_input_model = self.pool.get('hr.payslip.input')    
  30.         other_input_model.create(cr, uid, ['name': 'Total Late'], 'code': 'late_deduction', 'amount': total_late, 'contract_id': vals['contract_id']}, context=None)
  31.         other_input.create(cr, uid, {'name': 'Total Undertime', 'code' : 'undertime_deduction', 'amount': total_undertime, 'contract_id': vals['contract_id']}, context=None)
  32.         other_input.create(cr, uid, {'name': 'Total Overtime', 'code': 'overtime_pay', 'amount': total_overtime, 'contract_id': vals['contract_id']}, context=None)
  33.         
  34.         return super(awb_hr_payslip_extension, self).create(cr, uid, vals, context=context)
  35. awb_hr_payslip_extension()

 

this is my error from this code:(

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: payslip_id - payslip.id]

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Nov. 22
6092
3
Apr. 18
7520
2
Juli 25
3563
1
Juli 25
2679
0
Dez. 24
1443