diff --git a/__init__.py b/__init__.py index 9b9ad56..e699df9 100644 --- a/__init__.py +++ b/__init__.py @@ -10,7 +10,7 @@ from . import employee from . import uvt from . import event_category from . import account -from . import event +# from . import event from . import loan @@ -49,7 +49,7 @@ def register(): payroll.PayrollLineMoveLine, payroll.PayrollsMultiPaymentStart, liquidation.LiquidationExportStart, - event.Event, + # event.Event, loan.LoanLine, module='staff_payroll_co', type_='model') Pool.register( diff --git a/event.py b/event.py index fcaf9b5..6f29b6d 100644 --- a/event.py +++ b/event.py @@ -7,5 +7,3 @@ from trytond.model import fields class Event(metaclass=PoolMeta): 'Staff Event' __name__ = 'staff.event' - line_payroll = fields.Many2One('staff.payroll.line', - 'Line Payroll', states={'readonly': True}) diff --git a/liquidation.py b/liquidation.py index 46b04a1..b2cf633 100644 --- a/liquidation.py +++ b/liquidation.py @@ -555,35 +555,17 @@ class Liquidation(Workflow, ModelSQL, ModelView): ('state', 'in', ['pending', 'partial']), ] lines_loan = LoanLine.search(dom) - grouped = {} - for l in lines_loan: - key = 0 - party = l.loan.party_to_pay - if party: - key = party.id + for m in lines_loan: - 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([ - ('origin', 'in', ['staff.loan.line,' + str(l) for l in v['lines']]), - ]) - party = v['party'] if v['party'] != 0 else None - amount = sum(v['amount']) - res = self.get_line_(wage_type, amount, 1, account_id, party=party) - res['move_lines'] = [('add', move_lines)] - res['liquidation'] = self.id - line_, = LiquidationLine.create([res]) - LoanLine.write([l for l in lines_loan], {'state': 'paid', 'origin': line_}) + move_lines = MoveLine.search([ + ('origin', 'in', ['staff.loan.line,' + str(m)]), + ]) + party = m.loan.party_to_pay.id if m.loan.party_to_pay else None + res = self.get_line_(wage_type, m.amount, 1, account_id, party=party) + res['move_lines'] = [('add', move_lines)] + res['liquidation'] = self.id + line_, = LiquidationLine.create([res]) + LoanLine.write([m], {'state': 'paid', 'origin': line_}) @fields.depends('start_period', 'end_period', 'contract') def on_change_with_time_contracting(self): diff --git a/payroll.py b/payroll.py index 6b12b64..4dabc6d 100644 --- a/payroll.py +++ b/payroll.py @@ -46,6 +46,8 @@ class PayrollLine(metaclass=PoolMeta): move_lines = fields.Many2Many('staff.payroll.line-move.line', 'line', 'move_line', 'Payroll Line - Move Line') + origin = fields.Reference("Origin", selection='get_origin') + def get_expense_amount(self): expense = super(PayrollLine, self).get_expense_amount() 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}) 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): "Payroll Line - MoveLine" @@ -407,43 +421,27 @@ class Payroll(metaclass=PoolMeta): ] lines_loan = LoanLine.search(dom) to_write = {} - grouped = {} - 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([ - ('origin', 'in', ['staff.loan.line,' + str(l) for l in v['lines']]), - ]) - party = v['party'] if v['party'] != 0 else None - amount = sum(v['amount']) - line_ = line - if r == 0: - to_write = { - 'party': party, - 'unit_value': amount, - 'move_lines': [('add', move_lines)] - } - else: - res = self.get_line(line.wage, 1, amount, party=party) - res['move_lines'] = [('add', move_lines)] - line_, = PayrollLine.create([res]) - LoanLine.write([l for l in lines_loan], {'state': 'paid', 'origin': line_}) - PayrollLine.write([line], to_write) + for m, r in zip(lines_loan, range(len(lines_loan))): + party = m.loan.party_to_pay.id if m.loan.party_to_pay else None + move_lines = MoveLine.search([ + ('origin', 'in', ['staff.loan.line,' + str(m)]), + ]) + amount = m.amount + line_ = line + if r == 0: + to_write = { + 'origin': m, + 'party': party, + 'unit_value': amount, + 'move_lines': [('add', move_lines)] + } + else: + res = self.get_line(line.wage, 1, amount, party=party) + res['origin'] = m + res['move_lines'] = [('add', move_lines)] + line_, = PayrollLine.create([res]) + LoanLine.write([m], {'state': 'paid', 'origin': line_}) + PayrollLine.write([line], to_write) def validate_wage_type(self, line, concept=None): if concept == 'holidays': @@ -501,19 +499,37 @@ class Payroll(metaclass=PoolMeta): PayrollLine = pool.get('staff.payroll.line') events = Event.search([ ('employee', '=', self.employee), - ('start_date', '<=', self.end), - ('end_date', '>=', self.start), ('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 discounts = {} for event in events: - if not event.category.payroll_effect and event.line_payroll: + if not event.category.payroll_effect: 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: - absenteeism_days += event.days + absenteeism_days += qty_pay if event.quantity_pay: - qty_pay = event.quantity_pay wage = event.category.wage_type if 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.update({ 'is_event': True, - 'start_date': event.start_date, - 'end_date': event.end_date, + 'start_date': start_date, + 'end_date': end_date, + 'origin': event }) - lines = PayrollLine.create([res]) - if lines: - event.line_payroll = lines[0] - event.save() + PayrollLine.create([res]) + # lines = PayrollLine.create([res]) + + # if lines: + # event.line_payroll = lines[0] + # event.save() if event.category.wage_type_discount and event.quantity_discount: id_wt_event = event.category.wage_type_discount.id if id_wt_event not in discounts.keys(): diff --git a/view/payroll_line_form.xml b/view/payroll_line_form.xml index ae52c8b..9a59603 100644 --- a/view/payroll_line_form.xml +++ b/view/payroll_line_form.xml @@ -12,6 +12,8 @@ this repository contains the full copyright notices and license terms. --> +