add option discount loans
This commit is contained in:
parent
9e76c5b845
commit
e244cdbb32
|
@ -11,6 +11,7 @@ from . import uvt
|
|||
from . import event_category
|
||||
from . import account
|
||||
from . import event
|
||||
from . import loan
|
||||
|
||||
|
||||
def register():
|
||||
|
@ -49,6 +50,7 @@ def register():
|
|||
payroll.PayrollsMultiPaymentStart,
|
||||
liquidation.LiquidationExportStart,
|
||||
event.Event,
|
||||
loan.LoanLine,
|
||||
module='staff_payroll_co', type_='model')
|
||||
Pool.register(
|
||||
payroll.PayrollGlobalReport,
|
||||
|
|
|
@ -517,18 +517,73 @@ class Liquidation(Workflow, ModelSQL, ModelView):
|
|||
for line in lines:
|
||||
values.append(abs(line.debit - line.credit))
|
||||
lines_to_reconcile.append(line.id)
|
||||
wages[wage_type.id] = {
|
||||
'sequence': wage_type.sequence,
|
||||
'wage': wage_type.id,
|
||||
'description': wage_type.name,
|
||||
'amount': sum(values),
|
||||
'days': self.time_contracting,
|
||||
'account': account_id,
|
||||
value = self.get_line_(wage_type, sum(values), self.time_contracting, account_id, party=self.party_to_pay)
|
||||
value.update({
|
||||
'move_lines': [('add', lines_to_reconcile)],
|
||||
'party_to_pay': self.party_to_pay,
|
||||
}
|
||||
})
|
||||
wages[wage_type.id] = value
|
||||
|
||||
Liquidation.write([self], {'lines': [('create', wages.values())]})
|
||||
if self.kind == 'contract':
|
||||
self.process_loans_to_pay()
|
||||
|
||||
def get_line_(self, wage, amount, days, account_id, party=None):
|
||||
value = {
|
||||
'sequence': wage.sequence,
|
||||
'wage': wage.id,
|
||||
'account': account_id,
|
||||
'description': wage.name,
|
||||
'amount': amount,
|
||||
'days': days,
|
||||
'party_to_pay': party,
|
||||
}
|
||||
return value
|
||||
|
||||
def process_loans_to_pay(self):
|
||||
pool = Pool()
|
||||
MoveLine = pool.get('account.move.line')
|
||||
LoanLine = pool.get('staff.loan.line')
|
||||
LiquidationLine = pool.get('staff.liquidation.line')
|
||||
|
||||
for wage in self.employee.mandatory_wages:
|
||||
if wage.wage_type.type_concept == 'loan':
|
||||
wage_type = wage.wage_type
|
||||
account_id = wage_type.credit_account.id
|
||||
dom = [
|
||||
('loan.party', '=', self.employee.party.id),
|
||||
('loan.account_debit', '=', account_id),
|
||||
('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
|
||||
|
||||
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_})
|
||||
|
||||
@fields.depends('start_period', 'end_period', 'contract')
|
||||
def on_change_with_time_contracting(self):
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class LoanLine(metaclass=PoolMeta):
|
||||
'Loan Line'
|
||||
__name__ = 'staff.loan.line'
|
||||
|
||||
@classmethod
|
||||
def _get_origin(cls):
|
||||
'Return list of Model names for origin Reference'
|
||||
return super(LoanLine, cls)._get_origin() + [
|
||||
'staff.payroll.line', 'staff.liquidation.line']
|
85
payroll.py
85
payroll.py
|
@ -348,32 +348,12 @@ class Payroll(metaclass=PoolMeta):
|
|||
pool = Pool()
|
||||
MoveLine = pool.get('account.move.line')
|
||||
PayrollLine = pool.get('staff.payroll.line')
|
||||
staff_loan = False
|
||||
Module = Pool().get('ir.module')
|
||||
modules = Module.search(['name', '=', 'staff_loan'])
|
||||
if modules and modules[0].state == 'activated':
|
||||
staff_loan = True
|
||||
LoanLine = pool.get('staff.loan.line')
|
||||
LoanLine = pool.get('staff.loan.line')
|
||||
|
||||
for line in self.lines:
|
||||
if line.wage_type.type_concept == 'loan' and staff_loan:
|
||||
dom = [
|
||||
('loan.party', '=', self.employee.party.id),
|
||||
('loan.account_debit', '=', line.wage_type.credit_account.id),
|
||||
('maturity_date', '>=', self.start),
|
||||
('maturity_date', '<=', self.end),
|
||||
('state', 'in', ['pending', 'partial']),
|
||||
]
|
||||
lines_loan = LoanLine.search(dom)
|
||||
if lines_loan:
|
||||
move_lines = MoveLine.search([
|
||||
('origin', 'in', ['staff.loan.line,' + str(l.id) for l in lines_loan]),
|
||||
])
|
||||
unit_value = sum([l.amount for l in lines_loan])
|
||||
PayrollLine.write([line], {
|
||||
'unit_value': unit_value,
|
||||
'move_lines': [('add', move_lines)]
|
||||
})
|
||||
to_write = {}
|
||||
if line.wage_type.type_concept == 'loan':
|
||||
self.process_loans_to_pay(line, LoanLine, PayrollLine, MoveLine)
|
||||
|
||||
if line.wage_type.provision_cancellation:
|
||||
amount_line = [m.amount for m in self.lines if m.wage_type
|
||||
|
@ -393,19 +373,68 @@ class Payroll(metaclass=PoolMeta):
|
|||
values.append(abs(m.debit - m.credit))
|
||||
if sum(values) <= amount:
|
||||
lines_to_reconcile.append(m.id)
|
||||
PayrollLine.write([line], {
|
||||
to_write = {
|
||||
'move_lines': [('add', lines_to_reconcile)]
|
||||
})
|
||||
}
|
||||
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], {
|
||||
to_write = {
|
||||
'unit_value': unit_value,
|
||||
'move_lines': [('add', lines_to_reconcile)]
|
||||
})
|
||||
}
|
||||
PayrollLine.write([line], to_write)
|
||||
|
||||
def process_loans_to_pay(self, line, LoanLine, PayrollLine, MoveLine):
|
||||
|
||||
dom = [
|
||||
('loan.party', '=', self.employee.party.id),
|
||||
('loan.account_debit', '=', line.wage_type.credit_account.id),
|
||||
('maturity_date', '<=', self.end),
|
||||
('state', 'in', ['pending', 'partial']),
|
||||
]
|
||||
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)
|
||||
|
||||
def validate_wage_type(self, line, concept=None):
|
||||
if concept == 'holidays':
|
||||
|
|
|
@ -11,6 +11,7 @@ depends:
|
|||
staff_payroll
|
||||
account_voucher
|
||||
email
|
||||
staff_loan
|
||||
xml:
|
||||
configuration.xml
|
||||
uvt.xml
|
||||
|
|
Loading…
Reference in New Issue