Add minor fixes, indentation, remove comments

This commit is contained in:
Oscar Alvarez 2020-11-03 22:37:03 -05:00
parent 5132753f99
commit 5994a58db8
2 changed files with 83 additions and 87 deletions

View file

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

View file

@ -1,5 +1,5 @@
[tryton] [tryton]
version=5.0.2 version=5.0.3
depends: depends:
party party
currency currency