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']
|
|
|
|
|
2020-10-09 01:26:49 +02:00
|
|
|
UVT_SUM_FORMULA = {
|
|
|
|
28: 10,
|
|
|
|
33: 69,
|
|
|
|
35: 162,
|
|
|
|
37: 268,
|
|
|
|
39: 770
|
|
|
|
}
|
|
|
|
|
2020-04-16 00:38:42 +02:00
|
|
|
|
|
|
|
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)
|
2020-10-09 01:26:49 +02:00
|
|
|
end_range = fields.Numeric('End Range', digits=(16, 0))
|
|
|
|
rate = fields.Numeric('Rate', digits=(16, 0), required=True)
|
2020-04-16 00:38:42 +02:00
|
|
|
|
|
|
|
@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
|
2020-10-09 01:26:49 +02:00
|
|
|
uvt_config = Decimal(configuration.uvt_value)
|
2020-04-16 00:38:42 +02:00
|
|
|
|
2020-10-09 01:26:49 +02:00
|
|
|
percent_exent = Decimal('0.75')
|
|
|
|
payment2uvt = Decimal(payment * percent_exent) / uvt_config
|
2020-04-16 00:38:42 +02:00
|
|
|
uvt_withholdings = cls.search([
|
2020-10-09 01:26:49 +02:00
|
|
|
['AND', ['OR',
|
|
|
|
[
|
|
|
|
('start_range', '<', payment2uvt),
|
|
|
|
('end_range', '>=', payment2uvt)
|
|
|
|
],
|
|
|
|
[
|
|
|
|
('start_range', '<', payment2uvt),
|
|
|
|
('end_range', '=', None)
|
|
|
|
],
|
|
|
|
]]
|
2020-10-08 05:35:51 +02:00
|
|
|
])
|
2020-04-16 00:38:42 +02:00
|
|
|
if uvt_withholdings:
|
|
|
|
uvt_wh = uvt_withholdings[0]
|
2020-10-09 01:26:49 +02:00
|
|
|
rate = uvt_wh.rate
|
|
|
|
add_sum = UVT_SUM_FORMULA[rate] if UVT_SUM_FORMULA.get(rate) else 0
|
2020-10-09 23:12:11 +02:00
|
|
|
print(payment)
|
|
|
|
print(payment2uvt, rate)
|
2020-10-09 01:26:49 +02:00
|
|
|
value = (payment2uvt - uvt_wh.start_range) * Decimal(rate / 100) + add_sum
|
2020-10-09 23:12:11 +02:00
|
|
|
print(value)
|
2020-04-16 00:38:42 +02:00
|
|
|
res = round(value, 1) * uvt_config
|
2020-10-09 23:12:11 +02:00
|
|
|
print(res)
|
2020-04-16 00:38:42 +02:00
|
|
|
res = Decimal(round(res, 2))
|
|
|
|
return res
|