add validate withholding in liquidation

This commit is contained in:
Camilo Sarmiento 2020-10-17 12:00:26 -05:00
parent 462fa08eb3
commit a02924f046
3 changed files with 46 additions and 31 deletions

View file

@ -195,11 +195,56 @@ class Liquidation(Workflow, ModelSQL, ModelView):
for rec in records:
rec.create_move()
@classmethod
def validate_withholding(cls, liquidation):
rec = liquidation
pool = Pool()
UvtWithholding = pool.get('staff.payroll.uvt_withholding')
WageType = pool.get('staff.wage_type')
wage_tax = WageType.search([('type_concept', '=', 'tax')])
if wage_tax:
wage_tax = wage_tax[0]
deductions_month = sum([l.amount for l in rec.lines if l.wage.definition != 'payment'])
salary_full = rec.net_payment
payrolls = {p.end: p for p in rec.payrolls}
max_date = max(payrolls.keys())
if rec.liquidation_date.month == max_date.month:
payroll = payrolls[max_date]
line_tax = None
for line in payroll.lines:
if line.wage_type.type_concept == 'tax' and line.amount:
line_tax = line
if not line_tax:
deductions_month += payroll.get_deductions_month()
salary_args = payroll.get_salary_full(wage_tax)
salary_full += salary_args['salary']
print('Salary ----> ', salary_full)
print('Total Deductions ----> ', deductions_month)
base_salary_withholding = salary_full - deductions_month
amount_tax = UvtWithholding.compute_withholding(
base_salary_withholding)
amount_tax = rec.currency.round(Decimal(amount_tax))
if amount_tax:
create_tax = {
'sequence': wage_tax.sequence,
'wage': wage_tax.id,
'description': wage_tax.name,
'amount': amount_tax * -1,
'days': rec.time_contracting,
'account': wage_tax.credit_account,
}
cls.write([rec], {
'lines': [('create', [create_tax])]
}
)
@classmethod
@ModelView.button
def compute_liquidation(cls, records):
for rec in records:
rec.set_liquidation_lines()
cls.validate_withholding(rec)
def get_dates(self, name):
if name == 'start':

View file

@ -66,35 +66,6 @@ ENTITY_ACCOUNTS = {
'890480023': (2370100105, 72057205),
'890903790': (23700601, 72056801),
}
# ENTITY_ACCOUNTS = {
# '806008394': (23700501, 72056901),
# '860066942': (23700502, 72056902),
# '890300625': (23700503, 72056903),
# '900226715': (23700504, 72056904),
# '830003564': (23700505, 72056905),
# '800251440': (23700506, 72056906),
# '800088702': (23700507, 72056907),
# '901097473': (23700508, 72056908),
# '900156264': (23700509, 72056909),
# '800130907': (23700510, 72056910),
# '860045904': (23700511, 72056911),
# '890102044': (23700514, 72056914),
# '900336004': (23803001, 72057001),
# '800149496': (23803002, 72057002),
# '800144331': (23803004, 72057004),
# '800229739': (23803005, 72057005),
# '860013570': (2370100101, 72057201),
# '890102002': (2370100102, 72057202),
# '890903790': (23700601, 72057101),
# '830113831': (23700501, 72056901),
# '804002105': (23700513, 72056913),
# '900298372': (23700513, 72056913),
# '830009783': (23700516, 72056916),
# '800148514': (23803003, 72057003),
# '891780093': (2370100103, 72057203),
# '890480023': (2370100105, 72057205),
# '809102044': (23700514, 72056914),
# }
class PayrollLine(metaclass=PoolMeta):
@ -423,7 +394,7 @@ class Payroll(metaclass=PoolMeta):
if line.wage_type.month_application:
salary_args = self.get_salary_full(line.wage_type)
unit_value = line.wage_type.compute_unit_price(salary_args)
elif line.wage_type.type_concept == 'interest':
if line.wage_type.type_concept == 'interest':
unit_value = self._compute_interest(line.wage_type, self.start)
elif line.wage_type.type_concept == 'tax':
unit_value = self._compute_line_tax(line)

1
uvt.py
View file

@ -14,7 +14,6 @@ UVT_SUM_FORMULA = {
39: 770
}
class UvtWithholding(ModelSQL, ModelView):
"UVT Withholding"
__name__ = 'staff.payroll.uvt_withholding'