67 lines
3.3 KiB
Python
67 lines
3.3 KiB
Python
# -*- coding:utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class HrPayslipLine(models.Model):
|
|
_name = 'hr.payslip.line'
|
|
_description = 'Payslip Line'
|
|
_order = 'contract_id, sequence, code'
|
|
|
|
name = fields.Char(required=True)
|
|
sequence = fields.Integer(required=True, index=True, default=5,
|
|
help='Use to arrange calculation sequence')
|
|
code = fields.Char(required=True,
|
|
help="The code of salary rules can be used as reference in computation of other rules. "
|
|
"In that case, it is case sensitive.")
|
|
slip_id = fields.Many2one('hr.payslip', string='Pay Slip', required=True, ondelete='cascade')
|
|
salary_rule_id = fields.Many2one('hr.salary.rule', string='Rule', required=True)
|
|
contract_id = fields.Many2one('hr.contract', string='Contract', required=True, index=True)
|
|
employee_id = fields.Many2one('hr.employee', string='Employee', required=True)
|
|
rate = fields.Float(string='Rate (%)', digits='Payroll Rate', default=100.0)
|
|
amount = fields.Monetary()
|
|
quantity = fields.Float(digits='Payroll', default=1.0)
|
|
total = fields.Monetary(string='Total')
|
|
ytd = fields.Monetary(string='YTD')
|
|
|
|
amount_select = fields.Selection(related='salary_rule_id.amount_select', readonly=True)
|
|
amount_fix = fields.Float(related='salary_rule_id.amount_fix', readonly=True)
|
|
amount_percentage = fields.Float(related='salary_rule_id.amount_percentage', readonly=True)
|
|
appears_on_payslip = fields.Boolean(related='salary_rule_id.appears_on_payslip', readonly=True)
|
|
category_id = fields.Many2one(related='salary_rule_id.category_id', readonly=True)
|
|
partner_id = fields.Many2one(related='salary_rule_id.partner_id', readonly=True)
|
|
|
|
date_from = fields.Date(string='From', related="slip_id.date_from", store=True)
|
|
date_to = fields.Date(string='To', related="slip_id.date_to", store=True)
|
|
company_id = fields.Many2one(related='slip_id.company_id')
|
|
currency_id = fields.Many2one('res.currency', related='slip_id.currency_id')
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for values in vals_list:
|
|
if 'employee_id' not in values or 'contract_id' not in values:
|
|
payslip = self.env['hr.payslip'].browse(values.get('slip_id'))
|
|
values['employee_id'] = values.get('employee_id') or payslip.employee_id.id
|
|
values['contract_id'] = values.get('contract_id') or payslip.contract_id and payslip.contract_id.id
|
|
if not values['contract_id']:
|
|
raise UserError(_('You must set a contract to create a payslip line.'))
|
|
return super(HrPayslipLine, self).create(vals_list)
|
|
|
|
def get_payslip_styling_dict(self):
|
|
return {
|
|
'NET': {
|
|
'line_style': 'color:#875A7B;',
|
|
'line_class': 'o_total o_border_bottom fw-bold',
|
|
},
|
|
'GROSS': {
|
|
'line_style': 'color:#00A09D;',
|
|
'line_class': 'o_subtotal o_border_bottom',
|
|
},
|
|
'BASIC': {
|
|
'line_style': 'color:#00A09D;',
|
|
'line_class': 'o_subtotal o_border_bottom',
|
|
},
|
|
}
|