fix post liquidation with tax

This commit is contained in:
Wilson Gomez 2023-10-03 11:31:00 -05:00
parent 75e8cc788c
commit aa1ed8d9b8
2 changed files with 67 additions and 33 deletions

View File

@ -367,10 +367,14 @@ class Liquidation(Workflow, ModelSQL, ModelView):
Move.post([move])
def get_moves_lines(self):
Configuration = Pool().get('staff.configuration')
configuration = Configuration(1)
tax = getattr(configuration, 'tax_withholding')
lines_moves = []
to_reconcile = []
grouped = {}
amount = []
party_id = self.employee.party.id
for line in self.lines:
definition = line.wage.definition
concept = line.wage.type_concept
@ -443,53 +447,72 @@ class Liquidation(Workflow, ModelSQL, ModelView):
}
if hasattr(adjust, 'analytic_account') and adjust.analytic_account:
grouped[key]['analytic'] = adjust.analytic_account
if tax and line.tax_base:
tax_line = {
'amount': line.tax_base,
'tax': tax.id,
'type': 'base',
}
grouped[key]['tax_lines'] = [('create', [tax_line])]
grouped[adjust.account.id]['amount'].append(adjust.amount)
amount.append(adjust.amount)
for account_id, values in grouped.items():
_amount = sum(values['amount'])
debit = _amount
credit = _ZERO
lines_moves.append(self._prepare_line(values['description'],
account_id, debit=debit, credit=credit, party_to_pay=values.get('party_to_pay'), analytic=values.get('analytic', None)))
party = values.get('party_to_pay', party_id)
if not party:
party = party_id
line = {
'description': values['description'],
'debit': _amount,
'credit': _ZERO,
'account': account_id,
'party': party,
'tax_lines': values.get('tax_lines', None),
}
# debit = _amount
# credit = _ZERO
lines_moves.append(self._prepare_line(line, values.get('analytic')))
if lines_moves:
lines_moves.append(self._prepare_line(
self.description,
self.account,
credit=sum(amount),
party_to_pay=self.party_to_pay,
))
line = {
'description': self.description,
'debit': _ZERO,
'credit': sum(amount),
'account': self.account.id,
'party': self.party_to_pay if self.party_to_pay else party_id,
}
lines_moves.append(self._prepare_line(line))
return lines_moves, grouped
def _prepare_line(self, description, account_id, debit=_ZERO, credit=_ZERO, party_to_pay=None, analytic=None):
if debit < _ZERO:
credit = debit
debit = _ZERO
elif credit < _ZERO:
debit = credit
credit = _ZERO
def _prepare_line(self, line, analytic=None):
if line['debit'] < _ZERO:
line['credit'] = abs(line['debit'])
line['debit'] = _ZERO
elif line['credit'] < _ZERO:
line['debit'] = abs(line['credit'])
line['credit'] = _ZERO
credit = abs(credit)
debit = abs(debit)
party_id = self.employee.party.id
if party_to_pay:
party_id = party_to_pay.id
res = {
'description': description,
'debit': debit,
'credit': credit,
'account': account_id,
'party': party_id,
}
# credit = abs(credit)
# debit = abs(debit)
# party_id = self.employee.party.id
# if party_to_pay:
# party_id = party_to_pay.id
# res = {
# 'description': description,
# 'debit': debit,
# 'credit': credit,
# 'account': account_id,
# 'party': party_id,
# }
if analytic:
res['analytic_lines'] = [
line['analytic_lines'] = [
('create', [{
'debit': res['debit'],
'credit': res['credit'],
'debit': line['debit'],
'credit': line['credit'],
'account': analytic.id,
'date': self.liquidation_date
}])]
return res
return line
def _get_dates(self):
date_end_contract = None
@ -768,6 +791,9 @@ class LiquidationLine(ModelSQL, ModelView):
party_to_pay = fields.Many2One('party.party', 'Party to Pay')
salary_average = fields.Function(fields.Numeric('Salary Average',
digits=(16, 2)), 'get_average_payroll')
tax_base = fields.Numeric('Tax Base', digits=(16, 2))
is_wage_tax = fields.Function(fields.Boolean('Is wage tax'),
'on_change_with_is_wage_tax')
@classmethod
def __setup__(cls):
@ -783,6 +809,12 @@ class LiquidationLine(ModelSQL, ModelView):
table_h.drop_column('hoard_amount')
super(LiquidationLine, cls).__register__(module_name)
@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_party(self, name=None):
if self.liquidation.employee:
return self.liquidation.employee.party.id

View File

@ -18,6 +18,8 @@ this repository contains the full copyright notices and license terms.-->
<field name="party_to_pay"/>
<label name="salary_average"/>
<field name="salary_average"/>
<label name="tax_base"/>
<field name="tax_base"/>
<notebook colspan="6">
<page string="General" id="general">
<field name="move_lines" colspan="4"/>