relation of pay provision cancellation

This commit is contained in:
wilson gomez sanchez 2021-02-04 14:51:06 -05:00
parent d2f6802fc5
commit 0545df2679
4 changed files with 65 additions and 40 deletions

View File

@ -44,6 +44,7 @@ def register():
liquidation.MoveProvisionBonusServiceStart,
payroll.PayrollSupportDispersionStart,
employee.UpdateEmployeeStart,
payroll.PayrollLineMoveLine,
module='staff_payroll_co', type_='model')
Pool.register(
payroll.PayrollGlobalReport,

View File

@ -5,7 +5,7 @@ from decimal import Decimal
from datetime import date, timedelta
import math
from trytond.exceptions import UserError
from trytond.model import ModelView, fields, Workflow
from trytond.model import ModelView, fields, Workflow, ModelSQL
from trytond.pool import Pool, PoolMeta
from trytond.report import Report
from trytond.wizard import Wizard, StateView, Button, StateAction, StateReport, StateTransition
@ -25,7 +25,7 @@ __all__ = [
'Exo2276Report', 'IncomeWithholdings', 'IncomeWithholdingsStart',
'ExportMovesReport', 'IncomeWithholdingsReport', 'PayrollExportStart',
'PayrollExport', 'PayrollExportReport', 'PayrollSupportDispersionStart',
'PayrollSupportDispersion'
'PayrollSupportDispersion', 'PayrollLineMoveLine',
]
@ -79,6 +79,18 @@ ENTITY_ACCOUNTS = {
class PayrollLine(metaclass=PoolMeta):
__name__ = "staff.payroll.line"
move_lines = fields.Many2Many('staff.payroll.line-move.line',
'line', 'move_line', 'Payroll Line - Move Line')
class PayrollLineMoveLine(ModelSQL):
"Payroll Line - MoveLine"
__name__ = "staff.payroll.line-move.line"
_table = 'staff_payroll_line_move_line_rel'
line = fields.Many2One('staff.payroll.line', 'Line',
ondelete='CASCADE', select=True, required=True)
move_line = fields.Many2One('account.move.line', 'Move Line',
ondelete='RESTRICT', select=True, required=True)
class Payroll(metaclass=PoolMeta):
@ -97,11 +109,6 @@ class Payroll(metaclass=PoolMeta):
department = fields.Many2One('company.department', 'Department',
required=False, depends=['employee'])
sended_mail = fields.Boolean('Sended Email')
# move_line_provision = fields.Function(fields.Many2Many('account.move.lines',
# None, None, 'Lines Provision',
# domain=[
# ('employee', '=', Eval('employee')),
# ],), 'get_lines_provision')
@classmethod
def __setup__(cls):
@ -126,6 +133,20 @@ class Payroll(metaclass=PoolMeta):
if self.employee and self.employee.department:
self.department = self.employee.department.id
def create_move(self):
super(Payroll, self).create_move()
pool = Pool()
MoveLine = pool.get('account.move.line')
grouped = {line.wage_type.debit_account.id: {'lines': [m for m in line.move_lines]} for line in self.lines if line.wage_type.provision_cancellation}
for p in self.move.lines:
print(p.account.id)
if p.account.id not in grouped or (
p.account.kind not in ('payable', 'receivable')):
continue
to_reconcile = [p]
to_reconcile.extend(grouped[p.account.id]['lines'])
MoveLine.reconcile(set(to_reconcile))
@fields.depends('period', 'employee', 'start', 'end', 'contract',
'description', 'date_effective', 'last_payroll')
def on_change_period(self):
@ -184,20 +205,6 @@ class Payroll(metaclass=PoolMeta):
if not self.description and self.period:
self.description = self.period.description
# def get_lines_provision(self, name):
# if not self.party:
# return
# Move_line = Pool().get('account.move.line')
# wage_types = []
# wage_types = [line.wage_type.id for line in self.lines if line.wage_type.provision_cancellation]
# lines = Move_line.search([
# ('account', 'in', wage_types),
# ('reconciliation', '=', None),
# ('party', '=', self.employee.party.id)
# ])
# lines_ids = [line.id for line in lines]
# return lines_ids
def adjust_partial_sunday(self, quantity):
# Factor = 8 hour sunday / 6 days (monday-saturday)
factor = 1.33
@ -336,30 +343,29 @@ class Payroll(metaclass=PoolMeta):
return payrolls
def _create_payroll_lines(self, wages, extras, discounts=None):
super(Payroll, self)._create_payroll_lines(wages, extras, discounts=None)
pool = Pool()
MoveLine = pool.get('account.move.line')
_wages = []
for wage, party, fix_amount in wages:
print(wage.provision_cancellation)
if wage.provision_cancellation:
qty = 1
salary_args = self.get_salary_full(wage)
unit_value = wage.provision_cancellation.compute_unit_price(salary_args)
line = self.get_line(wage, qty, unit_value, party)
amount_line = line['unit_value'] * self.worked_days
if not wage.provision_cancellation.credit_account:
return self.raise_user_error('provision_missing_account', wage.provision_cancellation.name)
lines = MoveLine.search([
('account', '=', wage.provision_cancellation.credit_account.id),
PayrollLine = pool.get('staff.payroll.line')
for line in self.lines:
if line.wage_type.provision_cancellation:
amount_line = [m.amount for m in self.lines if m.wage_type == line.wage_type.provision_cancellation]
move_lines = MoveLine.search([
('account', '=', line.wage_type.provision_cancellation.credit_account.id),
('reconciliation', '=', None),
('party', '=', self.employee.party.id)
])
amount = sum(abs(line.debit - line.credit) for line in lines)
print('line', line)
fix_amount = amount_line + amount
_wages.append([wage, party, fix_amount])
super(Payroll, self)._create_payroll_lines(_wages, extras, discounts=None)
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)
PayrollLine.write([line], {
'unit_value': amount,
'amount': amount,
'move_lines': [('add', lines_to_reconcile)]
})
def search_salary_month(self, wage):
res = _ZERO

View File

@ -294,5 +294,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit" ref="staff_payroll.payroll_view_tree"/>
<field name="name">payroll_tree</field>
</record>
<record model="ir.ui.view" id="payroll_line_form">
<field name="model">staff.payroll.line</field>
<field name="inherit" ref="staff_payroll.payroll_line_view_form"/>
<field name="name">payroll_line_form</field>
</record>
</data>
</tryton>

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='reconciled']"
position="after">
<notebook colspan="6">
<page string="General" id="general">
<field name="move_lines" colspan="4"/>
</page>
</notebook>
</xpath>
</data>