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