trytonpsk-staff_payroll_co/uvt.py
2020-10-07 22:35:51 -05:00

45 lines
1.5 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'
start_range = fields.Numeric('Start Range', digits=(16, 0), required=True)
end_range = fields.Numeric('End Range', digits=(16, 0), 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) / uvt_config
uvt_withholdings = cls.search([
('start_range', '>', payment2uvt),
('end_range', '<=', payment2uvt),
])
if uvt_withholdings:
uvt_wh = uvt_withholdings[0]
value = (payment2uvt - uvt_wh.start_range) * (uvt_wh.rate / 100)
res = round(value, 1) * uvt_config
res = Decimal(round(res, 2))
return res