trytonpsk-staff_payroll_co/uvt.py
Camilo Sarmiento af0387c577 migrato to git
2020-04-15 17:38:42 -05:00

43 lines
1.4 KiB
Python

#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
from decimal import Decimal
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
__all__ = ['UvtWithholding']
class UvtWithholding(ModelSQL, ModelView):
"UVT Withholding"
__name__ = 'staff.payroll.uvt_withholding'
uvt_salary = fields.Float('UVT Salary', digits=(16, 2), required=True)
rate = fields.Float('Rate', digits=(16, 2), required=True)
@classmethod
def __setup__(cls):
super(UvtWithholding, cls).__setup__()
@classmethod
def compute_withholding(cls, payment):
"""
Compute unit price for application of withholdings tax to employee
"""
res = Decimal('0.0')
Configuration = Pool().get('staff.configuration')
configuration = Configuration(1)
if not configuration.uvt_value:
return res
uvt_config = float(configuration.uvt_value)
payment2uvt = (float(payment) * 0.75) / uvt_config
uvt_withholdings = cls.search([
('uvt_salary', '<=', payment2uvt),
], order=[('uvt_salary', 'DESC')])
if uvt_withholdings:
uvt_wh = uvt_withholdings[0]
value = (payment2uvt - uvt_wh.uvt_salary) * uvt_wh.rate / 100
res = round(value, 1) * uvt_config
res = Decimal(round(res, 2))
return res