From f032e11202e059eef737b892a725a7348f7f1e56 Mon Sep 17 00:00:00 2001 From: Serpent Consulting Services Date: Fri, 4 Nov 2011 13:57:55 +0530 Subject: [PATCH] [FIX] Hr_payroll_account : System should check the existence of accounts configured in expense journal prior to validation of payslip lp bug: https://launchpad.net/bugs/885663 fixed bzr revid: support@serpentcs.com-20111104082755-xro8bmrnufwhbe3b --- .../hr_payroll_account/hr_payroll_account.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/addons/hr_payroll_account/hr_payroll_account.py b/addons/hr_payroll_account/hr_payroll_account.py index 75a49c5a2a6..684289c9737 100644 --- a/addons/hr_payroll_account/hr_payroll_account.py +++ b/addons/hr_payroll_account/hr_payroll_account.py @@ -95,7 +95,10 @@ class hr_payslip(osv.osv): partner_id = False debit_account_id = line.salary_rule_id.account_debit.id credit_account_id = line.salary_rule_id.account_credit.id - debit_line = (0, 0, { + + if debit_account_id: + + debit_line = (0, 0, { 'name': line.name, 'date': timenow, 'partner_id': partner_id, @@ -108,7 +111,12 @@ class hr_payslip(osv.osv): 'tax_code_id': line.salary_rule_id.account_tax_id and line.salary_rule_id.account_tax_id.id or False, 'tax_amount': line.salary_rule_id.account_tax_id and amt or 0.0, }) - credit_line = (0, 0, { + line_ids.append(debit_line) + debit_sum += debit_line[2]['debit'] - debit_line[2]['credit'] + + if credit_account_id: + + credit_line = (0, 0, { 'name': line.name, 'date': timenow, 'partner_id': partner_id, @@ -121,38 +129,40 @@ class hr_payslip(osv.osv): 'tax_code_id': line.salary_rule_id.account_tax_id and line.salary_rule_id.account_tax_id.id or False, 'tax_amount': line.salary_rule_id.account_tax_id and amt or 0.0, }) - if debit_account_id: - line_ids.append(debit_line) - debit_sum += debit_line[2]['debit'] - debit_line[2]['credit'] - if credit_account_id: line_ids.append(credit_line) credit_sum += credit_line[2]['credit'] - credit_line[2]['debit'] if debit_sum > credit_sum: + acc_id = slip.journal_id.default_credit_account_id.id + if not acc_id: + raise osv.except_osv(_('Configuration Error!'),_('The Expense Journal "%s" has not properly configured the Credit Account!')%(slip.journal_id.name)) adjust_credit = (0, 0, { 'name': _('Adjustment Entry'), 'date': timenow, 'partner_id': partner_id, - 'account_id': slip.journal_id.default_credit_account_id.id, + 'account_id': acc_id, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'debit': 0.0, 'credit': debit_sum - credit_sum, }) line_ids.append(adjust_credit) + elif debit_sum < credit_sum: + acc_id = slip.journal_id.default_debit_account_id.id + if not acc_id: + raise osv.except_osv(_('Configuration Error!'),_('The Expense Journal "%s" has not properly configured the Debit Account!')%(slip.journal_id.name)) adjust_debit = (0, 0, { 'name': _('Adjustment Entry'), 'date': timenow, 'partner_id': partner_id, - 'account_id': slip.journal_id.default_debit_account_id.id, + 'account_id': acc_id, 'journal_id': slip.journal_id.id, 'period_id': period_id, 'debit': credit_sum - debit_sum, 'credit': 0.0, }) line_ids.append(adjust_debit) - move.update({'line_id': line_ids}) move_id = move_pool.create(cr, uid, move, context=context) self.write(cr, uid, [slip.id], {'move_id': move_id}, context=context)