minor fix
This commit is contained in:
parent
0406ba7afb
commit
48336faa1b
108
payroll.py
108
payroll.py
|
@ -3,6 +3,7 @@
|
|||
import calendar
|
||||
from decimal import Decimal
|
||||
from datetime import date, timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import math
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.model import ModelView, fields, Workflow, ModelSQL
|
||||
|
@ -372,6 +373,18 @@ class Payroll(metaclass=PoolMeta):
|
|||
])
|
||||
return payrolls
|
||||
|
||||
def _get_payrolls_period(self, start_date, end_date):
|
||||
_, end_day = calendar.monthrange(end_date.year, end_date.month)
|
||||
start = date(start_date.year, start_date.month, 1)
|
||||
end = date(end_date.year, end_date.month, end_day)
|
||||
payrolls = self.search([
|
||||
('employee', '=', self.employee.id),
|
||||
('start', '>=', start),
|
||||
('start', '<=', end),
|
||||
('contract', '=', self.contract.id)
|
||||
])
|
||||
return payrolls
|
||||
|
||||
def _create_payroll_lines(self, wages, extras, discounts=None):
|
||||
super(Payroll, self)._create_payroll_lines(wages, extras, discounts=None)
|
||||
pool = Pool()
|
||||
|
@ -387,12 +400,21 @@ class Payroll(metaclass=PoolMeta):
|
|||
])
|
||||
lines_to_reconcile = []
|
||||
values = []
|
||||
for m in move_lines:
|
||||
values.append(abs(m.debit - m.credit))
|
||||
lines_to_reconcile.append(m.id)
|
||||
amount = sum(values) + sum(amount_line)
|
||||
if line.wage_type.type_concept == 'holidays':
|
||||
unit_value = line.unit_value
|
||||
amount = line.amount
|
||||
for m in move_lines:
|
||||
values.append(abs(m.debit - m.credit))
|
||||
if sum(values) <= amount:
|
||||
lines_to_reconcile.append(m.id)
|
||||
else:
|
||||
for m in move_lines:
|
||||
values.append(abs(m.debit - m.credit))
|
||||
lines_to_reconcile.append(m.id)
|
||||
amount = sum(values) + sum(amount_line)
|
||||
unit_value = amount
|
||||
PayrollLine.write([line], {
|
||||
'unit_value': amount,
|
||||
'unit_value': unit_value,
|
||||
'amount': amount,
|
||||
'move_lines': [('add', lines_to_reconcile)]
|
||||
})
|
||||
|
@ -461,7 +483,10 @@ class Payroll(metaclass=PoolMeta):
|
|||
if event.amount_to_pay:
|
||||
unit_value = Decimal(event.amount_to_pay)
|
||||
else:
|
||||
unit_value = wage.compute_unit_price(salary_args)
|
||||
if event.is_vacations:
|
||||
unit_value = self.get_salary_average(wage)
|
||||
else:
|
||||
unit_value = wage.compute_unit_price(salary_args)
|
||||
res = self.get_line(wage, qty_pay, unit_value)
|
||||
lines = PayrollLine.create([res])
|
||||
event.line_payroll = lines[0]
|
||||
|
@ -475,6 +500,39 @@ class Payroll(metaclass=PoolMeta):
|
|||
self.save()
|
||||
return discounts
|
||||
|
||||
def get_salary_average(self, wage):
|
||||
end_date = self.start
|
||||
start_date_contract = self.contract.start_date
|
||||
start_date = end_date + relativedelta(months=-4)
|
||||
|
||||
if start_date <= start_date_contract:
|
||||
start_date = start_date_contract
|
||||
|
||||
next_date = date(start_date.year, start_date.month, 1)
|
||||
average_days_monthly = []
|
||||
while next_date < end_date:
|
||||
_, end_day = calendar.monthrange(next_date.year, next_date.month)
|
||||
payrolls = self._get_payrolls_period(next_date, next_date)
|
||||
salary_base = 0
|
||||
worked_days = 0
|
||||
if payrolls:
|
||||
for payroll in payrolls:
|
||||
salary_base += payroll.compute_salary_full(wage)
|
||||
worked_days += payroll.worked_days
|
||||
|
||||
if end_day == worked_days:
|
||||
worked_days = 30
|
||||
average_day = salary_base / worked_days
|
||||
average_days_monthly.append(average_day)
|
||||
|
||||
next_date += relativedelta(months=1)
|
||||
res = sum(average_days_monthly)/len(average_days_monthly)
|
||||
# if len(average_days_monthly) != len(set(average_days_monthly)):
|
||||
# res = sum(average_days_monthly)/len(average_days_monthly) * 30
|
||||
# else:
|
||||
# res = sum(average_days_monthly)/len(average_days_monthly) * 30
|
||||
return res
|
||||
|
||||
def update_wage_no_salary(self):
|
||||
PayrollLine = Pool().get('staff.payroll.line')
|
||||
for line in self.lines:
|
||||
|
@ -1684,10 +1742,22 @@ class Exo2276Report(Report):
|
|||
new_objects = {}
|
||||
start_period = data['start_period']
|
||||
end_period = data['end_period']
|
||||
cesanpag_wage = WageType.search_read([
|
||||
('type_concept', 'in', ['unemployment', 'interest']),
|
||||
], fields_names=['credit_account'])
|
||||
accounts_id = [p['credit_account'] for p in cesanpag_wage]
|
||||
pag_wage = WageType.search_read([
|
||||
('type_concept', 'in', ['unemployment', 'interest', 'holidays']),
|
||||
], fields_names=['credit_account', 'type_concept'])
|
||||
|
||||
accounts_id = {'cesanpag': [], 'holidays': []}
|
||||
for p in pag_wage:
|
||||
if p['type_concept'] in ('unemployment', 'interest'):
|
||||
accounts_id['cesanpag'].append(p['credit_account'])
|
||||
else:
|
||||
accounts_id['holidays'].append(p['credit_account'])
|
||||
|
||||
# accounts_id_c = ['cesanpagp':['credit_account'] for p in pag_wage]
|
||||
# cesanpag_wage = WageType.search_read([
|
||||
# ('type_concept', 'in', ['unemployment', 'interest']),
|
||||
# ], fields_names=['credit_account'])
|
||||
# accounts_id = [p['credit_account'] for p in cesanpag_wage]
|
||||
index = 0
|
||||
for payroll in payrolls:
|
||||
index += 1
|
||||
|
@ -1700,7 +1770,7 @@ class Exo2276Report(Report):
|
|||
'type_document': party.type_document,
|
||||
'id_number': party.id_number,
|
||||
'first_family_name': party.first_family_name,
|
||||
'second_family_name':party.second_family_name,
|
||||
'second_family_name': party.second_family_name,
|
||||
'first_name': party.first_name,
|
||||
'second_name': party.second_name,
|
||||
'addresses': party.addresses[0].street,
|
||||
|
@ -1743,17 +1813,21 @@ class Exo2276Report(Report):
|
|||
new_objects[party.id] = cls._prepare_lines(payrolls, new_objects[party.id], party.id)
|
||||
|
||||
_cesanpag = 0
|
||||
_holidays = 0
|
||||
|
||||
lines_liquid = MoveLine.search_read([
|
||||
('party', '=', party.id),
|
||||
('move.state', '=', 'posted'),
|
||||
('move.date', '>=', data['start_period']),
|
||||
('move.date', '<=', data['end_period']),
|
||||
('account', 'in', accounts_id),
|
||||
('account', 'in', accounts_id['cesanpag']+accounts_id['holidays']),
|
||||
('debit', '>', 0),
|
||||
], fields_names=['debit', 'move'])
|
||||
], fields_names=['debit', 'move', 'account'])
|
||||
if lines_liquid:
|
||||
_cesanpag = sum([l['debit'] for l in lines_liquid])
|
||||
_cesanpag = sum([l['debit'] for l in lines_liquid if l['account'] in accounts_id['cesanpag']])
|
||||
_holidays = sum([l['debit'] for l in lines_liquid if l['account'] in accounts_id['holidays']])
|
||||
new_objects[party.id]['cesanpag'] = _cesanpag
|
||||
new_objects[party.id]['holidays'] = _holidays
|
||||
|
||||
report_context['records'] = new_objects.values()
|
||||
report_context['end_period'] = end_period
|
||||
|
@ -1792,7 +1866,8 @@ class Exo2276Report(Report):
|
|||
vals['payments'] += line.amount
|
||||
vals['extras'] += line.amount
|
||||
elif line.wage_type.type_concept == 'holidays':
|
||||
vals['holidays'] += line.amount
|
||||
continue
|
||||
# vals['holidays'] += line.amount
|
||||
elif line.wage_type.type_concept == 'bonus':
|
||||
vals['payments'] += line.amount
|
||||
vals['bonus'] += line.amount
|
||||
|
@ -1842,6 +1917,9 @@ class Exo2276Report(Report):
|
|||
])
|
||||
return vals
|
||||
|
||||
# vals['unemployment'], vals['interest'], vals['holidays'],
|
||||
# vals['bonus_service']
|
||||
|
||||
|
||||
class IncomeWithholdingsStart(ModelView):
|
||||
'Income Withholding Start'
|
||||
|
|
Loading…
Reference in New Issue