Fix round unit price not amount
This commit is contained in:
parent
a02924f046
commit
4fde8cb87c
91
payroll.py
91
payroll.py
|
@ -19,8 +19,8 @@ __all__ = [
|
|||
'PayrollGlobalReport', 'PayrollPaymentReport', 'PayrollPayment',
|
||||
'PayrollPaymentStart', 'PayrollPaycheckStart', 'PayrollPaycheckReport',
|
||||
'PayrollPaycheck', 'PayrollSheetReport', 'PayrollSheet', 'PayrollLine',
|
||||
'PayrollSheetStart', 'PayrollGroupStart', 'PayrollGroup',
|
||||
'PayrollByPeriodDynamic', 'OpenPayrollByPeriod', 'OpenPayrollByPeriodStart',
|
||||
'PayrollSheetStart', 'PayrollGroupStart', 'OpenPayrollByPeriodStart',
|
||||
'PayrollByPeriodDynamic', 'OpenPayrollByPeriod', 'PayrollGroup',
|
||||
'FixPayrollStart', 'FixPayroll', 'Exo2276Start', 'Exo2276',
|
||||
'Exo2276Report', 'IncomeWithholdings', 'ExportMovesReport',
|
||||
'IncomeWithholdingsStart', 'IncomeWithholdingsReport',
|
||||
|
@ -71,16 +71,17 @@ ENTITY_ACCOUNTS = {
|
|||
class PayrollLine(metaclass=PoolMeta):
|
||||
__name__ = "staff.payroll.line"
|
||||
|
||||
def get_amount(self, name):
|
||||
amount = super(PayrollLine, self).get_amount(name)
|
||||
if amount and self.wage_type and self.wage_type.round_amounts:
|
||||
if self.wage_type.round_amounts == 'above_amount':
|
||||
amount = math.ceil(float(amount) / 100.0) * 100
|
||||
if self.wage_type.round_amounts == 'under_amount':
|
||||
amount = math.floor(float(amount) / 100.0) * 100
|
||||
if self.wage_type.round_amounts == 'automatic':
|
||||
amount = round(amount, -2)
|
||||
return amount
|
||||
# BUG BUG BUG BUG BUG BUG BUG BUG
|
||||
# def get_amount(self, name):
|
||||
# amount = super(PayrollLine, self).get_amount(name)
|
||||
# if amount and self.wage_type and self.wage_type.round_amounts:
|
||||
# if self.wage_type.round_amounts == 'above_amount':
|
||||
# amount = math.ceil(float(amount) / 100.0) * 100
|
||||
# elif self.wage_type.round_amounts == 'under_amount':
|
||||
# amount = math.floor(float(amount) / 100.0) * 100
|
||||
# elif self.wage_type.round_amounts == 'automatic':
|
||||
# amount = round(amount, -2)
|
||||
# return amount
|
||||
|
||||
|
||||
class Payroll(metaclass=PoolMeta):
|
||||
|
@ -103,17 +104,12 @@ class Payroll(metaclass=PoolMeta):
|
|||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Payroll, cls).__setup__()
|
||||
table = cls.__table__()
|
||||
cls._error_messages.update({
|
||||
'period_without_contract': ('The period selected without contract'
|
||||
' for the employee!'),
|
||||
'error_report': ('Error %s !'),
|
||||
}
|
||||
)
|
||||
# cls._sql_constraints += [
|
||||
# ('employee_period_contract_uniq', Unique(table, table.contract, table.employee, table.period, table.project),
|
||||
# 'Already exists one payroll for this employee with this contract in this period!'),
|
||||
# ]
|
||||
|
||||
@fields.depends('end', 'date_effective')
|
||||
def on_change_with_date_effective(self):
|
||||
|
@ -184,7 +180,8 @@ 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')
|
||||
|
@ -251,6 +248,11 @@ class Payroll(metaclass=PoolMeta):
|
|||
return 0
|
||||
return amount
|
||||
|
||||
def is_first_payroll(self):
|
||||
if self.start <= self.contract.start_date <= self.end:
|
||||
pass
|
||||
return False
|
||||
|
||||
def _is_last_payroll_month(self):
|
||||
_, end_day = calendar.monthrange(self.start.year, self.start.month)
|
||||
last_day = date(self.start.year, self.start.month, end_day)
|
||||
|
@ -261,8 +263,8 @@ class Payroll(metaclass=PoolMeta):
|
|||
def _compute_apply_special_salary(self):
|
||||
MandatoryWages = Pool().get('staff.payroll.mandatory_wage')
|
||||
mandatory_wages = MandatoryWages.search([
|
||||
('employee', '=', self.employee.id),
|
||||
('wage_type.apply_special_salary', '=', True),
|
||||
('employee', '=', self.employee.id),
|
||||
('wage_type.apply_special_salary', '=', True),
|
||||
])
|
||||
salary_plus = _ZERO
|
||||
wages = [w.wage_type for w in mandatory_wages]
|
||||
|
@ -320,8 +322,14 @@ class Payroll(metaclass=PoolMeta):
|
|||
return res
|
||||
|
||||
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':
|
||||
unit_value = math.ceil(float(unit_value) / 100.0) * 100
|
||||
elif self.wage_type.round_amounts == 'under_amount':
|
||||
unit_value = math.floor(float(unit_value) / 100.0) * 100
|
||||
elif self.wage_type.round_amounts == 'automatic':
|
||||
unit_value = round(unit_value, -2)
|
||||
res = super(Payroll, self).get_line(wage, qty, unit_value, party)
|
||||
# res['unit_value'] = self._validate_amount_wage(wage, res['unit_value'])
|
||||
return res
|
||||
|
||||
# def _validate_amount_wage(self, wage, amount):
|
||||
|
@ -356,7 +364,6 @@ class Payroll(metaclass=PoolMeta):
|
|||
('end_date', '>=', self.start),
|
||||
('state', '=', 'done'),
|
||||
])
|
||||
days = 0
|
||||
events_lines_to_create = []
|
||||
absenteeism_days = 0
|
||||
discounts = {}
|
||||
|
@ -409,12 +416,12 @@ class Payroll(metaclass=PoolMeta):
|
|||
else:
|
||||
contract = self.contract
|
||||
dom_payroll.append(
|
||||
('start', '>=', contract.start_date),
|
||||
('start', '>=', contract.start_date),
|
||||
)
|
||||
if contract.end_date:
|
||||
dom_payroll.append(
|
||||
('start', '<=', contract.end_date)
|
||||
)
|
||||
)
|
||||
|
||||
payrolls = self.search(dom_payroll)
|
||||
return [p.id for p in payrolls]
|
||||
|
@ -527,7 +534,7 @@ class Payroll(metaclass=PoolMeta):
|
|||
for l in self.lines:
|
||||
if l.wage_type and l.wage_type.type_concept in concepts and \
|
||||
l.wage_type.definition == 'payment' and \
|
||||
l.wage_type.salary_constitute == True:
|
||||
l.wage_type.salary_constitute is True:
|
||||
res += l.amount
|
||||
return res
|
||||
|
||||
|
@ -545,9 +552,9 @@ class PayrollGlobalStart(ModelView):
|
|||
'Payroll Global Start'
|
||||
__name__ = 'staff.payroll_global.start'
|
||||
start_period = fields.Many2One('staff.payroll.period',
|
||||
'Start Period', required=True)
|
||||
'Start Period', required=True)
|
||||
end_period = fields.Many2One('staff.payroll.period', 'End Period',
|
||||
depends=['start_period'])
|
||||
depends=['start_period'])
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
department = fields.Many2One('company.department', 'Department')
|
||||
include_finished = fields.Boolean('Include Finished Contract')
|
||||
|
@ -569,7 +576,7 @@ class PayrollGlobal(Wizard):
|
|||
'staff_payroll_co.payroll_global_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
print_ = StateReport('staff.payroll.global_report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
@ -603,11 +610,11 @@ class PayrollGlobalReport(Report):
|
|||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(PayrollGlobalReport, cls).get_context(records, data)
|
||||
report_context = super(PayrollGlobalReport, 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')
|
||||
Department = pool.get('company.department')
|
||||
start_period = Period(data['start_period'])
|
||||
|
@ -736,12 +743,15 @@ class PayrollGlobalReport(Report):
|
|||
@classmethod
|
||||
def default_values(cls):
|
||||
WageType = Pool().get('staff.wage_type')
|
||||
fields_string = ['employee_code', 'employee', 'employee_salary',
|
||||
'employee_id_number', 'party_health', 'party_retirement', 'basic_salary',
|
||||
fields_string = [
|
||||
'employee_code', 'employee', 'employee_salary',
|
||||
'employee_id_number', 'party_health', 'party_retirement',
|
||||
'basic_salary',
|
||||
]
|
||||
fields_numeric = [
|
||||
'net_payment', 'worked_days', 'gross_payments', 'total_deductions',
|
||||
'others_payments', 'others_deductions'
|
||||
]
|
||||
fields_numeric = ['net_payment', 'worked_days',
|
||||
'gross_payments', 'total_deductions', 'others_payments',
|
||||
'others_deductions']
|
||||
lines_fields = dict(WageType.type_concept.selection).keys()
|
||||
if '' in lines_fields:
|
||||
lines_fields.remove('')
|
||||
|
@ -755,17 +765,6 @@ class PayrollGlobalReport(Report):
|
|||
default_values.setdefault(field, Decimal(0))
|
||||
return default_values
|
||||
|
||||
# @classmethod
|
||||
# def round_basic_salary(cls, salary):
|
||||
# basic_salary = math.ceil(salary)
|
||||
# string_basic_salary = str(basic_salary)[len(str(basic_salary))-1]
|
||||
# if string_basic_salary == '9':
|
||||
# return basic_salary + 1
|
||||
# elif string_basic_salary == '1':
|
||||
# return basic_salary - 1
|
||||
# else:
|
||||
# return basic_salary
|
||||
|
||||
|
||||
class PayrollPaymentStart(ModelView):
|
||||
'Payroll Payment Start'
|
||||
|
|
54
wage_type.py
54
wage_type.py
|
@ -1,8 +1,7 @@
|
|||
#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, Pool
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
|
@ -22,10 +21,11 @@ class WageType(metaclass=PoolMeta):
|
|||
month_application = fields.Boolean('Month Application')
|
||||
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')
|
||||
round_amounts = fields.Selection(ROUND_AMOUNTS, 'Rounds amounts', help='Approximates the highest value in hundreds')
|
||||
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')
|
||||
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'),
|
||||
|
@ -39,27 +39,27 @@ class WageType(metaclass=PoolMeta):
|
|||
def __setup__(cls):
|
||||
super(WageType, cls).__setup__()
|
||||
new_sel = [
|
||||
('health', 'Health'),
|
||||
('retirement', 'Retirement'),
|
||||
('risk', 'Risk'),
|
||||
('box_family', 'Box Family'),
|
||||
('commission', 'Commission'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('food', 'Food'),
|
||||
('unemployment', 'Unemployment'),
|
||||
('allowance', 'Allowance'),
|
||||
('transport', 'Transport'),
|
||||
('interest', 'Interest'),
|
||||
('bonus', 'Bonus'),
|
||||
('tax', 'Tax'),
|
||||
('holidays', 'Holidays'),
|
||||
('syndicate', 'Syndicate'),
|
||||
('fsp', 'FSP'),
|
||||
('sena', 'SENA'),
|
||||
('icbf', 'ICBF'),
|
||||
('acquired_product', 'Acquired Product'),
|
||||
('loan', 'Loan'),
|
||||
('advance', 'Advance'),
|
||||
('health', 'Health'),
|
||||
('retirement', 'Retirement'),
|
||||
('risk', 'Risk'),
|
||||
('box_family', 'Box Family'),
|
||||
('commission', 'Commission'),
|
||||
('bonus_service', 'Bonus Service'),
|
||||
('food', 'Food'),
|
||||
('unemployment', 'Unemployment'),
|
||||
('allowance', 'Allowance'),
|
||||
('transport', 'Transport'),
|
||||
('interest', 'Interest'),
|
||||
('bonus', 'Bonus'),
|
||||
('tax', 'Tax'),
|
||||
('holidays', 'Holidays'),
|
||||
('syndicate', 'Syndicate'),
|
||||
('fsp', 'FSP'),
|
||||
('sena', 'SENA'),
|
||||
('icbf', 'ICBF'),
|
||||
('acquired_product', 'Acquired Product'),
|
||||
('loan', 'Loan'),
|
||||
('advance', 'Advance'),
|
||||
]
|
||||
if new_sel not in cls.type_concept.selection:
|
||||
cls.type_concept.selection.extend(new_sel)
|
||||
|
|
Loading…
Reference in New Issue