fix in get line for move
This commit is contained in:
parent
634b72de45
commit
9b7921a774
87
payroll.py
87
payroll.py
|
@ -255,8 +255,9 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
@ModelView.button
|
||||
@Workflow.transition('posted')
|
||||
def post(cls, records):
|
||||
wage_dict = cls.create_cache_wage_types()
|
||||
for payroll in records:
|
||||
payroll.create_move()
|
||||
payroll.create_move(wage_dict)
|
||||
|
||||
@fields.depends('start', 'end')
|
||||
def on_change_start(self):
|
||||
|
@ -311,14 +312,14 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
|
||||
return salary_full
|
||||
|
||||
def create_move(self):
|
||||
def create_move(self, wage_dict):
|
||||
pool = Pool()
|
||||
Move = pool.get('account.move')
|
||||
Period = pool.get('account.period')
|
||||
if self.move:
|
||||
return
|
||||
period_id = Period.find(self.company.id, date=self.date_effective)
|
||||
move_lines = self.get_moves_lines()
|
||||
move_lines = self.get_moves_lines(wage_dict)
|
||||
move, = Move.create([{
|
||||
'journal': self.journal.id,
|
||||
'origin': str(self),
|
||||
|
@ -331,7 +332,7 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
self.write([self], {'move': move.id})
|
||||
Move.post([self.move])
|
||||
|
||||
def get_moves_lines(self):
|
||||
def get_moves_lines(self, wage_dict):
|
||||
lines_moves = {}
|
||||
mandatory_wages = dict([(m.wage_type.id, m.party)
|
||||
for m in self.employee.mandatory_wages])
|
||||
|
@ -342,23 +343,25 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
entity_in_line = configuration.expense_contribution_entity
|
||||
debit_acc2 = None
|
||||
attr_getter = attrgetter(
|
||||
'amount', 'party', 'amount_60_40', 'wage_type',
|
||||
'wage_type.definition', 'wage_type.account_60_40',
|
||||
'wage_type.debit_account', 'wage_type.credit_account',
|
||||
'wage_type.expense_formula'
|
||||
'amount', 'party', 'amount_60_40', 'wage_type.id'
|
||||
)
|
||||
for line in self.lines:
|
||||
amount, party, amount_60_40, wage_type, definition, account_60_40, debit_acc, credit_acc, expense_for = attr_getter(line)
|
||||
amount, party, amount_60_40, wage_type = attr_getter(line)
|
||||
wage_type_= wage_dict[wage_type]
|
||||
definition = wage_type_['definition']
|
||||
account_60_40 = wage_type_['account_60_40.']
|
||||
debit_acc = wage_type_['debit_account.']
|
||||
credit_acc = wage_type_['credit_account.']
|
||||
expense_for = wage_type_['expense_formula']
|
||||
if amount <= 0 or not wage_type:
|
||||
continue
|
||||
try:
|
||||
party_id = party.id
|
||||
except:
|
||||
party_id = None
|
||||
wage_type_id = wage_type.id
|
||||
if not party_id:
|
||||
if mandatory_wages.get(wage_type_id):
|
||||
party_id = mandatory_wages[wage_type_id].id
|
||||
if mandatory_wages.get(wage_type):
|
||||
party_id = mandatory_wages[wage_type].id
|
||||
else:
|
||||
party_id = employee_id
|
||||
|
||||
|
@ -366,7 +369,7 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
# if not line.wage_type:
|
||||
# continue
|
||||
if expense_for:
|
||||
expense = line.get_expense_amount()
|
||||
expense = line.get_expense_amount(wage_type_)
|
||||
|
||||
if definition == 'payment':
|
||||
amount_debit = amount + expense
|
||||
|
@ -383,37 +386,37 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
amount_credit = amount + expense
|
||||
# debit_acc = line.wage_type.debit_account
|
||||
|
||||
try:
|
||||
if True:
|
||||
if debit_acc and amount_debit > _ZERO:
|
||||
if definition == 'discount':
|
||||
amount_debit = amount_debit * (-1)
|
||||
if debit_acc.id not in lines_moves.keys():
|
||||
if debit_acc['id'] not in lines_moves.keys():
|
||||
if entity_in_line:
|
||||
p = party_id
|
||||
else:
|
||||
p = employee_id
|
||||
|
||||
lines_moves[debit_acc.id] = {
|
||||
lines_moves[debit_acc['id']] = {
|
||||
employee_id: line.get_move_line(
|
||||
debit_acc, p,
|
||||
('debit', amount_debit)
|
||||
)}
|
||||
else:
|
||||
line.update_move_line(
|
||||
lines_moves[debit_acc.id][employee_id],
|
||||
lines_moves[debit_acc['id']][employee_id],
|
||||
{'debit': amount_debit, 'credit': _ZERO}
|
||||
)
|
||||
|
||||
if debit_acc2:
|
||||
if debit_acc2.id not in lines_moves.keys():
|
||||
lines_moves[debit_acc2.id] = {
|
||||
if debit_acc2['id'] not in lines_moves.keys():
|
||||
lines_moves[debit_acc2['id']] = {
|
||||
employee_id: line.get_move_line(
|
||||
debit_acc2, party_id,
|
||||
('debit', amount_debit2)
|
||||
)}
|
||||
else:
|
||||
line.update_move_line(
|
||||
lines_moves[debit_acc2.id][employee_id],
|
||||
lines_moves[debit_acc2['id']][employee_id],
|
||||
{'debit': amount_debit, 'credit': _ZERO}
|
||||
)
|
||||
|
||||
|
@ -421,16 +424,16 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
if amount_credit > _ZERO:
|
||||
line_credit_ready = False
|
||||
if credit_acc:
|
||||
if credit_acc.id not in lines_moves.keys():
|
||||
lines_moves[credit_acc.id] = {
|
||||
if credit_acc['id'] not in lines_moves.keys():
|
||||
lines_moves[credit_acc['id']] = {
|
||||
party_id: line.get_move_line(
|
||||
credit_acc, party_id, ('credit',
|
||||
amount_credit)
|
||||
)}
|
||||
line_credit_ready = True
|
||||
else:
|
||||
if party_id not in lines_moves[credit_acc.id].keys():
|
||||
lines_moves[credit_acc.id].update({
|
||||
if party_id not in lines_moves[credit_acc['id']].keys():
|
||||
lines_moves[credit_acc['id']].update({
|
||||
party_id: line.get_move_line(
|
||||
credit_acc, party_id, (
|
||||
'credit', amount_credit)
|
||||
|
@ -438,23 +441,24 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
})
|
||||
line_credit_ready = True
|
||||
if definition != 'payment':
|
||||
deduction_acc = wage_type.deduction_account
|
||||
deduction_acc = wage_type_['deduction_account.']
|
||||
if deduction_acc:
|
||||
if deduction_acc.id not in lines_moves.keys():
|
||||
lines_moves[deduction_acc.id] = {
|
||||
if deduction_acc['id'] not in lines_moves.keys():
|
||||
lines_moves[deduction_acc['id']] = {
|
||||
employee_id: line.get_move_line(
|
||||
deduction_acc, employee_id, (
|
||||
'credit', -amount),
|
||||
)}
|
||||
line_credit_ready = True
|
||||
else:
|
||||
lines_moves[deduction_acc.id][employee_id]['credit'] -= amount
|
||||
lines_moves[deduction_acc['id']][employee_id]['credit'] -= amount
|
||||
|
||||
if credit_acc and not line_credit_ready:
|
||||
lines_moves[credit_acc.id][party_id]['credit'] += amount_credit
|
||||
except Exception as e:
|
||||
raise WageTypeValidationError(
|
||||
gettext('staff_payroll.bad_configuration_of_wage_type', wage=wage_type.name))
|
||||
lines_moves[credit_acc['id']][party_id]['credit'] += amount_credit
|
||||
# except Exception as e:
|
||||
|
||||
# raise WageTypeValidationError(
|
||||
# gettext('staff_payroll.bad_configuration_of_wage_type', wage=wage_type_['name']))
|
||||
result = []
|
||||
for r in lines_moves.values():
|
||||
_line = list(r.values())
|
||||
|
@ -521,7 +525,9 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
'expense_formula', 'uom', 'default_quantity', 'type_concept',
|
||||
'salary_constitute', 'receipt', 'concepts_salary',
|
||||
'contract_finish', 'limit_days', 'month_application',
|
||||
'minimal_amount', 'adjust_days_worked', 'round_amounts'
|
||||
'minimal_amount', 'adjust_days_worked', 'round_amounts',
|
||||
'debit_account.name', 'credit_account.name',
|
||||
'deduction_account.name', 'account_60_40.name'
|
||||
]
|
||||
wages = Wage.search_read([], fields_names=fields_names)
|
||||
return {w['id']: w for w in wages}
|
||||
|
@ -591,7 +597,8 @@ class Payroll(Workflow, ModelSQL, ModelView):
|
|||
if discount:
|
||||
quantity -= discount
|
||||
else:
|
||||
quantity = extras.get(wage_name, 0)
|
||||
extra_key = wage_name.split(' ')[0]
|
||||
quantity = extras.get(extra_key, 0)
|
||||
|
||||
return quantity
|
||||
|
||||
|
@ -799,10 +806,10 @@ class PayrollLine(ModelSQL, ModelView):
|
|||
credit = amount[1]
|
||||
|
||||
res = {
|
||||
'description': account.name,
|
||||
'description': account['name'],
|
||||
'debit': debit,
|
||||
'credit': credit,
|
||||
'account': account.id,
|
||||
'account': account['id'],
|
||||
'party': party_id,
|
||||
}
|
||||
return res
|
||||
|
@ -815,12 +822,12 @@ class PayrollLine(ModelSQL, ModelView):
|
|||
move_line['credit'] += values['credit']
|
||||
return move_line
|
||||
|
||||
def get_expense_amount(self):
|
||||
def get_expense_amount(self, wage_type):
|
||||
expense = 0
|
||||
wage_type = self.wage_type
|
||||
if wage_type.expense_formula:
|
||||
wage_type_ = self.wage_type
|
||||
if wage_type['expense_formula']:
|
||||
salary_args = self.payroll.get_salary_full(wage_type)
|
||||
expense = wage_type.compute_expense(salary_args, wage_type.expense_formula)
|
||||
expense = wage_type_.compute_expense(wage_type['expense_formula'], salary_args)
|
||||
return expense
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue