2020-04-16 00:38:42 +02:00
|
|
|
#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'
|
2020-10-08 05:35:51 +02:00
|
|
|
start_range = fields.Numeric('Start Range', digits=(16, 0), required=True)
|
|
|
|
end_range = fields.Numeric('End Range', digits=(16, 0), required=True)
|
2020-04-16 00:38:42 +02:00
|
|
|
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)
|
|
|
|
|
2020-10-08 05:35:51 +02:00
|
|
|
payment2uvt = float(payment) / uvt_config
|
2020-04-16 00:38:42 +02:00
|
|
|
|
|
|
|
uvt_withholdings = cls.search([
|
2020-10-08 05:35:51 +02:00
|
|
|
('start_range', '>', payment2uvt),
|
|
|
|
('end_range', '<=', payment2uvt),
|
|
|
|
])
|
2020-04-16 00:38:42 +02:00
|
|
|
if uvt_withholdings:
|
|
|
|
uvt_wh = uvt_withholdings[0]
|
2020-10-08 05:35:51 +02:00
|
|
|
value = (payment2uvt - uvt_wh.start_range) * (uvt_wh.rate / 100)
|
2020-04-16 00:38:42 +02:00
|
|
|
res = round(value, 1) * uvt_config
|
|
|
|
res = Decimal(round(res, 2))
|
|
|
|
return res
|