From d4764194a0eb3885d1f5bdca83eb6f844ecf3102 Mon Sep 17 00:00:00 2001 From: Wilson Gomez Date: Tue, 3 Oct 2023 08:40:49 -0500 Subject: [PATCH] add line tax and base tax in account_move --- configuration.py | 5 ++++- payroll.py | 39 ++++++++++++++++++++----------------- uvt.py | 9 ++++----- view/configuration_form.xml | 2 ++ view/payroll_line_form.xml | 2 ++ 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/configuration.py b/configuration.py index 802a0da..ef6b7b0 100644 --- a/configuration.py +++ b/configuration.py @@ -2,7 +2,7 @@ # this repository contains the full copyright notices and license terms. from trytond.model import fields from trytond.pool import PoolMeta -from trytond.pyson import Id +from trytond.pyson import Id, Eval class Configuration(metaclass=PoolMeta): @@ -26,3 +26,6 @@ class Configuration(metaclass=PoolMeta): limit_shift_month = fields.Integer('Limit Shift Month') wage_shift_fixed = fields.Many2One('staff.wage_type', 'Wage Shift Fixed') + tax_withholding = fields.Many2One('account.tax', 'Tax Withholding', + domain=[('company', '=', Eval('company', -1))], + depends=['company']) diff --git a/payroll.py b/payroll.py index f274d62..9b89c11 100644 --- a/payroll.py +++ b/payroll.py @@ -49,18 +49,24 @@ class PayrollLine(metaclass=PoolMeta): is_event = fields.Boolean('Is Event') start_date = fields.Date('Start Date', depends=['is_event'], - states={ - 'invisible': ~Eval('is_event'), - }) + states={'invisible': ~Eval('is_event')}) end_date = fields.Date('End Date', depends=['is_event'], - states={ - 'invisible': ~Eval('is_event'), - }) + states={'invisible': ~Eval('is_event')}) move_lines = fields.Many2Many('staff.payroll.line-move.line', 'line', 'move_line', 'Payroll Line - Move Line') origin = fields.Reference("Origin", selection='get_origin') amount_60_40 = fields.Numeric('Amount 60/40', digits=(16, 2), depends=['wage_type']) + tax_base = fields.Numeric('Tax Base', digits=(16, 2), states={ + 'invisible': ~Eval('is_wage_tax', False)}, depends=['wage_type', 'is_wage_tax']) + is_wage_tax = fields.Function(fields.Boolean('Is wage tax'), + 'on_change_with_is_wage_tax') + + @fields.depends('wage_type') + def on_change_with_is_wage_tax(self, name=None): + if self.wage_type: + return self.wage_type.type_concept == 'tax' + return False def get_expense_amount(self, wage_type): expense = super(PayrollLine, self).get_expense_amount(wage_type) @@ -164,8 +170,8 @@ class Payroll(metaclass=PoolMeta): else: account_id = line.wage_type.debit_account.id grouped.update({account_id: { - 'lines': list(line.move_lines) - }}) + 'lines': list(line.move_lines) + }}) for p in self.move.lines: if p.account.id not in grouped or ( p.account.type.statement not in ('balance')) or p.reconciliation: @@ -669,6 +675,7 @@ class Payroll(metaclass=PoolMeta): def update_wage_no_salary(self, cache_wage_dict): PayrollLine = Pool().get('staff.payroll.line') att_getter = attrgetter('wage_type.type_concept', 'wage_type.month_application') + tax_base = None for line in self.lines: wage = cache_wage_dict[line.wage_type.id] type_concept, month_application = att_getter(line) @@ -678,10 +685,12 @@ class Payroll(metaclass=PoolMeta): if type_concept == 'interest': unit_value = self._compute_interest(wage, self.start) elif type_concept == 'tax': - unit_value = self._compute_line_tax(line, wage) + unit_value, tax_base = self._compute_line_tax(line, wage) + if unit_value > 0: + tax_base = Decimal(str(round(tax_base, 2))) else: continue - PayrollLine.write([line], {'unit_value': unit_value}) + PayrollLine.write([line], {'unit_value': unit_value, 'tax_base': tax_base}) def _get_payrolls_contract(self): dom_payroll = [('employee', '=', self.employee.id)] @@ -880,24 +889,18 @@ class Payroll(metaclass=PoolMeta): deductions_renta_renta25c = deductions_renta + renta25c ret_general = self.check_limit(base_salary_withholding, 'renta_deductions', deductions_renta_renta25c) - # percent_ret_general = base_salary_withholding * \ - # LIM_PERCENT_DEDUCTIBLE['renta_deductions'] / 100 - # ret_general = base_salary_withholding * \ - # LIM_UVT_DEDUCTIBLE['renta_deductions'] / 100 - # if deductions_renta >= lim_rete_deductions: - # deductions_renta = lim_rete_deductions print(deductions_renta, 'renta') print(renta25c, 'renta 25') print(ret_general, 'renta general') if deductions_renta_renta25c > ret_general: - deductions_renta_renta25c = lim_rete_deductions + deductions_renta_renta25c = ret_general print(deductions_renta_renta25c, 'rr25', base_salary_withholding) base_salary_withholding -= deductions_renta_renta25c unit_value = UvtWithholding.compute_withholding( base_salary_withholding) unit_value = self.currency.round(Decimal(unit_value)) - return unit_value + return unit_value, base_salary_withholding def get_non_fiscal_amount(self, name=None): res = _ZERO diff --git a/uvt.py b/uvt.py index f5faf17..497e13e 100644 --- a/uvt.py +++ b/uvt.py @@ -48,10 +48,9 @@ class UvtWithholding(ModelSQL, ModelView): return res uvt_config = Decimal(configuration.uvt_value) - percent_exent = Decimal('0.75') - # payment2uvt = Decimal(payment) / uvt_config - payment2uvt = Decimal(payment * percent_exent) / uvt_config - print(payment) + # percent_exent = Decimal('0.75') + # payment2uvt = Decimal(payment * percent_exent) / uvt_config + payment2uvt = Decimal(payment) / uvt_config # print('depurada', Decimal(payment * percent_exent)) uvt_withholdings = cls.search([ ['AND', ['OR', [ @@ -75,5 +74,5 @@ class UvtWithholding(ModelSQL, ModelView): # res = round(value, 1) * uvt_config res = value * uvt_config print('respuesta >', res) - res = Decimal(round(res, 2)) + res = Decimal(round(res, -3)) return res diff --git a/view/configuration_form.xml b/view/configuration_form.xml index fcaba6b..944bae2 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -20,6 +20,8 @@ this repository contains the full copyright notices and license terms. -->