Fix compute days worked
This commit is contained in:
parent
eae41f6899
commit
2b0d7936a6
|
@ -1,6 +1,7 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
from datetime import timedelta
|
||||
from trytond import backend
|
||||
from trytond.model import Workflow, ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
|
@ -274,7 +275,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
if not self.employee or not self.contract:
|
||||
return
|
||||
Payroll = Pool().get('staff.payroll')
|
||||
date_start, date_end = self._compute_time()
|
||||
date_start, date_end = self._get_dates()
|
||||
payrolls = Payroll.search([
|
||||
('employee', '=', self.employee.id),
|
||||
('start', '>=', date_start),
|
||||
|
@ -376,7 +377,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
}
|
||||
return res
|
||||
|
||||
def _compute_time(self):
|
||||
def _get_dates(self):
|
||||
date_end_contract = None
|
||||
if self.contract.start_date > self.start_period.start:
|
||||
date_start = self.contract.start_date
|
||||
|
@ -399,7 +400,7 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
Payroll = pool.get('staff.payroll')
|
||||
Liquidation = pool.get('staff.liquidation')
|
||||
MoveLine = pool.get('account.move.line')
|
||||
date_start, date_end = self._compute_time()
|
||||
date_start, date_end = self._get_dates()
|
||||
payrolls = Payroll.search([
|
||||
('employee', '=', self.employee.id),
|
||||
('start', '>=', date_start),
|
||||
|
@ -478,22 +479,33 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
def on_change_with_time_contracting(self):
|
||||
delta = None
|
||||
if self.start_period and self.end_period and self.contract:
|
||||
date_start, date_end = self._compute_time()
|
||||
delta = (date_end - date_start).days + 1
|
||||
date_start, date_end = self._get_dates()
|
||||
delta = self.get_time_contracting(date_start, date_end)
|
||||
return delta
|
||||
|
||||
def _get_time_contracting(self):
|
||||
if not self.start_period or not self.end_period or not self.employee:
|
||||
return
|
||||
Payroll = Pool().get('staff.payroll')
|
||||
def get_time_contracting(self, start_date, end_date):
|
||||
sum_days = 0
|
||||
if end_date.day == 31:
|
||||
end_date = (end_date.year, end_date.month, 30)
|
||||
|
||||
payrolls = Payroll.search([
|
||||
('employee', '=', self.employee.id),
|
||||
('period.start', '>=', self.contract.start_date),
|
||||
('period.end', '<=', self.contract.end_date),
|
||||
('contract', '=', self.contract.id),
|
||||
])
|
||||
return sum([p.worked_days for p in payrolls])
|
||||
delta = (end_date - start_date).days + 1
|
||||
if start_date.month == end_date.month:
|
||||
return delta
|
||||
|
||||
for d in range(delta):
|
||||
next_date = start_date + timedelta(days=d)
|
||||
if next_date.day == 31:
|
||||
continue
|
||||
if next_date.month == 2:
|
||||
if next_date.day == 29:
|
||||
continue
|
||||
elif next_date.day == 28:
|
||||
sum_days += 2
|
||||
else:
|
||||
sum_days += 1
|
||||
else:
|
||||
sum_days += 1
|
||||
return sum_days
|
||||
|
||||
def set_number(self):
|
||||
if self.number:
|
||||
|
@ -533,7 +545,8 @@ class LiquidationLine(ModelSQL, ModelView):
|
|||
required=True)
|
||||
wage = fields.Many2One('staff.wage_type', 'Wage Type', required=True)
|
||||
description = fields.Char('Description', required=True)
|
||||
amount = fields.Numeric('Amount', digits=(16, 2), required=True, depends=['adjustments', 'move_lines'])
|
||||
amount = fields.Numeric('Amount', digits=(16, 2), required=True,
|
||||
depends=['adjustments', 'move_lines'])
|
||||
days = fields.Integer('Days')
|
||||
notes = fields.Char('Notes')
|
||||
account = fields.Many2One('account.account', 'Account')
|
||||
|
@ -545,7 +558,8 @@ class LiquidationLine(ModelSQL, ModelView):
|
|||
], depends=['party', 'account'])
|
||||
party = fields.Function(fields.Many2One('party.party', 'Party'),
|
||||
'get_party')
|
||||
adjustments = fields.One2Many('staff.liquidation.line_adjustment', 'staff_liquidation_line', 'Adjustments')
|
||||
adjustments = fields.One2Many('staff.liquidation.line_adjustment',
|
||||
'staff_liquidation_line', 'Adjustments')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -566,7 +580,6 @@ class LiquidationLine(ModelSQL, ModelView):
|
|||
if self.liquidation.employee:
|
||||
return self.liquidation.employee.party.id
|
||||
|
||||
|
||||
@fields.depends('wage', 'description', 'amount', 'liquidation',
|
||||
'_parent_liquidation.employee', '_parent_liquidation.time_contracting',
|
||||
'_parent_liquidation.start_period', '_parent_liquidation.end_period',
|
||||
|
|
Loading…
Reference in New Issue