minor fix liquidation
This commit is contained in:
parent
c823e4a214
commit
f9d4660560
142
liquidation.py
142
liquidation.py
|
@ -5,7 +5,8 @@ from trytond.model import Workflow, ModelSQL, ModelView, fields
|
|||
from trytond.pool import Pool
|
||||
from trytond.report import Report
|
||||
from trytond.pyson import Eval, If, Bool
|
||||
from trytond.wizard import Wizard, StateView, Button, StateTransition, StateReport
|
||||
from trytond.wizard import (Wizard, StateView, Button,
|
||||
StateTransition, StateReport)
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.i18n import gettext
|
||||
from .exceptions import (
|
||||
|
@ -23,7 +24,7 @@ BONUS_SERVICE = ['bonus_service']
|
|||
CONTRACT = [
|
||||
'bonus_service', 'health', 'retirement', 'unemployment', 'interest',
|
||||
'holidays', 'convencional_bonus'
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
class Liquidation(Workflow, ModelSQL, ModelView):
|
||||
|
@ -38,42 +39,42 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
required=True, states=STATES, depends=['start_period'])
|
||||
kind = fields.Selection([
|
||||
('contract', 'Contract'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('interest', 'Interest'),
|
||||
('unemployment', 'Unemployment'),
|
||||
('holidays', 'Vacation'),
|
||||
('convencional_bonus', 'Convencional Bonus'),
|
||||
], 'Kind', required=True, states=STATES)
|
||||
('contract', 'Contract'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('interest', 'Interest'),
|
||||
('unemployment', 'Unemployment'),
|
||||
('holidays', 'Vacation'),
|
||||
('convencional_bonus', 'Convencional Bonus'),
|
||||
], 'Kind', required=True, states=STATES)
|
||||
liquidation_date = fields.Date('Liquidation Date', states=STATES,
|
||||
required=True)
|
||||
required=True)
|
||||
lines = fields.One2Many('staff.liquidation.line', 'liquidation',
|
||||
'Lines', states=STATES, depends=['employee', 'state'])
|
||||
'Lines', states=STATES, depends=['employee', 'state'])
|
||||
gross_payments = fields.Function(fields.Numeric(
|
||||
'Gross Payments', states=STATES, digits=(16, 2)),
|
||||
'get_sum_operation')
|
||||
'Gross Payments', states=STATES, digits=(16, 2)),
|
||||
'get_sum_operation')
|
||||
total_deductions = fields.Function(fields.Numeric(
|
||||
'Total Deductions', states=STATES, digits=(16, 2)),
|
||||
'get_sum_operation')
|
||||
'Total Deductions', states=STATES, digits=(16, 2)),
|
||||
'get_sum_operation')
|
||||
net_payment = fields.Function(fields.Numeric(
|
||||
'Net Payment', states=STATES, digits=(16, 2)),
|
||||
'get_net_payment')
|
||||
'Net Payment', states=STATES, digits=(16, 2)),
|
||||
'get_net_payment')
|
||||
time_contracting = fields.Integer('Time Contracting', states=STATES,
|
||||
depends=['start_period', 'end_period', 'employee'])
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('posted', 'Posted'),
|
||||
('cancel', 'Cancel'),
|
||||
], 'State', readonly=True)
|
||||
('draft', 'Draft'),
|
||||
('confirmed', 'Confirmed'),
|
||||
('posted', 'Posted'),
|
||||
('cancel', 'Cancel'),
|
||||
], 'State', readonly=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True,
|
||||
states={
|
||||
'readonly': (Eval('state') != 'draft') | Eval('lines', [0]),
|
||||
},
|
||||
},
|
||||
domain=[
|
||||
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', 0)),
|
||||
],
|
||||
],
|
||||
depends=['state'], select=True)
|
||||
description = fields.Char('Description', states=STATES, select=True)
|
||||
cause = fields.Char('Cause', states=STATES)
|
||||
|
@ -84,7 +85,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
required=True, states={
|
||||
'readonly': ((Eval('state') != 'draft')
|
||||
| (Eval('lines', [0]) & Eval('currency'))),
|
||||
},
|
||||
},
|
||||
depends=['state'])
|
||||
move = fields.Many2One('account.move', 'Move', readonly=True)
|
||||
contract = fields.Many2One('staff.contract', 'Contract',
|
||||
|
@ -95,10 +96,10 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
])
|
||||
payrolls = fields.Function(fields.Many2Many('staff.payroll',
|
||||
None, None, 'Payroll', depends=['start_period', 'end_period'],
|
||||
domain=[
|
||||
('employee', '=', Eval('employee')),
|
||||
('kind', '=', 'normal'),
|
||||
],), 'get_payrolls')
|
||||
domain=[
|
||||
('employee', '=', Eval('employee')),
|
||||
('kind', '=', 'normal'),
|
||||
],), 'get_payrolls')
|
||||
start = fields.Function(fields.Date('Start Date'), 'get_dates')
|
||||
end = fields.Function(fields.Date('End Date'), 'get_dates')
|
||||
party_to_pay = fields.Many2One('party.party', 'Party to Pay', states=STATES)
|
||||
|
@ -141,8 +142,8 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
sql_table = cls.__table__()
|
||||
|
||||
cursor.execute(*sql_table.update(
|
||||
[sql_table.kind], ['holidays'],
|
||||
where=sql_table.kind == 'vacation'))
|
||||
[sql_table.kind], ['holidays'],
|
||||
where=sql_table.kind == 'vacation'))
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
@ -189,7 +190,8 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
def confirm(cls, records):
|
||||
for rec in records:
|
||||
if not rec.contract:
|
||||
raise LiquidationEmployeeError(gettext('staff_payroll_co.msg_dont_contract'))
|
||||
raise LiquidationEmployeeError(
|
||||
gettext('staff_payroll_co.msg_dont_contract'))
|
||||
rec.set_number()
|
||||
|
||||
@classmethod
|
||||
|
@ -227,13 +229,14 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
'debit_account.name', 'credit_account.name',
|
||||
'deduction_account.name', 'account_60_40.name'
|
||||
]
|
||||
wage_tax = WageType.search_read([('type_concept', '=', 'tax')], fields_names=fields_names)
|
||||
wage_tax = WageType.search_read([('type_concept', '=', 'tax')],
|
||||
fields_names=fields_names)
|
||||
if not wage_tax:
|
||||
return
|
||||
|
||||
wage_tax = wage_tax[0]
|
||||
deductions_month = sum([
|
||||
l.amount for l in rec.lines if l.wage.definition != 'payment'
|
||||
ln.amount for ln in rec.lines if ln.wage.definition != 'payment'
|
||||
])
|
||||
salary_full = rec.net_payment
|
||||
payrolls = {p.end: p for p in rec.payrolls}
|
||||
|
@ -253,7 +256,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
base_salary_withholding = salary_full - deductions_month
|
||||
amount_tax = UvtWithholding.compute_withholding(
|
||||
base_salary_withholding)
|
||||
base_salary_withholding)
|
||||
amount_tax = rec.currency.round(Decimal(amount_tax))
|
||||
if amount_tax:
|
||||
create_tax = {
|
||||
|
@ -277,7 +280,8 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
@classmethod
|
||||
def copy(cls, records, default=None):
|
||||
raise RecordDuplicateError(gettext('staff_payroll_co.msg_cannot_duplicate_record'))
|
||||
raise RecordDuplicateError(
|
||||
gettext('staff_payroll_co.msg_cannot_duplicate_record'))
|
||||
|
||||
def get_dates(self, name):
|
||||
res = None
|
||||
|
@ -318,7 +322,10 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
Payroll = Pool().get('staff.payroll')
|
||||
Wage = Pool().get('staff.wage_type')
|
||||
wage, = Wage.search([('type_concept', '=', 'unemployment')])
|
||||
res = Payroll.get_salary_average(self.end, self.employee, self.contract, wage)
|
||||
res = Payroll.get_salary_average(
|
||||
self.end,
|
||||
self.employee,
|
||||
self.contract, wage)
|
||||
values = [self.end_period.end]
|
||||
if self.contract.end_date:
|
||||
values.append(self.contract.end_date)
|
||||
|
@ -347,11 +354,12 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
}])
|
||||
self.write([self], {'move': move.id})
|
||||
for ml in move.lines:
|
||||
if ml.account.id not in grouped.keys() or (
|
||||
ml.account.type.statement not in ('balance')):
|
||||
statement = ml.account.type.statement
|
||||
account_id = ml.account.id
|
||||
if account_id not in grouped.keys() or (statement not in ('balance')):
|
||||
continue
|
||||
to_reconcile = [ml]
|
||||
to_reconcile.extend(grouped[ml.account.id]['lines'])
|
||||
to_reconcile.extend(grouped[account_id]['lines'])
|
||||
if len(to_reconcile) > 1:
|
||||
MoveLine.reconcile(set(to_reconcile))
|
||||
Move.post([move])
|
||||
|
@ -406,7 +414,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
credit = _ZERO
|
||||
|
||||
lines_moves.append(self._prepare_line(values['description'],
|
||||
account_id, debit=debit, credit=credit, analytic=values.get('analytic', None)))
|
||||
account_id, debit=debit, credit=credit, analytic=values.get('analytic', None)))
|
||||
if lines_moves:
|
||||
lines_moves.append(self._prepare_line(
|
||||
self.description,
|
||||
|
@ -467,32 +475,34 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
date_start = self.start_period.start
|
||||
if self.contract.start_date > self.start_period.start:
|
||||
date_start = self.contract.start_date
|
||||
|
||||
# if self.contract.futhermores:
|
||||
# date_end_contract = self.contract.finished_date
|
||||
|
||||
date_end = self.end_period.end
|
||||
# if date_end_contract and date_end_contract <= self.end_period.end:
|
||||
# date_end = date_end_contract
|
||||
# elif self.contract.end_date and self.contract.end_date < self.end_period.end:
|
||||
# date_end = self.contract.end_date
|
||||
# date_end = self.end_period.end
|
||||
date_end = self.contract.finished_date
|
||||
return date_start, date_end
|
||||
|
||||
@classmethod
|
||||
def get_moves_lines_pending(cls, employee, wage_type, effective_date):
|
||||
def get_moves_lines_pending(cls, employee, wage_type, effective_date, moves=[]):
|
||||
MoveLine = Pool().get('account.move.line')
|
||||
lines = []
|
||||
if not wage_type.credit_account:
|
||||
return
|
||||
|
||||
account_id = wage_type.credit_account.id
|
||||
lines = MoveLine.search([
|
||||
domain = [
|
||||
('move.date', '<=', effective_date),
|
||||
('credit', '>', 0),
|
||||
('account', '=', account_id),
|
||||
('party', '=', employee.party.id),
|
||||
('reconciliation', '=', None),
|
||||
])
|
||||
]
|
||||
if moves:
|
||||
domain.append(
|
||||
[
|
||||
'OR',
|
||||
('move', 'in', moves),
|
||||
('move.origin', '=', None),
|
||||
])
|
||||
lines = MoveLine.search(domain)
|
||||
|
||||
return lines
|
||||
|
||||
@classmethod
|
||||
|
@ -522,6 +532,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
])
|
||||
wages = {}
|
||||
wages_target = {}
|
||||
moves = [p.move.id for p in payrolls]
|
||||
for payroll in payrolls:
|
||||
for l in payroll.lines:
|
||||
if not l.wage_type.contract_finish:
|
||||
|
@ -534,7 +545,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
|
||||
if l.wage_type.id not in wages_target.keys():
|
||||
mlines = self.get_moves_lines_pending(
|
||||
payroll.employee, l.wage_type, date_end
|
||||
payroll.employee, l.wage_type, date_end, moves
|
||||
)
|
||||
if not mlines:
|
||||
continue
|
||||
|
@ -544,15 +555,6 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
l.wage_type,
|
||||
]
|
||||
|
||||
# wages.append(l.wage_type.id)
|
||||
# This looks for lines provisioned before start period
|
||||
# old_lines_provisioned = MoveLine.search([
|
||||
# ('party', '=', self.employee.party.id),
|
||||
# ('move.date', '<', date_start),
|
||||
# ('reconciliation', '=', None),
|
||||
# ('account', '=', account_id),
|
||||
# ])
|
||||
# lines.extend(old_lines_provisioned)
|
||||
for (account_id, lines, wage_type) in wages_target.values():
|
||||
values = []
|
||||
lines_to_reconcile = []
|
||||
|
@ -620,7 +622,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
try:
|
||||
date_start, date_end = self._get_dates()
|
||||
delta = self.contract.get_time_days(date_start, date_end)
|
||||
except:
|
||||
except Exception:
|
||||
raise LiquidationEmployeeError(
|
||||
gettext('staff_payroll_co.msg_error_dates', s=self.employee.party.name))
|
||||
delta = 0
|
||||
|
@ -864,12 +866,12 @@ class LiquidationGroupStart(ModelView):
|
|||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
required=True, depends=['start_period'])
|
||||
kind = fields.Selection([
|
||||
('contract', 'Contract'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('interest', 'Interest'),
|
||||
('holidays', 'Vacation'),
|
||||
('unemployment', 'Unemployment'),
|
||||
], 'Kind', required=True)
|
||||
('contract', 'Contract'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('interest', 'Interest'),
|
||||
('holidays', 'Vacation'),
|
||||
('unemployment', 'Unemployment'),
|
||||
], 'Kind', required=True)
|
||||
liquidation_date = fields.Date('Liquidation Date', required=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
description = fields.Char('Description', required=True)
|
||||
|
|
Loading…
Reference in New Issue