Fix style remove comments
This commit is contained in:
parent
4fde8cb87c
commit
e0dc033d22
503
payroll.py
503
payroll.py
|
@ -15,25 +15,28 @@ from trytond.modules.staff_payroll import PayrollReport
|
|||
|
||||
|
||||
__all__ = [
|
||||
'Payroll', 'PayrollGlobalStart', 'PayrollGlobal',
|
||||
'PayrollGlobalReport', 'PayrollPaymentReport', 'PayrollPayment',
|
||||
'PayrollPaymentStart', 'PayrollPaycheckStart', 'PayrollPaycheckReport',
|
||||
'PayrollPaycheck', 'PayrollSheetReport', 'PayrollSheet', 'PayrollLine',
|
||||
'PayrollSheetStart', 'PayrollGroupStart', 'OpenPayrollByPeriodStart',
|
||||
'PayrollByPeriodDynamic', 'OpenPayrollByPeriod', 'PayrollGroup',
|
||||
'FixPayrollStart', 'FixPayroll', 'Exo2276Start', 'Exo2276',
|
||||
'Exo2276Report', 'IncomeWithholdings', 'ExportMovesReport',
|
||||
'IncomeWithholdingsStart', 'IncomeWithholdingsReport',
|
||||
'PayrollExportStart', 'PayrollExport', 'PayrollExportReport'
|
||||
'Payroll', 'PayrollGlobalStart', 'PayrollGlobal', 'PayrollGlobalReport',
|
||||
'PayrollPaymentReport', 'PayrollPayment', 'PayrollPaymentStart',
|
||||
'PayrollPaycheckStart', 'PayrollPaycheckReport', 'PayrollPaycheck',
|
||||
'PayrollSheetReport', 'PayrollSheet', 'PayrollLine', 'PayrollSheetStart',
|
||||
'PayrollGroupStart', 'OpenPayrollByPeriodStart', 'PayrollByPeriodDynamic',
|
||||
'OpenPayrollByPeriod', 'PayrollGroup', 'Exo2276Start', 'Exo2276',
|
||||
'Exo2276Report', 'IncomeWithholdings', 'IncomeWithholdingsStart',
|
||||
'ExportMovesReport', 'IncomeWithholdingsReport', 'PayrollExportStart',
|
||||
'PayrollExport', 'PayrollExportReport'
|
||||
]
|
||||
|
||||
|
||||
STATES = {'readonly': (Eval('state') != 'draft')}
|
||||
|
||||
_ZERO = Decimal('0.0')
|
||||
|
||||
PAYMENTS = ['salary', 'bonus', 'reco', 'recf', 'hedo', 'heno',
|
||||
'dom', 'hedf', 'henf']
|
||||
SOCIAL_SEGURITY = ['risk', 'health', 'retirement',
|
||||
'box_family', 'sena', 'icbf']
|
||||
|
||||
SOCIAL_SEGURITY = [
|
||||
'risk', 'health', 'retirement', 'box_family', 'sena', 'icbf'
|
||||
]
|
||||
|
||||
ENTITY_ACCOUNTS = {
|
||||
'830113831': (23700501, 72056901),
|
||||
|
@ -128,7 +131,8 @@ class Payroll(metaclass=PoolMeta):
|
|||
return
|
||||
self.date_effective = self.period.end
|
||||
self.on_change_employee()
|
||||
#Search last contract
|
||||
|
||||
# Search last contract
|
||||
contract = self.search_contract_on_period(self.employee, self.period)
|
||||
|
||||
start_date = None
|
||||
|
@ -180,8 +184,9 @@ class Payroll(metaclass=PoolMeta):
|
|||
|
||||
def _get_line_quantity(self, quantity_days, wage, extras, discount):
|
||||
quantity_days = self.get_days(self.start, self.end, wage)
|
||||
quantity = super(Payroll, self)._get_line_quantity(quantity_days, wage,
|
||||
extras, discount)
|
||||
quantity = super(Payroll, self)._get_line_quantity(
|
||||
quantity_days, wage, extras, discount
|
||||
)
|
||||
return quantity
|
||||
|
||||
@fields.depends('start', 'end', 'employee', 'period', 'contract')
|
||||
|
@ -212,6 +217,7 @@ class Payroll(metaclass=PoolMeta):
|
|||
res = super(Payroll, self).get_salary_full(wage)
|
||||
salary_pae = _ZERO
|
||||
salary_full = res['salary']
|
||||
|
||||
"""
|
||||
if wage.type_concept in ('health', 'retirement', 'fsp', 'tax', 'box_family') \
|
||||
and self.kind == 'special':
|
||||
|
@ -323,27 +329,15 @@ class Payroll(metaclass=PoolMeta):
|
|||
|
||||
def get_line(self, wage, qty, unit_value, party=None):
|
||||
if unit_value and wage and wage.round_amounts:
|
||||
if self.wage_type.round_amounts == 'above_amount':
|
||||
if wage.round_amounts == 'above_amount':
|
||||
unit_value = math.ceil(float(unit_value) / 100.0) * 100
|
||||
elif self.wage_type.round_amounts == 'under_amount':
|
||||
elif wage.round_amounts == 'under_amount':
|
||||
unit_value = math.floor(float(unit_value) / 100.0) * 100
|
||||
elif self.wage_type.round_amounts == 'automatic':
|
||||
elif wage.round_amounts == 'automatic':
|
||||
unit_value = round(unit_value, -2)
|
||||
res = super(Payroll, self).get_line(wage, qty, unit_value, party)
|
||||
return res
|
||||
|
||||
# def _validate_amount_wage(self, wage, amount):
|
||||
# config = Pool().get('staff.configuration')(1)
|
||||
# salary_in_date = self.contract.get_salary_in_date(self.end)
|
||||
# if config and config.minimum_salary and \
|
||||
# wage.type_concept == 'transport' and \
|
||||
# salary_in_date >= (config.minimum_salary * 2):
|
||||
# amount = 0
|
||||
# if wage.type_concept in SOCIAL_SEGURITY and \
|
||||
# amount < wage.minimal_unit_price:
|
||||
# amount = wage.minimal_unit_price
|
||||
# return amount
|
||||
|
||||
def set_preliquidation(self, extras, discounts=None):
|
||||
discounts = self.set_events()
|
||||
ctx = {
|
||||
|
@ -529,7 +523,10 @@ class Payroll(metaclass=PoolMeta):
|
|||
|
||||
@fields.depends('lines')
|
||||
def on_change_with_ibc(self, name=None):
|
||||
concepts = ['salary', 'transport', 'extras', 'bonus', 'commission', 'bonus_service', 'advance']
|
||||
concepts = [
|
||||
'salary', 'transport', 'extras', 'bonus', 'commission',
|
||||
'bonus_service', 'advance'
|
||||
]
|
||||
res = _ZERO
|
||||
for l in self.lines:
|
||||
if l.wage_type and l.wage_type.type_concept in concepts and \
|
||||
|
@ -640,11 +637,10 @@ class PayrollGlobalReport(Report):
|
|||
)
|
||||
if data['department']:
|
||||
dom_pay.append(
|
||||
['AND',
|
||||
['OR', [
|
||||
['AND', ['OR', [
|
||||
('employee.department', '=', data['department']),
|
||||
('department', '=', None),
|
||||
],[
|
||||
], [
|
||||
('department', '=', data['department']),
|
||||
],
|
||||
]]
|
||||
|
@ -667,7 +663,10 @@ class PayrollGlobalReport(Report):
|
|||
parties = {}
|
||||
|
||||
payments = ['salary', 'transport', 'extras', 'food', 'bonus']
|
||||
deductions = ['health', 'retirement', 'tax', 'syndicate', 'fsp', 'acquired_product']
|
||||
deductions = [
|
||||
'health', 'retirement', 'tax', 'syndicate',
|
||||
'fsp', 'acquired_product'
|
||||
]
|
||||
for payroll in payrolls:
|
||||
employee_id = payroll.employee.id
|
||||
party_health = ''
|
||||
|
@ -685,18 +684,7 @@ class PayrollGlobalReport(Report):
|
|||
party_retirement = payroll.employee.party_retirement.name
|
||||
parties[employee_id]['party_health'] = party_health
|
||||
parties[employee_id]['party_retirement'] = party_retirement
|
||||
# parties[employee_id]['employee_salary'] = payroll.employee.salary
|
||||
parties[employee_id]['basic_salary'] = payroll.contract.get_salary_in_date(payroll.end)
|
||||
# payroll_lines = PayrollLine.search([
|
||||
# ('payroll', '=', payroll.id),
|
||||
# ('wage_type.type_concept', '=', 'salary'),
|
||||
# ])
|
||||
# if payroll_lines:
|
||||
# basic_salary = math.ceil(payroll_lines[0].unit_value * 240)
|
||||
# parties[employee_id]['basic_salary'] = cls.round_basic_salary(basic_salary)
|
||||
# else:
|
||||
# parties[employee_id]['basic_salary'] = payroll.contract.salary
|
||||
|
||||
parties[employee_id]['employee_position'] = position_contract or position_employee or ''
|
||||
|
||||
for line in payroll.lines:
|
||||
|
@ -770,9 +758,9 @@ class PayrollPaymentStart(ModelView):
|
|||
'Payroll Payment Start'
|
||||
__name__ = 'staff.payroll_payment.start'
|
||||
period = fields.Many2One('staff.payroll.period', 'Period',
|
||||
required=True)
|
||||
required=True)
|
||||
company = fields.Many2One('company.company', 'Company',
|
||||
required=True)
|
||||
required=True)
|
||||
department = fields.Many2One('company.department', 'Department')
|
||||
|
||||
@staticmethod
|
||||
|
@ -787,7 +775,7 @@ class PayrollPayment(Wizard):
|
|||
'staff_payroll_co.payroll_payment_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
print_ = StateReport('staff.payroll.payment_report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
@ -880,7 +868,7 @@ class PayrollPaycheck(Wizard):
|
|||
'staff_payroll_co.payroll_paycheck_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
print_ = StateReport('staff.payroll.paycheck_report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
@ -1004,10 +992,6 @@ class PayrollPaycheckReport(Report):
|
|||
for line in payroll.lines:
|
||||
if line.wage_type.type_concept == kind:
|
||||
res += line.amount
|
||||
# if kind == 'retirement':
|
||||
# res += Decimal((float(line.amount) * 0.16) / 0.04)
|
||||
# else:
|
||||
# res += line.amount
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
|
@ -1050,7 +1034,7 @@ class PayrollSheet(Wizard):
|
|||
'staff_payroll_co.payroll_sheet_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
print_ = StateReport('staff.payroll.sheet_report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
@ -1071,19 +1055,15 @@ class PayrollSheetReport(Report):
|
|||
@classmethod
|
||||
def get_domain_payroll(cls, data):
|
||||
dom_payroll = []
|
||||
|
||||
return dom_payroll
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(PayrollSheetReport, cls).get_context(records, data)
|
||||
pool = Pool()
|
||||
user = pool.get('res.user')(Transaction().user)
|
||||
Payroll = pool.get('staff.payroll')
|
||||
PayrollLine = pool.get('staff.payroll.line')
|
||||
Period = pool.get('staff.payroll.period')
|
||||
clause = []
|
||||
periods_names = ''
|
||||
dom_payroll = cls.get_domain_payroll(data)
|
||||
if data['periods']:
|
||||
|
@ -1091,7 +1071,9 @@ class PayrollSheetReport(Report):
|
|||
periods_names = [p.name + ' / ' for p in periods]
|
||||
dom_payroll.append([('period', 'in', data['periods'])])
|
||||
|
||||
payrolls = Payroll.search(dom_payroll, order=[('employee.party.name', 'ASC'), ('period.name', 'ASC')])
|
||||
payrolls = Payroll.search(dom_payroll,
|
||||
order=[('employee.party.name', 'ASC'), ('period.name', 'ASC')]
|
||||
)
|
||||
|
||||
new_objects = []
|
||||
default_vals = cls.default_values()
|
||||
|
@ -1121,10 +1103,9 @@ class PayrollSheetReport(Report):
|
|||
payroll.end)/30
|
||||
values['salary_day'] = salary_day_in_date
|
||||
values['salary_hour'] = (salary_day_in_date / 8) if salary_day_in_date else 0
|
||||
# values['salary_day'] = payroll.employee.salary_day
|
||||
# values['salary_hour'] = (payroll.employee.salary_day / 8)
|
||||
values['worked_days'] = payroll.worked_days
|
||||
values['gross_payment'] = payroll.gross_payments
|
||||
|
||||
# Add compatibility with staff contracting
|
||||
project = ""
|
||||
if hasattr(payroll, 'project'):
|
||||
|
@ -1155,64 +1136,64 @@ class PayrollSheetReport(Report):
|
|||
@classmethod
|
||||
def default_values(cls):
|
||||
fields_no_amount = [
|
||||
'item',
|
||||
'employee',
|
||||
'id_number',
|
||||
'position',
|
||||
'legal_salary',
|
||||
'salary_day',
|
||||
'salary_hour',
|
||||
'worked_days',
|
||||
'period',
|
||||
'department',
|
||||
'item',
|
||||
'employee',
|
||||
'id_number',
|
||||
'position',
|
||||
'legal_salary',
|
||||
'salary_day',
|
||||
'salary_hour',
|
||||
'worked_days',
|
||||
'period',
|
||||
'department',
|
||||
]
|
||||
|
||||
fields_amount = [
|
||||
'salary',
|
||||
'reco',
|
||||
'recf',
|
||||
'hedo',
|
||||
'heno',
|
||||
'dom',
|
||||
'hedf',
|
||||
'henf',
|
||||
'cost_reco',
|
||||
'cost_recf',
|
||||
'cost_hedo',
|
||||
'cost_heno',
|
||||
'cost_dom',
|
||||
'cost_hedf',
|
||||
'cost_henf',
|
||||
'bonus',
|
||||
'total_extras',
|
||||
'gross_payment',
|
||||
'health',
|
||||
'retirement',
|
||||
'food',
|
||||
'transport',
|
||||
'fsp',
|
||||
'retefuente',
|
||||
'other_deduction',
|
||||
'total_deduction',
|
||||
'ibc',
|
||||
'net_payment',
|
||||
'box_family',
|
||||
'box_family',
|
||||
'unemployment',
|
||||
'interest',
|
||||
'holidays',
|
||||
'bonus_service',
|
||||
'discount',
|
||||
'other',
|
||||
'total_benefit',
|
||||
'risk',
|
||||
'health_provision',
|
||||
'retirement_provision',
|
||||
'total_ssi',
|
||||
'total_cost',
|
||||
'sena',
|
||||
'icbf',
|
||||
'acquired_product',
|
||||
'salary',
|
||||
'reco',
|
||||
'recf',
|
||||
'hedo',
|
||||
'heno',
|
||||
'dom',
|
||||
'hedf',
|
||||
'henf',
|
||||
'cost_reco',
|
||||
'cost_recf',
|
||||
'cost_hedo',
|
||||
'cost_heno',
|
||||
'cost_dom',
|
||||
'cost_hedf',
|
||||
'cost_henf',
|
||||
'bonus',
|
||||
'total_extras',
|
||||
'gross_payment',
|
||||
'health',
|
||||
'retirement',
|
||||
'food',
|
||||
'transport',
|
||||
'fsp',
|
||||
'retefuente',
|
||||
'other_deduction',
|
||||
'total_deduction',
|
||||
'ibc',
|
||||
'net_payment',
|
||||
'box_family',
|
||||
'box_family',
|
||||
'unemployment',
|
||||
'interest',
|
||||
'holidays',
|
||||
'bonus_service',
|
||||
'discount',
|
||||
'other',
|
||||
'total_benefit',
|
||||
'risk',
|
||||
'health_provision',
|
||||
'retirement_provision',
|
||||
'total_ssi',
|
||||
'total_cost',
|
||||
'sena',
|
||||
'icbf',
|
||||
'acquired_product',
|
||||
]
|
||||
|
||||
if '' in fields_no_amount:
|
||||
|
@ -1227,14 +1208,14 @@ class PayrollSheetReport(Report):
|
|||
|
||||
@classmethod
|
||||
def _prepare_lines(cls, payroll, vals):
|
||||
extras =[
|
||||
'reco',
|
||||
'recf',
|
||||
'hedo',
|
||||
'heno',
|
||||
'dom',
|
||||
'hedf',
|
||||
'henf',
|
||||
extras = [
|
||||
'reco',
|
||||
'recf',
|
||||
'hedo',
|
||||
'heno',
|
||||
'dom',
|
||||
'hedf',
|
||||
'henf',
|
||||
]
|
||||
for line in payroll.lines:
|
||||
if line.wage_type.definition == 'payment':
|
||||
|
@ -1251,25 +1232,25 @@ class PayrollSheetReport(Report):
|
|||
vals['risk'] += line.amount
|
||||
elif line.wage_type.type_concept == 'box_family':
|
||||
vals['box_family'] += line.amount
|
||||
elif line.wage_type.type_concept == 'unemployment':
|
||||
elif line.wage_type.type_concept == 'unemployment':
|
||||
vals['unemployment'] += line.amount
|
||||
elif line.wage_type.type_concept == 'interest':
|
||||
elif line.wage_type.type_concept == 'interest':
|
||||
vals['interest'] += line.amount
|
||||
elif line.wage_type.type_concept == 'holidays':
|
||||
elif line.wage_type.type_concept == 'holidays':
|
||||
vals['holidays'] += line.amount
|
||||
elif line.wage_type.type_concept == 'bonus':
|
||||
elif line.wage_type.type_concept == 'bonus':
|
||||
vals['bonus'] += line.amount
|
||||
elif line.wage_type.type_concept == 'bonus_service':
|
||||
elif line.wage_type.type_concept == 'bonus_service':
|
||||
vals['bonus_service'] += line.amount
|
||||
elif line.wage_type.type_concept == 'transport':
|
||||
elif line.wage_type.type_concept == 'transport':
|
||||
vals['transport'] += line.amount
|
||||
elif line.wage_type.type_concept == 'food':
|
||||
elif line.wage_type.type_concept == 'food':
|
||||
vals['food'] += line.amount
|
||||
elif line.wage_type.type_concept == 'sena':
|
||||
elif line.wage_type.type_concept == 'sena':
|
||||
vals['sena'] += line.amount
|
||||
elif line.wage_type.type_concept == 'icbf':
|
||||
elif line.wage_type.type_concept == 'icbf':
|
||||
vals['icbf'] += line.amount
|
||||
elif line.wage_type.type_concept == 'acquired_product':
|
||||
elif line.wage_type.type_concept == 'acquired_product':
|
||||
vals['acquired_product'] += line.amount
|
||||
else:
|
||||
print('Warning: Line no processed... ', line.wage_type.name)
|
||||
|
@ -1293,38 +1274,37 @@ class PayrollSheetReport(Report):
|
|||
vals['discount'] += line.amount
|
||||
print('Warning: Line no processed... ', line.wage_type.name)
|
||||
|
||||
vals['gross_payment'] = vals['salary'] + vals['total_extras'] + vals['transport'] + vals['food'] + vals['bonus']
|
||||
vals['gross_payment'] = sum([
|
||||
vals['salary'], vals['total_extras'], vals['transport'],
|
||||
vals['food'], vals['bonus']
|
||||
])
|
||||
vals['net_payment'] = vals['gross_payment'] - vals['total_deduction']
|
||||
vals['ibc'] = vals['gross_payment']
|
||||
vals['total_benefit'] = vals['unemployment'] + vals['interest'] + vals['holidays'] + vals['bonus_service']
|
||||
vals['total_benefit'] = sum([
|
||||
vals['unemployment'], vals['interest'], vals['holidays'],
|
||||
vals['bonus_service']
|
||||
])
|
||||
vals['total_ssi'] = vals['retirement_provision'] + vals['risk']
|
||||
vals['total_cost'] = vals['total_ssi'] + vals['box_family'] + vals['net_payment'] + vals['total_benefit']
|
||||
vals['total_cost'] = sum([
|
||||
vals['total_ssi'], vals['box_family'], vals['net_payment'],
|
||||
vals['total_benefit']
|
||||
])
|
||||
return vals
|
||||
|
||||
|
||||
class PayrollGroupStart:
|
||||
__metaclass__ = PoolMeta
|
||||
class PayrollGroupStart(metaclass=PoolMeta):
|
||||
__name__ = 'staff.payroll_group.start'
|
||||
department = fields.Many2One('company.department', 'Department')
|
||||
|
||||
|
||||
class PayrollGroup:
|
||||
__metaclass__ = PoolMeta
|
||||
class PayrollGroup(metaclass=PoolMeta):
|
||||
__name__ = 'staff.payroll_group'
|
||||
|
||||
def get_employees_dom(self, employees_w_payroll):
|
||||
dom_employees = super(PayrollGroup, self).get_employees_dom(employees_w_payroll)
|
||||
dom = super(PayrollGroup, self).get_employees_dom(employees_w_payroll)
|
||||
if self.start.department:
|
||||
dom_employees.append(
|
||||
('department', '=', self.start.department.id),
|
||||
)
|
||||
return dom_employees
|
||||
|
||||
# def contract_out_date(self, employee):
|
||||
# if employee.contract.end_date and \
|
||||
# employee.contract.end_date < self.start.period.start:
|
||||
# return True
|
||||
# return False
|
||||
dom.append(('department', '=', self.start.department.id))
|
||||
return dom
|
||||
|
||||
|
||||
class OpenPayrollByPeriodStart(ModelView):
|
||||
|
@ -1332,7 +1312,7 @@ class OpenPayrollByPeriodStart(ModelView):
|
|||
__name__ = 'staff_payroll_co.open_payroll_by_period.start'
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
|
||||
required=True)
|
||||
required=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
@ -1352,11 +1332,10 @@ class OpenPayrollByPeriod(Wizard):
|
|||
'staff_payroll_co.open_payroll_by_period_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'open_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
open_ = StateAction('staff_payroll_co.act_payroll_by_period_board')
|
||||
|
||||
def do_open_(self, action):
|
||||
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'fiscalyear': self.start.fiscalyear.id,
|
||||
|
@ -1374,9 +1353,9 @@ class PayrollByPeriodDynamic(Period):
|
|||
payrolls = fields.Function(fields.One2Many('staff.payroll', None,
|
||||
'Payrolls'), 'get_payrolls')
|
||||
amount_net_payment = fields.Function(fields.Numeric('Amount Net Payment',
|
||||
digits=(16, 2)), 'get_amount')
|
||||
digits=(16, 2)), 'get_amount')
|
||||
amount_total_cost = fields.Function(fields.Numeric('Amount Total Cost',
|
||||
digits=(16, 2)), 'get_amount')
|
||||
digits=(16, 2)), 'get_amount')
|
||||
|
||||
def get_amount(self, name=None):
|
||||
res = []
|
||||
|
@ -1396,195 +1375,13 @@ class PayrollByPeriodDynamic(Period):
|
|||
return [i.id for i in payrolls]
|
||||
|
||||
|
||||
class FixPayrollStart(ModelView):
|
||||
'Fix Payroll Start'
|
||||
__name__ = 'staff.fix_payroll.start'
|
||||
start_period = fields.Many2One('staff.payroll.period',
|
||||
'Start Period', required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
depends=['start_period'], required=True)
|
||||
employee = fields.Many2One('company.employee', 'Employee')
|
||||
wage_type = fields.Many2One('staff.wage_type', 'Wage Type', required=True)
|
||||
project = fields.Many2One('project.work', 'Project', domain=[
|
||||
('type', '=', 'project')
|
||||
])
|
||||
|
||||
|
||||
class FixPayroll(Wizard):
|
||||
'Fix Payroll'
|
||||
__name__ = 'staff.fix_payroll'
|
||||
start = StateView('staff.fix_payroll.start',
|
||||
'staff_payroll_co.fix_payroll_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Accept', 'open_', 'tryton-ok', default=True),
|
||||
])
|
||||
open_ = StateTransition()
|
||||
|
||||
def transition_open_(self):
|
||||
pool = Pool()
|
||||
Payroll = pool.get('staff.payroll')
|
||||
Move = pool.get('account.move')
|
||||
Employee = pool.get('company.employee')
|
||||
|
||||
dom_start = [
|
||||
('end', '=', '2018-12-31'),
|
||||
('project', '=', self.start.project.id)
|
||||
]
|
||||
|
||||
if self.start.employee:
|
||||
dom_start.append(('employee', '=', self.start.employee.id))
|
||||
payrolls = Payroll.search(dom_start)
|
||||
|
||||
for payroll in payrolls:
|
||||
dom_payrolls = [
|
||||
('start', '>=', self.start.start_period.start),
|
||||
('start', '<=', self.start.end_period.start),
|
||||
('state', '=', 'posted'),
|
||||
('employee', '=', payroll.employee.id),
|
||||
('contract', '=', payroll.contract.id),
|
||||
]
|
||||
_payrolls = Payroll.search(dom_payrolls, order=[('start', 'ASC')])
|
||||
|
||||
move_ids = [ p.move.id for p in _payrolls]
|
||||
Move.draft(move_ids)
|
||||
|
||||
amount = 0
|
||||
for _payroll in _payrolls:
|
||||
if not _payroll.move:
|
||||
continue
|
||||
# _payroll.move.draft([_payroll.move.id])
|
||||
# _payroll.move.save()
|
||||
|
||||
for line in _payroll.lines:
|
||||
if line.wage_type.id == self.start.wage_type.id:
|
||||
self.recompute_wage_type(line)
|
||||
# _payroll.save()
|
||||
# amount = line.amount
|
||||
# acc_debit_id = line.wage_type.debit_account.id
|
||||
# acc_credit_id = line.wage_type.credit_account.id
|
||||
break
|
||||
|
||||
debit_ready = credit_ready = False
|
||||
# for mline in _payroll.move.lines:
|
||||
# if debit_ready and credit_ready:
|
||||
# break
|
||||
# if mline.reconciliation:
|
||||
# continue
|
||||
# # if mline.account.id in [acc_debit_id, acc_credit_id]:
|
||||
# # if mline.account.id == acc_credit_id:
|
||||
# # mline.write([mline], {'credit': amount})
|
||||
# # credit_ready = True
|
||||
# # elif mline.account.id == acc_debit_id:
|
||||
# # mline.write([mline], {'debit': amount})
|
||||
# # acc_debit_id = True
|
||||
# payroll.process([payroll])
|
||||
# payroll.post([payroll])
|
||||
# if _payroll.move.state == 'posted':
|
||||
# continue
|
||||
# if debit_ready and credit_ready:
|
||||
# _payroll.move.write([payroll.move], {
|
||||
# 'state': 'posted',
|
||||
# })
|
||||
|
||||
# if payroll.move and line.wage_type.type_concept in ['risk', 'box_family']:
|
||||
# self.fix_move(payroll.move, line.wage_type, line.amount)
|
||||
return 'end'
|
||||
|
||||
def _compute_wage_type(self, wage_type, payroll):
|
||||
salary_args = payroll.get_salary_full(wage_type)
|
||||
return wage_type.compute_unit_price(salary_args)
|
||||
|
||||
def recompute_wage_type(self, pline):
|
||||
Line = Pool().get('account.move.line')
|
||||
wage_type = pline.wage_type
|
||||
unit_value = None
|
||||
salary_args = {}
|
||||
salary = []
|
||||
if wage_type.type_concept in ['risk', 'box_family']:
|
||||
unit_value = self._compute_wage_type(wage_type, pline.payroll)
|
||||
if wage_type.type_concept == 'interest':
|
||||
unit_value = pline.payroll._compute_interest(pline.wage_type, pline.payroll.start)
|
||||
elif wage_type.type_concept == 'holidays':
|
||||
concepts_salary_ids = [cs.id for cs in wage_type.concepts_salary]
|
||||
for line in pline.payroll.lines:
|
||||
if line.wage_type.id in concepts_salary_ids:
|
||||
salary.append(line.amount)
|
||||
salary_args['salary'] = sum(salary)
|
||||
unit_value = wage_type.compute_unit_price(salary_args)
|
||||
if not unit_value:
|
||||
return
|
||||
|
||||
pline.write([pline], {'unit_value': unit_value})
|
||||
pline.on_change_with_amount()
|
||||
if pline.payroll.move:
|
||||
# Check that line is not reconciled
|
||||
move = pline.payroll.move
|
||||
debit_account = wage_type.debit_account.id
|
||||
credit_account = wage_type.credit_account.id
|
||||
debit_ready = False
|
||||
credit_ready = False
|
||||
vals = []
|
||||
to_process = [l for l in move.lines if l.account.id in (debit_account, credit_account)]
|
||||
for line in to_process:
|
||||
if line.reconciliation or len(to_process) == 1:
|
||||
return
|
||||
# if len(to_process) > 1:
|
||||
for line in to_process:
|
||||
# if debit_ready and credit_ready:
|
||||
# break
|
||||
# if line.reconciliation:
|
||||
# break
|
||||
|
||||
if line.account.id == debit_account and line.debit != pline.amount:
|
||||
Line.write([line], {'debit': pline.amount})
|
||||
elif line.account.id == credit_account and line.credit != pline.amount:
|
||||
Line.write([line], {'credit': pline.amount})
|
||||
# vals[line] = {}
|
||||
# if line.debit > 0:
|
||||
# vals = {'debit': pline.amount}
|
||||
# debit_ready = True
|
||||
# else:
|
||||
# vals = {'credit': pline.amount}
|
||||
# # vals = {'credit': pline.amount}
|
||||
# credit_ready = True
|
||||
|
||||
# move.write([move], {'state': 'draft'})
|
||||
# if len(vals) == 2:
|
||||
# for l, v in vals:
|
||||
|
||||
move.write([move], {
|
||||
'state': 'posted',
|
||||
})
|
||||
|
||||
def fix_move(self, move, wage_type, amount):
|
||||
accounts = []
|
||||
if wage_type.credit_account:
|
||||
accounts.append(wage_type.credit_account.id)
|
||||
if wage_type.debit_account:
|
||||
accounts.append(wage_type.debit_account.id)
|
||||
|
||||
move.write([move], {
|
||||
'state': 'draft',
|
||||
})
|
||||
for line in move.lines:
|
||||
if line.account.id not in accounts:
|
||||
continue
|
||||
if line.debit > 0:
|
||||
line.debit = amount
|
||||
else:
|
||||
line.credit = amount
|
||||
line.save()
|
||||
|
||||
move.write([move], {
|
||||
'state': 'posted',
|
||||
})
|
||||
|
||||
|
||||
class Exo2276Start(ModelView):
|
||||
'Payroll Exo 2276 Start'
|
||||
__name__ = 'staff.payroll_exo2276.start'
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period', required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period', required=True)
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period',
|
||||
required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
required=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
|
||||
@staticmethod
|
||||
|
@ -1717,7 +1514,6 @@ class Exo2276Report(Report):
|
|||
report_context['company'] = user.company
|
||||
return report_context
|
||||
|
||||
|
||||
@classmethod
|
||||
def _prepare_lines(cls, payrolls, vals, party_id):
|
||||
payroll_ids = [payroll.id for payroll in payrolls]
|
||||
|
@ -1800,8 +1596,10 @@ class Exo2276Report(Report):
|
|||
class IncomeWithholdingsStart(ModelView):
|
||||
'Income Withholding Start'
|
||||
__name__ = 'staff.payroll.income_withholdings.start'
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period', required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period', required=True)
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period',
|
||||
required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
required=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
employees = fields.Many2Many('company.employee', None, None, 'Employees')
|
||||
|
||||
|
@ -1838,7 +1636,6 @@ class IncomeWithholdings(Wizard):
|
|||
|
||||
class IncomeWithholdingsReport(Exo2276Report):
|
||||
'Income Withholding Report'
|
||||
|
||||
__name__ = 'staff.payroll.income_withholdings_report'
|
||||
|
||||
@classmethod
|
||||
|
@ -1874,10 +1671,12 @@ class PayrollExportStart(ModelView):
|
|||
'Export Payroll Start'
|
||||
__name__ = 'staff.payroll.export.start'
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period', required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period', required=True)
|
||||
start_period = fields.Many2One('staff.payroll.period', 'Start Period',
|
||||
required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
required=True)
|
||||
department = fields.Many2One('company.department', 'Department',
|
||||
required=False, depends=['employee'])
|
||||
required=False, depends=['employee'])
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
@ -1891,7 +1690,7 @@ class PayrollExport(Wizard):
|
|||
'staff_payroll_co.payroll_export_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
print_ = StateReport('staff.payroll.export_report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
|
32
wage_type.py
32
wage_type.py
|
@ -1,5 +1,5 @@
|
|||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
# 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 trytond.pool import PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.transaction import Transaction
|
||||
|
@ -22,18 +22,10 @@ class WageType(metaclass=PoolMeta):
|
|||
apply_special_salary = fields.Boolean('Apply Special Salary')
|
||||
adjust_days_worked = fields.Boolean('Adjust Days Worked',
|
||||
help='If is true, rounded month work days on payroll to 30 indeed '
|
||||
'if month has 31 days, or rounded to 15 indeed the biweekly'
|
||||
'pay has 16 days')
|
||||
'if month has 31 days, or rounded to 15 indeed the biweekly'
|
||||
'pay has 16 days')
|
||||
round_amounts = fields.Selection(ROUND_AMOUNTS, 'Rounds amounts',
|
||||
help='Approximates the highest value in hundreds')
|
||||
# minimal_expense = fields.Function(fields.Numeric('Minimun Expense Amount'),
|
||||
# 'validate_minimum_amount')
|
||||
# minimal_unit_price = fields.Function(fields.Numeric('Minimun Expense Amount'),
|
||||
# 'validate_minimum_amount')
|
||||
# limit_days = fields.Numeric('Limit Days', states={
|
||||
# 'invisible': Eval('type_concept') != 'special',
|
||||
# 'required': Eval('type_concept') == 'special',
|
||||
# })
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -68,16 +60,6 @@ class WageType(metaclass=PoolMeta):
|
|||
def __register__(cls, module_name):
|
||||
super(WageType, cls).__register__(module_name)
|
||||
cursor = Transaction().connection.cursor()
|
||||
cursor.execute('ALTER TABLE staff_wage_type DROP COLUMN IF EXISTS amount_required')
|
||||
|
||||
# def validate_minimum_amount(self, name):
|
||||
# config = Pool().get('staff.configuration')(1)
|
||||
# if config:
|
||||
# minimum_salary = config.minimum_salary
|
||||
# num_subperiod = 30 / config.default_liquidation_period
|
||||
# amount = minimum_salary / num_subperiod
|
||||
# if name == 'minimal_unit_price':
|
||||
# return self.compute_unit_price({'salary': amount})
|
||||
# if name == 'minimal_expense':
|
||||
# return self.compute_expense({'salary': amount})
|
||||
# return 0
|
||||
cursor.execute(
|
||||
'ALTER TABLE staff_wage_type DROP COLUMN IF EXISTS amount_required'
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue