mirror of
https://bitbucket.org/presik/trytonpsk-staff_payroll.git
synced 2023-12-14 05:33:13 +01:00
Add minor fixes, indentation, remove comments
This commit is contained in:
parent
5132753f99
commit
5994a58db8
2 changed files with 83 additions and 87 deletions
168
payroll.py
168
payroll.py
|
@ -10,13 +10,15 @@ from trytond.transaction import Transaction
|
|||
from trytond.modules.company import CompanyReport
|
||||
from trytond.wizard import Wizard, StateView, StateTransition, Button
|
||||
|
||||
__all__ = ['Payroll', 'PayrollLine', 'PayrollReport', 'Move',
|
||||
'PayrollGroupStart', 'PayrollGroup', 'PayrollPreliquidation',
|
||||
'PayrollRecompute']
|
||||
__all__ = [
|
||||
'Payroll', 'PayrollLine', 'PayrollReport', 'Move', 'PayrollGroupStart',
|
||||
'PayrollGroup', 'PayrollPreliquidation', 'PayrollRecompute'
|
||||
]
|
||||
|
||||
STATES = {'readonly': (Eval('state') != 'draft')}
|
||||
|
||||
_DEFAULT_WORK_DAY = 8
|
||||
|
||||
_ZERO = Decimal('0.0')
|
||||
|
||||
|
||||
|
@ -25,13 +27,13 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
__name__ = "staff.payroll"
|
||||
_rec_name = 'number'
|
||||
number = fields.Char('Number', readonly=True, help="Secuence",
|
||||
select=True)
|
||||
select=True)
|
||||
period = fields.Many2One('staff.payroll.period', 'Period',
|
||||
required=True, states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
})
|
||||
required=True, states={
|
||||
'readonly': Eval('state') != 'draft',
|
||||
})
|
||||
employee = fields.Many2One('company.employee', 'Employee',
|
||||
states=STATES, required=True, depends=['state'], select=True)
|
||||
states=STATES, required=True, depends=['state'], select=True)
|
||||
kind = fields.Selection([
|
||||
('normal', 'Normal'),
|
||||
('special', 'Special'),
|
||||
|
@ -115,27 +117,27 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
'bad_configuration_wage_type': ('Bad configuration of the wage type "%s".'),
|
||||
})
|
||||
cls._transitions |= set((
|
||||
('draft', 'cancel'),
|
||||
('cancel', 'draft'),
|
||||
('draft', 'processed'),
|
||||
('processed', 'posted'),
|
||||
('posted', 'draft'),
|
||||
('processed', 'draft'),
|
||||
))
|
||||
('draft', 'cancel'),
|
||||
('cancel', 'draft'),
|
||||
('draft', 'processed'),
|
||||
('processed', 'posted'),
|
||||
('posted', 'draft'),
|
||||
('processed', 'draft'),
|
||||
))
|
||||
cls._buttons.update({
|
||||
'draft': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
},
|
||||
'post': {
|
||||
'invisible': Eval('state') != 'processed',
|
||||
},
|
||||
'cancel': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
},
|
||||
'process': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
},
|
||||
})
|
||||
'draft': {
|
||||
'invisible': Eval('state') == 'draft',
|
||||
},
|
||||
'post': {
|
||||
'invisible': Eval('state') != 'processed',
|
||||
},
|
||||
'cancel': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
},
|
||||
'process': {
|
||||
'invisible': Eval('state') != 'draft',
|
||||
},
|
||||
})
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
|
@ -145,6 +147,15 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
def default_kind():
|
||||
return 'normal'
|
||||
|
||||
@staticmethod
|
||||
def default_state():
|
||||
return 'draft'
|
||||
|
||||
@staticmethod
|
||||
def _get_origin():
|
||||
'Return list of Model names for origin Reference'
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def default_journal():
|
||||
Configuration = Pool().get('staff.configuration')
|
||||
|
@ -176,25 +187,17 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
for payroll in payrolls:
|
||||
payroll.check_start_end()
|
||||
|
||||
@staticmethod
|
||||
def default_state():
|
||||
return 'draft'
|
||||
|
||||
@staticmethod
|
||||
def _get_origin():
|
||||
'Return list of Model names for origin Reference'
|
||||
return []
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
if clause[1].startswith('!') or clause[1].startswith('not '):
|
||||
bool_op = 'AND'
|
||||
else:
|
||||
bool_op = 'OR'
|
||||
return [bool_op,
|
||||
return [
|
||||
bool_op,
|
||||
('employee',) + tuple(clause[1:]),
|
||||
('number',) + tuple(clause[1:]),
|
||||
]
|
||||
]
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
@ -279,7 +282,6 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
|
||||
def compute_salary_full(self, wage):
|
||||
wages_ids = [s.id for s in wage.concepts_salary]
|
||||
# wages_names = [s.name for s in wage.concepts_salary]
|
||||
if wages_ids:
|
||||
salary_full = sum([
|
||||
line.amount for line in self.lines if line.wage_type.id in wages_ids
|
||||
|
@ -297,13 +299,13 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
period_id = Period.find(self.company.id, date=self.date_effective)
|
||||
move_lines = self.get_moves_lines()
|
||||
move, = Move.create([{
|
||||
'journal': self.journal.id,
|
||||
'origin': str(self),
|
||||
'period': period_id,
|
||||
'date': self.date_effective,
|
||||
'state': 'draft',
|
||||
'description': self.description,
|
||||
'lines': [('create', move_lines)],
|
||||
'journal': self.journal.id,
|
||||
'origin': str(self),
|
||||
'period': period_id,
|
||||
'date': self.date_effective,
|
||||
'state': 'draft',
|
||||
'description': self.description,
|
||||
'lines': [('create', move_lines)],
|
||||
}])
|
||||
self.write([self], {'move': move.id})
|
||||
Move.post([self.move])
|
||||
|
@ -341,7 +343,6 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
amount_credit = line.amount + expense
|
||||
debit_acc = line.wage_type.debit_account
|
||||
|
||||
# if 1:
|
||||
try:
|
||||
if debit_acc and amount_debit > _ZERO:
|
||||
if line.wage_type.definition == 'discount':
|
||||
|
@ -390,7 +391,6 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
|
||||
if credit_acc and not line_credit_ready:
|
||||
lines_moves[credit_acc.id][party.id]['credit'] += amount_credit
|
||||
# else:
|
||||
except:
|
||||
self.raise_user_error('bad_configuration_wage_type', line.wage_type.name)
|
||||
|
||||
|
@ -412,8 +412,7 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
PayrollLine = Pool().get('staff.payroll.line')
|
||||
values = []
|
||||
salary_args = {}
|
||||
salary_in_date = self.contract.get_salary_in_date(
|
||||
self.end)
|
||||
salary_in_date = self.contract.get_salary_in_date(self.end)
|
||||
for wage, party, fix_amount in wages:
|
||||
if not fix_amount:
|
||||
salary_args = self.get_salary_full(wage)
|
||||
|
@ -428,8 +427,9 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
discount = discounts.get(wage.id)
|
||||
qty = self.get_line_quantity_special(wage)
|
||||
if qty == 0:
|
||||
qty = self.get_line_quantity(wage, self.start, self.end,
|
||||
extras, discount)
|
||||
qty = self.get_line_quantity(
|
||||
wage, self.start, self.end, extras, discount
|
||||
)
|
||||
values.append(self.get_line(wage, qty, unit_value, party))
|
||||
|
||||
PayrollLine.create(values)
|
||||
|
@ -449,24 +449,25 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
|
||||
def update_preliquidation(self, extras):
|
||||
for line in self.lines:
|
||||
if not line.wage_type.salary_constitute:
|
||||
salary_args = self.get_salary_full(line.wage_type)
|
||||
unit_value = line.wage_type.compute_unit_price(salary_args)
|
||||
unit_value = self._validate_amount_wage(line.wage_type, unit_value)
|
||||
line.write([line], {
|
||||
'unit_value': unit_value,
|
||||
})
|
||||
if line.wage_type.salary_constitute:
|
||||
continue
|
||||
salary_args = self.get_salary_full(line.wage_type)
|
||||
unit_value = line.wage_type.compute_unit_price(salary_args)
|
||||
unit_value = self._validate_amount_wage(line.wage_type, unit_value)
|
||||
line.write([line], {
|
||||
'unit_value': unit_value,
|
||||
})
|
||||
|
||||
def get_line(self, wage, qty, unit_value, party=None):
|
||||
res = {
|
||||
'sequence': wage.sequence,
|
||||
'payroll': self.id,
|
||||
'wage_type': wage.id,
|
||||
'description': wage.name,
|
||||
'quantity': qty,
|
||||
'unit_value': unit_value,
|
||||
'uom': wage.uom,
|
||||
'receipt': wage.receipt,
|
||||
'sequence': wage.sequence,
|
||||
'payroll': self.id,
|
||||
'wage_type': wage.id,
|
||||
'description': wage.name,
|
||||
'quantity': qty,
|
||||
'unit_value': unit_value,
|
||||
'uom': wage.uom,
|
||||
'receipt': wage.receipt,
|
||||
}
|
||||
if party:
|
||||
res['party'] = party.id
|
||||
|
@ -474,8 +475,8 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
|
||||
def _get_line_quantity(self, quantity_days, wage, extras, discount):
|
||||
Configuration = Pool().get('staff.configuration')
|
||||
configuration = Configuration(1)
|
||||
default_hour_workday = configuration.default_hour_workday or _DEFAULT_WORK_DAY
|
||||
config = Configuration(1)
|
||||
default_hour_workday = config.default_hour_workday or _DEFAULT_WORK_DAY
|
||||
quantity = wage.default_quantity or 0
|
||||
if quantity_days < 0:
|
||||
quantity_days = 0
|
||||
|
@ -532,7 +533,8 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
return (self.gross_payments - self.total_deductions)
|
||||
|
||||
def get_total_cost(self, name):
|
||||
res = sum([line.amount for line in self.lines
|
||||
res = sum([
|
||||
line.amount for line in self.lines
|
||||
if line.wage_type.definition == 'payment'])
|
||||
return res
|
||||
|
||||
|
@ -544,7 +546,7 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
self.end <= self.period.end:
|
||||
return
|
||||
if self.start >= self.period.start and \
|
||||
self.end == None:
|
||||
self.end is None:
|
||||
return
|
||||
self.raise_user_error('wrong_start_end', self.employee.party.name)
|
||||
|
||||
|
@ -567,8 +569,7 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
def search_contract_on_period(cls, employee, period):
|
||||
Contract = Pool().get('staff.contract')
|
||||
contracts = Contract.search([
|
||||
('employee', '=', employee.id), ['AND',
|
||||
['OR', [
|
||||
('employee', '=', employee.id), ['AND', ['OR', [
|
||||
('start_date', '>=', period.start),
|
||||
('end_date', '<=', period.end),
|
||||
('end_date', '!=', None),
|
||||
|
@ -613,7 +614,6 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
else:
|
||||
return last_contract
|
||||
|
||||
|
||||
def get_days(self, start, end):
|
||||
adjust = 1
|
||||
quantity_days = (end - start).days + adjust
|
||||
|
@ -780,14 +780,13 @@ class PayrollGroup(Wizard):
|
|||
'staff_payroll.payroll_group_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Accept', 'open_', 'tryton-ok', default=True),
|
||||
])
|
||||
])
|
||||
open_ = StateTransition()
|
||||
|
||||
def transition_open_(self):
|
||||
pool = Pool()
|
||||
Employee = pool.get('company.employee')
|
||||
Payroll = pool.get('staff.payroll')
|
||||
Contract = pool.get('staff.contract')
|
||||
|
||||
#Remove employees with payroll this period
|
||||
payrolls_period = Payroll.search([
|
||||
|
@ -799,7 +798,6 @@ class PayrollGroup(Wizard):
|
|||
payroll_to_create = []
|
||||
|
||||
for employee in Employee.search(dom_employees):
|
||||
|
||||
start = self.start.period.start
|
||||
end = self.start.period.end
|
||||
contract = Payroll.search_contract_on_period(employee, self.start.period)
|
||||
|
@ -815,7 +813,6 @@ class PayrollGroup(Wizard):
|
|||
cont = 0
|
||||
for payroll in payrolls:
|
||||
cont += 1
|
||||
print(cont)
|
||||
payroll.on_change_period()
|
||||
payroll.set_preliquidation({})
|
||||
if wages:
|
||||
|
@ -824,9 +821,9 @@ class PayrollGroup(Wizard):
|
|||
|
||||
def get_employees_dom(self, employees_w_payroll):
|
||||
dom_employees = [
|
||||
('active', '=', True),
|
||||
('id', 'not in', employees_w_payroll),
|
||||
]
|
||||
('active', '=', True),
|
||||
('id', 'not in', employees_w_payroll),
|
||||
]
|
||||
return dom_employees
|
||||
|
||||
def get_values(self, contract, start_date, end_date):
|
||||
|
@ -848,8 +845,8 @@ class PayrollGroup(Wizard):
|
|||
'description': self.start.description,
|
||||
'date_effective': end_date,
|
||||
'contract': Payroll.search_contract_on_period(
|
||||
employee, self.start.period
|
||||
)
|
||||
employee, self.start.period
|
||||
)
|
||||
}
|
||||
return values
|
||||
|
||||
|
@ -889,8 +886,7 @@ class PayrollRecompute(Wizard):
|
|||
return 'end'
|
||||
|
||||
|
||||
class Move:
|
||||
__metaclass__ = PoolMeta
|
||||
class Move(metaclass=PoolMeta):
|
||||
__name__ = 'account.move'
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=5.0.2
|
||||
version=5.0.3
|
||||
depends:
|
||||
party
|
||||
currency
|
||||
|
|
Loading…
Reference in a new issue