Add option for liquidate social security
This commit is contained in:
parent
3f894915b9
commit
1e4729e01d
|
@ -88,5 +88,6 @@ def register():
|
|||
employee.UpdateEmployee,
|
||||
payroll.PayrollsMultiPayment,
|
||||
liquidation.LiquidationExport,
|
||||
liquidation.LiquidationDeduction,
|
||||
payroll_auditory.PayrollAuditory,
|
||||
module='staff_payroll_co', type_='wizard')
|
||||
|
|
|
@ -26,6 +26,8 @@ CONTRACT = [
|
|||
'holidays', 'convencional_bonus'
|
||||
]
|
||||
|
||||
concept_social_security = ['health', 'risk', 'box_family', 'retirement', 'fsp']
|
||||
|
||||
|
||||
class Liquidation(Workflow, ModelSQL, ModelView):
|
||||
'Staff Liquidation'
|
||||
|
@ -370,6 +372,8 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
grouped = {}
|
||||
amount = []
|
||||
for line in self.lines:
|
||||
definition = line.wage.definition
|
||||
concept = line.wage.type_concept
|
||||
if line.move_lines:
|
||||
for moveline in line.move_lines:
|
||||
to_reconcile.append(moveline)
|
||||
|
@ -384,16 +388,49 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
grouped[account_id]['amount'].append(amount_line)
|
||||
grouped[account_id]['lines'].append(moveline)
|
||||
amount.append(amount_line)
|
||||
elif line.wage.definition == 'discount':
|
||||
elif concept in concept_social_security:
|
||||
if definition == 'payment':
|
||||
account_credit = line.account.id
|
||||
if account_credit not in grouped.keys():
|
||||
grouped[account_credit] = {
|
||||
'amount': [],
|
||||
'description': line.description,
|
||||
'lines': [],
|
||||
'party_to_pay': line.party_to_pay,
|
||||
}
|
||||
grouped[account_credit]['amount'].append(line.amount * -1)
|
||||
account_debit = line.wage.debit_account.id
|
||||
if account_debit not in grouped.keys():
|
||||
grouped[account_debit] = {
|
||||
'amount': [],
|
||||
'description': line.description,
|
||||
'lines': [],
|
||||
'party_to_pay': line.party_to_pay,
|
||||
}
|
||||
grouped[account_debit]['amount'].append(line.amount)
|
||||
else:
|
||||
account_id = line.account.id
|
||||
if account_id not in grouped.keys():
|
||||
grouped[account_id] = {
|
||||
'amount': [],
|
||||
'description': line.description,
|
||||
'lines': [],
|
||||
'party_to_pay': line.party_to_pay,
|
||||
}
|
||||
grouped[account_id]['amount'].append(line.amount)
|
||||
amount.append(line.amount)
|
||||
if line.wage.expense_formula:
|
||||
expense = line.get_expense_amount()
|
||||
debit_account = line.wage.debit_account
|
||||
grouped[account_id]['amount'].append(expense * -1)
|
||||
if debit_account not in grouped.keys():
|
||||
grouped[debit_account] = {
|
||||
'amount': [],
|
||||
'description': line.description,
|
||||
'lines': [],
|
||||
'party_to_pay': line.party_to_pay,
|
||||
}
|
||||
grouped[debit_account]['amount'].append(expense)
|
||||
|
||||
for adjust in line.adjustments:
|
||||
key = adjust.account.id
|
||||
|
@ -413,7 +450,6 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
_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)))
|
||||
if lines_moves:
|
||||
|
@ -501,6 +537,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
[
|
||||
'OR',
|
||||
('move', 'in', moves),
|
||||
('move.origin', 'not ilike', 'staff.payroll'),
|
||||
('move.origin', '=', None),
|
||||
])
|
||||
lines = MoveLine.search(domain)
|
||||
|
@ -593,12 +630,12 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
}
|
||||
return value
|
||||
|
||||
def calculate_discounts(self):
|
||||
def calculate_social_security(self):
|
||||
LiquidationLine = Pool().get('staff.liquidation.line')
|
||||
wage_no_salary = [mw for mw in self.employee.mandatory_wages \
|
||||
if not mw.wage_type.salary_constitute and mw.wage_type.definition == 'deduction']
|
||||
wages = [mw for mw in self.employee.mandatory_wages \
|
||||
if mw.wage_type.type_concept in concept_social_security]
|
||||
lines_to_create = []
|
||||
for mw in wage_no_salary:
|
||||
for mw in wages:
|
||||
wage = mw.wage_type
|
||||
concepts_salary = [c.id for c in wage.concepts_salary]
|
||||
if concepts_salary:
|
||||
|
@ -608,10 +645,12 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
wage.unit_price_formula,
|
||||
{'salary': salary_full})
|
||||
if amount > 0:
|
||||
if wage.definition != 'payment':
|
||||
amount = amount * -1
|
||||
value = self.get_line_(
|
||||
wage, amount * -1,
|
||||
wage, amount,
|
||||
1,
|
||||
wage.deduction_account.id,
|
||||
wage.credit_account.id,
|
||||
party=mw.party)
|
||||
value['liquidation'] = self
|
||||
lines_to_create.append(value)
|
||||
|
@ -675,7 +714,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
for line in self.lines:
|
||||
if not line.amount:
|
||||
continue
|
||||
if name == 'gross_payments' and line.wage.definition == 'payment':
|
||||
if name == 'gross_payments' and line.wage.definition == 'payment' and line.wage.definition not in ('box_family', 'retirement'):
|
||||
res.append(line.amount)
|
||||
elif name == 'total_deductions' and line.wage.definition != 'payment':
|
||||
res.append(line.amount)
|
||||
|
@ -770,6 +809,15 @@ class LiquidationLine(ModelSQL, ModelView):
|
|||
res = 0
|
||||
return res
|
||||
|
||||
def get_expense_amount(self):
|
||||
expense = 0
|
||||
if self.wage.expense_formula:
|
||||
concepts_salary = [c.id for c in self.wage.concepts_salary]
|
||||
salary = sum(
|
||||
line.amount for line in self.liquidation.lines if line.wage.id in concepts_salary)
|
||||
expense = self.wage.compute_expense(self.wage.expense_formula, {'salary': salary})
|
||||
return expense
|
||||
|
||||
@classmethod
|
||||
def delete(cls, lines):
|
||||
LoanLine = Pool().get('staff.loan.line')
|
||||
|
@ -1260,3 +1308,19 @@ class LiquidationExportReport(Report):
|
|||
report_context['sum_net_payment'] = sum(sum_net_payment)
|
||||
report_context['sum_total_deductions'] = sum(sum_total_deductions)
|
||||
return report_context
|
||||
|
||||
|
||||
class LiquidationDeduction(Wizard):
|
||||
'Liquidation Deduction'
|
||||
__name__ = 'staff.liquidation_calculate_social_security'
|
||||
start_state = 'calculate_social_security'
|
||||
calculate_social_security = StateTransition()
|
||||
|
||||
def transition_calculate_social_security(self):
|
||||
Liquidation = Pool().get('staff.liquidation')
|
||||
liquidations_ids = Transaction().context['active_ids']
|
||||
if liquidations_ids:
|
||||
liquidations = Liquidation.browse(liquidations_ids)
|
||||
for liq in liquidations:
|
||||
liq.calculate_social_security()
|
||||
return 'end'
|
||||
|
|
|
@ -165,5 +165,15 @@ this repository contains the full copyright notices and license terms. -->
|
|||
</record>
|
||||
<menuitem parent="staff.menu_reporting" id="menu_liquidation_report"
|
||||
action="wizard_print_liquidation"/>
|
||||
|
||||
<record model="ir.action.wizard" id="wizard_liquidation_calculate_social_security">
|
||||
<field name="name">Calculate Social Security</field>
|
||||
<field name="wiz_name">staff.liquidation_calculate_social_security</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_liquidation_calculate_social_security_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">staff.liquidation,-1</field>
|
||||
<field name="action" ref="wizard_liquidation_calculate_social_security"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Loading…
Reference in New Issue