From f61339b82cd6993f00a91149fb5dca7a2bfb8ab1 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Fri, 11 Jul 2014 17:15:34 +0200 Subject: [PATCH] [FIX] account, bank statement reconciliation: fixed huge bugs when using tax with several children or when debit/credit are 0 but some amounts have to be put in a tax code + improved usability by adding domains where needed --- addons/account/account_bank_statement.py | 2 ++ addons/account/account_move_line.py | 35 ++++++++++++------- addons/account/account_view.xml | 4 +-- .../account/static/src/js/account_widgets.js | 33 ++++++++++------- 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 98e80f895f4..65dae8a2cc1 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -736,6 +736,8 @@ class account_bank_statement_line(osv.osv): st_line_currency_rate = st_line.currency_id and statement_currency.id == company_currency.id and (st_line.amount_currency / st_line.amount) or False to_create = [] for mv_line_dict in mv_line_dicts: + if mv_line_dict.get('is_tax_line'): + continue mv_line_dict['ref'] = move_name mv_line_dict['move_id'] = move_id mv_line_dict['period_id'] = st_line.statement_id.period_id.id diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cdcf0190f46..776111613ec 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -1230,35 +1230,43 @@ class account_move_line(osv.osv): if vals.get('account_tax_id', False): tax_id = tax_obj.browse(cr, uid, vals['account_tax_id']) total = vals['debit'] - vals['credit'] - if journal.type in ('purchase_refund', 'sale_refund'): + base_code = 'base_code_id' + tax_code = 'tax_code_id' + account_id = 'account_collected_id' + base_sign = 'base_sign' + tax_sign = 'tax_sign' + if journal.type in ('purchase_refund', 'sale_refund') or (journal.type in ('cash', 'bank') and total < 0): base_code = 'ref_base_code_id' tax_code = 'ref_tax_code_id' account_id = 'account_paid_id' base_sign = 'ref_base_sign' tax_sign = 'ref_tax_sign' - else: - base_code = 'base_code_id' - tax_code = 'tax_code_id' - account_id = 'account_collected_id' - base_sign = 'base_sign' - tax_sign = 'tax_sign' tmp_cnt = 0 - for tax in tax_obj.compute_all(cr, uid, [tax_id], total, 1.00, force_excluded=True).get('taxes'): + for tax in tax_obj.compute_all(cr, uid, [tax_id], total, 1.00, force_excluded=False).get('taxes'): #create the base movement if tmp_cnt == 0: if tax[base_code]: tmp_cnt += 1 - self.write(cr, uid,[result], { + if tax_id.price_include: + total = tax['price_unit'] + newvals = { 'tax_code_id': tax[base_code], - 'tax_amount': tax[base_sign] * abs(total) - }) + 'tax_amount': tax[base_sign] * abs(total), + } + if tax_id.price_include: + if tax['price_unit'] < 0: + newvals['credit'] = abs(tax['price_unit']) + else: + newvals['debit'] = tax['price_unit'] + self.write(cr, uid, [result], newvals, context=context) else: data = { 'move_id': vals['move_id'], 'name': tools.ustr(vals['name'] or '') + ' ' + tools.ustr(tax['name'] or ''), 'date': vals['date'], - 'partner_id': vals.get('partner_id',False), - 'ref': vals.get('ref',False), + 'partner_id': vals.get('partner_id', False), + 'ref': vals.get('ref', False), + 'statement_id': vals.get('statement_id', False), 'account_tax_id': False, 'tax_code_id': tax[base_code], 'tax_amount': tax[base_sign] * abs(total), @@ -1275,6 +1283,7 @@ class account_move_line(osv.osv): 'date': vals['date'], 'partner_id': vals.get('partner_id',False), 'ref': vals.get('ref',False), + 'statement_id': vals.get('statement_id', False), 'account_tax_id': False, 'tax_code_id': tax[tax_code], 'tax_amount': tax[tax_sign] * abs(tax['amount']), diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 5e80bfdadfe..ceb0d44507b 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -702,9 +702,9 @@ - + - + diff --git a/addons/account/static/src/js/account_widgets.js b/addons/account/static/src/js/account_widgets.js index c60bf4122d6..3b04058c33f 100644 --- a/addons/account/static/src/js/account_widgets.js +++ b/addons/account/static/src/js/account_widgets.js @@ -53,7 +53,7 @@ openerp.account = function (instance) { relation: "account.account", string: _t("Account"), type: "many2one", - domain: [['type','!=','view']], + domain: [['type','not in',['view', 'closed', 'consolidation']]], }, }, label: { @@ -81,6 +81,7 @@ openerp.account = function (instance) { relation: "account.tax", string: _t("Tax"), type: "many2one", + domain: [['type_tax_use','in',['purchase', 'all']], ['parent_id', '=', false]], }, }, amount: { @@ -1149,10 +1150,17 @@ openerp.account = function (instance) { deferred_tax = $.when(self.model_tax .call("compute_for_bank_reconciliation", [self.tax_id_field.get("value"), amount])) .then(function(data){ - var tax = data.taxes[0]; - var tax_account_id = (amount > 0 ? tax.account_collected_id : tax.account_paid_id) + line_created_being_edited[0].amount_with_tax = line_created_being_edited[0].amount; line_created_being_edited[0].amount = (data.total.toFixed(3) === amount.toFixed(3) ? amount : data.total); - line_created_being_edited[1] = {id: line_created_being_edited[0].id, account_id: tax_account_id, account_num: self.map_account_id_code[tax_account_id], label: tax.name, amount: tax.amount, no_remove_action: true, currency_id: self.st_line.currency_id}; + var current_line_cursor = 1; + $.each(data.taxes, function(index, tax){ + if (tax.amount !== 0.0) { + var tax_account_id = (amount > 0 ? tax.account_collected_id : tax.account_paid_id) + tax_account_id = tax_account_id !== false ? tax_account_id: line_created_being_edited[0].account_id + line_created_being_edited[current_line_cursor] = {id: line_created_being_edited[0].id, account_id: tax_account_id, account_num: self.map_account_id_code[tax_account_id], label: tax.name, amount: tax.amount, no_remove_action: true, currency_id: self.st_line.currency_id, is_tax_line: true}; + current_line_cursor = current_line_cursor + 1; + }; + }); } ); } else { @@ -1164,10 +1172,10 @@ openerp.account = function (instance) { $.when(deferred_tax).then(function(){ // Format amounts - if (line_created_being_edited[0].amount) - line_created_being_edited[0].amount_str = self.formatCurrency(Math.abs(line_created_being_edited[0].amount), line_created_being_edited[0].currency_id); - if (line_created_being_edited[1] && line_created_being_edited[1].amount) - line_created_being_edited[1].amount_str = self.formatCurrency(Math.abs(line_created_being_edited[1].amount), line_created_being_edited[0].currency_id); + $.each(line_created_being_edited, function(index, val) { + if (val.amount) + line_created_being_edited[index].amount_str = self.formatCurrency(Math.abs(val.amount), val.currency_id); + }); self.set("line_created_being_edited", line_created_being_edited); self.createdLinesChanged(); // TODO For some reason, previous line doesn't trigger change handler }); @@ -1318,13 +1326,14 @@ openerp.account = function (instance) { // idem prepareCreatedMoveLineForPersisting: function(line) { var dict = {}; - if (dict['account_id'] === undefined) dict['account_id'] = line.account_id; dict['name'] = line.label; - if (line.amount > 0) dict['credit'] = line.amount; - if (line.amount < 0) dict['debit'] = -1*line.amount; - if (line.tax_id) dict['tax_code_id'] = line.tax_id; + var amount = line.tax_id ? line.amount_with_tax: line.amount; + if (amount > 0) dict['credit'] = amount; + if (amount < 0) dict['debit'] = -1 * amount; + if (line.tax_id) dict['account_tax_id'] = line.tax_id; + if (line.is_tax_line) dict['is_tax_line'] = line.is_tax_line; if (line.analytic_account_id) dict['analytic_account_id'] = line.analytic_account_id; return dict;