mirror of
https://bitbucket.org/presik/trytonpsk-staff_payroll_co.git
synced 2023-12-14 06:42:56 +01:00
add field origin
This commit is contained in:
parent
e4c704e9aa
commit
027144c53a
|
@ -10,7 +10,7 @@ from . import employee
|
||||||
from . import uvt
|
from . import uvt
|
||||||
from . import event_category
|
from . import event_category
|
||||||
from . import account
|
from . import account
|
||||||
from . import event
|
# from . import event
|
||||||
from . import loan
|
from . import loan
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ def register():
|
||||||
payroll.PayrollLineMoveLine,
|
payroll.PayrollLineMoveLine,
|
||||||
payroll.PayrollsMultiPaymentStart,
|
payroll.PayrollsMultiPaymentStart,
|
||||||
liquidation.LiquidationExportStart,
|
liquidation.LiquidationExportStart,
|
||||||
event.Event,
|
# event.Event,
|
||||||
loan.LoanLine,
|
loan.LoanLine,
|
||||||
module='staff_payroll_co', type_='model')
|
module='staff_payroll_co', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
|
|
2
event.py
2
event.py
|
@ -7,5 +7,3 @@ from trytond.model import fields
|
||||||
class Event(metaclass=PoolMeta):
|
class Event(metaclass=PoolMeta):
|
||||||
'Staff Event'
|
'Staff Event'
|
||||||
__name__ = 'staff.event'
|
__name__ = 'staff.event'
|
||||||
line_payroll = fields.Many2One('staff.payroll.line',
|
|
||||||
'Line Payroll', states={'readonly': True})
|
|
||||||
|
|
|
@ -555,35 +555,17 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
||||||
('state', 'in', ['pending', 'partial']),
|
('state', 'in', ['pending', 'partial']),
|
||||||
]
|
]
|
||||||
lines_loan = LoanLine.search(dom)
|
lines_loan = LoanLine.search(dom)
|
||||||
grouped = {}
|
for m in lines_loan:
|
||||||
for l in lines_loan:
|
|
||||||
key = 0
|
|
||||||
party = l.loan.party_to_pay
|
|
||||||
if party:
|
|
||||||
key = party.id
|
|
||||||
|
|
||||||
try:
|
|
||||||
grouped[key]['amount'] += [l.amount]
|
|
||||||
grouped[key]['lines'] += [l.id]
|
|
||||||
except:
|
|
||||||
grouped[key] = {
|
|
||||||
'party': key,
|
|
||||||
'amount': [l.amount],
|
|
||||||
'lines': [l.id]
|
|
||||||
}
|
|
||||||
|
|
||||||
if grouped:
|
|
||||||
for v, r in zip(grouped.values(), range(len(grouped))):
|
|
||||||
move_lines = MoveLine.search([
|
move_lines = MoveLine.search([
|
||||||
('origin', 'in', ['staff.loan.line,' + str(l) for l in v['lines']]),
|
('origin', 'in', ['staff.loan.line,' + str(m)]),
|
||||||
])
|
])
|
||||||
party = v['party'] if v['party'] != 0 else None
|
party = m.loan.party_to_pay.id if m.loan.party_to_pay else None
|
||||||
amount = sum(v['amount'])
|
res = self.get_line_(wage_type, m.amount, 1, account_id, party=party)
|
||||||
res = self.get_line_(wage_type, amount, 1, account_id, party=party)
|
|
||||||
res['move_lines'] = [('add', move_lines)]
|
res['move_lines'] = [('add', move_lines)]
|
||||||
res['liquidation'] = self.id
|
res['liquidation'] = self.id
|
||||||
line_, = LiquidationLine.create([res])
|
line_, = LiquidationLine.create([res])
|
||||||
LoanLine.write([l for l in lines_loan], {'state': 'paid', 'origin': line_})
|
LoanLine.write([m], {'state': 'paid', 'origin': line_})
|
||||||
|
|
||||||
@fields.depends('start_period', 'end_period', 'contract')
|
@fields.depends('start_period', 'end_period', 'contract')
|
||||||
def on_change_with_time_contracting(self):
|
def on_change_with_time_contracting(self):
|
||||||
|
|
87
payroll.py
87
payroll.py
|
@ -46,6 +46,8 @@ class PayrollLine(metaclass=PoolMeta):
|
||||||
move_lines = fields.Many2Many('staff.payroll.line-move.line',
|
move_lines = fields.Many2Many('staff.payroll.line-move.line',
|
||||||
'line', 'move_line', 'Payroll Line - Move Line')
|
'line', 'move_line', 'Payroll Line - Move Line')
|
||||||
|
|
||||||
|
origin = fields.Reference("Origin", selection='get_origin')
|
||||||
|
|
||||||
def get_expense_amount(self):
|
def get_expense_amount(self):
|
||||||
expense = super(PayrollLine, self).get_expense_amount()
|
expense = super(PayrollLine, self).get_expense_amount()
|
||||||
if self.wage_type.round_amounts:
|
if self.wage_type.round_amounts:
|
||||||
|
@ -66,6 +68,18 @@ class PayrollLine(metaclass=PoolMeta):
|
||||||
LoanLine.write([m for m in loan_lines], {'state': 'pending', 'origin': None})
|
LoanLine.write([m for m in loan_lines], {'state': 'pending', 'origin': None})
|
||||||
super(PayrollLine, cls).delete(lines)
|
super(PayrollLine, cls).delete(lines)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_origin(cls):
|
||||||
|
'Return list of Model names for origin Reference'
|
||||||
|
return ['staff.loan.line', 'staff.event']
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_origin(cls):
|
||||||
|
Model = Pool().get('ir.model')
|
||||||
|
get_name = Model.get_name
|
||||||
|
models = cls._get_origin()
|
||||||
|
return [(None, '')] + [(m, get_name(m)) for m in models]
|
||||||
|
|
||||||
|
|
||||||
class PayrollLineMoveLine(ModelSQL):
|
class PayrollLineMoveLine(ModelSQL):
|
||||||
"Payroll Line - MoveLine"
|
"Payroll Line - MoveLine"
|
||||||
|
@ -407,42 +421,26 @@ class Payroll(metaclass=PoolMeta):
|
||||||
]
|
]
|
||||||
lines_loan = LoanLine.search(dom)
|
lines_loan = LoanLine.search(dom)
|
||||||
to_write = {}
|
to_write = {}
|
||||||
grouped = {}
|
for m, r in zip(lines_loan, range(len(lines_loan))):
|
||||||
for l in lines_loan:
|
party = m.loan.party_to_pay.id if m.loan.party_to_pay else None
|
||||||
key = 0
|
|
||||||
party = l.loan.party_to_pay
|
|
||||||
if party:
|
|
||||||
key = party.id
|
|
||||||
|
|
||||||
try:
|
|
||||||
grouped[key]['amount'] += [l.amount]
|
|
||||||
grouped[key]['lines'] += [l.id]
|
|
||||||
except:
|
|
||||||
grouped[key] = {
|
|
||||||
'party': key,
|
|
||||||
'amount': [l.amount],
|
|
||||||
'lines': [l.id]
|
|
||||||
}
|
|
||||||
|
|
||||||
if grouped:
|
|
||||||
for v, r in zip(grouped.values(), range(len(grouped))):
|
|
||||||
move_lines = MoveLine.search([
|
move_lines = MoveLine.search([
|
||||||
('origin', 'in', ['staff.loan.line,' + str(l) for l in v['lines']]),
|
('origin', 'in', ['staff.loan.line,' + str(m)]),
|
||||||
])
|
])
|
||||||
party = v['party'] if v['party'] != 0 else None
|
amount = m.amount
|
||||||
amount = sum(v['amount'])
|
|
||||||
line_ = line
|
line_ = line
|
||||||
if r == 0:
|
if r == 0:
|
||||||
to_write = {
|
to_write = {
|
||||||
|
'origin': m,
|
||||||
'party': party,
|
'party': party,
|
||||||
'unit_value': amount,
|
'unit_value': amount,
|
||||||
'move_lines': [('add', move_lines)]
|
'move_lines': [('add', move_lines)]
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
res = self.get_line(line.wage, 1, amount, party=party)
|
res = self.get_line(line.wage, 1, amount, party=party)
|
||||||
|
res['origin'] = m
|
||||||
res['move_lines'] = [('add', move_lines)]
|
res['move_lines'] = [('add', move_lines)]
|
||||||
line_, = PayrollLine.create([res])
|
line_, = PayrollLine.create([res])
|
||||||
LoanLine.write([l for l in lines_loan], {'state': 'paid', 'origin': line_})
|
LoanLine.write([m], {'state': 'paid', 'origin': line_})
|
||||||
PayrollLine.write([line], to_write)
|
PayrollLine.write([line], to_write)
|
||||||
|
|
||||||
def validate_wage_type(self, line, concept=None):
|
def validate_wage_type(self, line, concept=None):
|
||||||
|
@ -501,19 +499,37 @@ class Payroll(metaclass=PoolMeta):
|
||||||
PayrollLine = pool.get('staff.payroll.line')
|
PayrollLine = pool.get('staff.payroll.line')
|
||||||
events = Event.search([
|
events = Event.search([
|
||||||
('employee', '=', self.employee),
|
('employee', '=', self.employee),
|
||||||
('start_date', '<=', self.end),
|
|
||||||
('end_date', '>=', self.start),
|
|
||||||
('state', '=', 'done'),
|
('state', '=', 'done'),
|
||||||
|
['OR',
|
||||||
|
[
|
||||||
|
('end_date', '>=', self.start),
|
||||||
|
('start_date', '<=', self.start),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
('end_date', '>=', self.end),
|
||||||
|
('start_date', '<=', self.end),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
('start_date', '>=', self.start),
|
||||||
|
('end_date', '<=', self.end),
|
||||||
|
],
|
||||||
|
]
|
||||||
])
|
])
|
||||||
absenteeism_days = 0
|
absenteeism_days = 0
|
||||||
discounts = {}
|
discounts = {}
|
||||||
for event in events:
|
for event in events:
|
||||||
if not event.category.payroll_effect and event.line_payroll:
|
if not event.category.payroll_effect:
|
||||||
continue
|
continue
|
||||||
|
start_date = self.start
|
||||||
|
if event.start_date > start_date:
|
||||||
|
start_date = event.start_date
|
||||||
|
end_date = self.end
|
||||||
|
if event.end_date < end_date:
|
||||||
|
end_date = event.end_date
|
||||||
|
qty_pay = self.contract.get_time_days(start_date, end_date)
|
||||||
if event.absenteeism:
|
if event.absenteeism:
|
||||||
absenteeism_days += event.days
|
absenteeism_days += qty_pay
|
||||||
if event.quantity_pay:
|
if event.quantity_pay:
|
||||||
qty_pay = event.quantity_pay
|
|
||||||
wage = event.category.wage_type
|
wage = event.category.wage_type
|
||||||
if wage:
|
if wage:
|
||||||
salary_args = self.get_salary_full(wage)
|
salary_args = self.get_salary_full(wage)
|
||||||
|
@ -528,13 +544,16 @@ class Payroll(metaclass=PoolMeta):
|
||||||
res = self.get_line(wage, qty_pay, unit_value)
|
res = self.get_line(wage, qty_pay, unit_value)
|
||||||
res.update({
|
res.update({
|
||||||
'is_event': True,
|
'is_event': True,
|
||||||
'start_date': event.start_date,
|
'start_date': start_date,
|
||||||
'end_date': event.end_date,
|
'end_date': end_date,
|
||||||
|
'origin': event
|
||||||
})
|
})
|
||||||
lines = PayrollLine.create([res])
|
PayrollLine.create([res])
|
||||||
if lines:
|
# lines = PayrollLine.create([res])
|
||||||
event.line_payroll = lines[0]
|
|
||||||
event.save()
|
# if lines:
|
||||||
|
# event.line_payroll = lines[0]
|
||||||
|
# event.save()
|
||||||
if event.category.wage_type_discount and event.quantity_discount:
|
if event.category.wage_type_discount and event.quantity_discount:
|
||||||
id_wt_event = event.category.wage_type_discount.id
|
id_wt_event = event.category.wage_type_discount.id
|
||||||
if id_wt_event not in discounts.keys():
|
if id_wt_event not in discounts.keys():
|
||||||
|
|
|
@ -12,6 +12,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
</notebook>
|
</notebook>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="/form/field[@name='party']" position="after">
|
<xpath expr="/form/field[@name='party']" position="after">
|
||||||
|
<label name="origin"/>
|
||||||
|
<field name="origin"/>
|
||||||
<label name="is_event"/>
|
<label name="is_event"/>
|
||||||
<field name="is_event"/>
|
<field name="is_event"/>
|
||||||
<label name="start_date"/>
|
<label name="start_date"/>
|
||||||
|
|
|
@ -7,7 +7,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
position="after">
|
position="after">
|
||||||
<!-- <label name="available_days"/>
|
<!-- <label name="available_days"/>
|
||||||
<field name="available_days"/> -->
|
<field name="available_days"/> -->
|
||||||
<label name="line_payroll"/>
|
<!-- <label name="line_payroll"/>
|
||||||
<field name="line_payroll"/>
|
<field name="line_payroll"/> -->
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in a new issue