From 89cbef8540ab08af16b70bea903ec3ddc582f2eb Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Fri, 16 Sep 2016 11:11:45 +0200 Subject: [PATCH] [FIX/REF] account: set default behavior of apply_taxes to False on creation of account.move.line. This allows to import acccount.move.line via csv and provide the field 'tax_ids' (which is needed for the tax statement). This option is now a context's key, replace the key 'dont_apply_taxes' which was now useless --- addons/account/models/account_bank_statement.py | 2 +- addons/account/models/account_invoice.py | 1 - addons/account/models/account_move.py | 13 ++++--------- addons/account/tests/test_tax.py | 2 +- .../account_tax_cash_basis/models/account_move.py | 4 ++-- .../models/account_partial_reconcile.py | 2 +- addons/account_voucher/models/account_voucher.py | 2 +- addons/point_of_sale/models/pos_order.py | 4 ++-- 8 files changed, 12 insertions(+), 18 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index bb440f7a516..9a4e7d7a907 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -951,7 +951,7 @@ class AccountBankStatementLine(models.Model): # Create write-offs for aml_dict in new_aml_dicts: aml_dict['payment_id'] = payment and payment.id or False - aml_obj.with_context(check_move_validity=False).create(aml_dict) + aml_obj.with_context(check_move_validity=False, apply_taxes=True).create(aml_dict) # Create counterpart move lines and reconcile them for aml_dict in counterpart_aml_dicts: diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 439daf7bf33..a73cd59284a 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -863,7 +863,6 @@ class AccountInvoice(models.Model): 'narration': inv.comment, } ctx['company_id'] = inv.company_id.id - ctx['dont_create_taxes'] = True ctx['invoice'] = inv ctx_nolang = ctx.copy() ctx_nolang.pop('lang', None) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 8e4d908b176..2d12c12a4de 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -108,10 +108,6 @@ class AccountMove(models.Model): move.assert_balanced() return move - @api.multi - def copy(self, default=None): - return super(AccountMove, self.with_context(dont_create_taxes=True)).copy(default) - @api.multi def write(self, vals): if 'line_ids' in vals: @@ -992,10 +988,9 @@ class AccountMoveLine(models.Model): #TODO: to check/refactor @api.model - def create(self, vals, apply_taxes=True): - """ :param apply_taxes: set to False if you don't want vals['tax_ids'] to result in the creation of move lines for taxes and eventual - adjustment of the line amount (in case of a tax included in price). This is useful for use cases where you don't want to - apply taxes in the default fashion (eg. taxes). You can also pass 'dont_create_taxes' in context. + def create(self, vals): + """ :context's key apply_taxes: set to True if you want vals['tax_ids'] to result in the creation of move lines for taxes and eventual + adjustment of the line amount (in case of a tax included in price). :context's key `check_move_validity`: check data consistency after move line creation. Eg. set to false to disable verification that the move debit-credit == 0 while creating the move lines composing the move. @@ -1050,7 +1045,7 @@ class AccountMoveLine(models.Model): # Create tax lines tax_lines_vals = [] - if apply_taxes and not context.get('dont_create_taxes') and vals.get('tax_ids'): + if context.get('apply_taxes') and vals.get('tax_ids'): # Get ids from triplets : https://www.odoo.com/documentation/master/reference/orm.html#openerp.models.Model.write tax_ids = [tax['id'] for tax in self.resolve_2many_commands('tax_ids', vals['tax_ids']) if tax.get('id')] # Since create() receives ids instead of recordset, let's just use the old-api bridge diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py index 1eb214cf313..d626f4e20e0 100644 --- a/addons/account/tests/test_tax.py +++ b/addons/account/tests/test_tax.py @@ -120,7 +120,7 @@ class TestTax(AccountTestUsers): })], 'company_id': company_id, } - move = self.env['account.move'].create(vals) + move = self.env['account.move'].with_context(apply_taxes=True).create(vals) aml_fixed_tax = move.line_ids.filtered(lambda l: l.tax_line_id.id == self.fixed_tax.id) diff --git a/addons/account_tax_cash_basis/models/account_move.py b/addons/account_tax_cash_basis/models/account_move.py index 73b99952501..8d25c555daf 100644 --- a/addons/account_tax_cash_basis/models/account_move.py +++ b/addons/account_tax_cash_basis/models/account_move.py @@ -18,7 +18,7 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" @api.model - def create(self, vals, apply_taxes=True): + def create(self, vals): taxes = False if vals.get('tax_line_id'): taxes = [{'use_cash_basis': self.env['account.tax'].browse(vals['tax_line_id']).use_cash_basis}] @@ -26,4 +26,4 @@ class AccountMoveLine(models.Model): taxes = self.env['account.move.line'].resolve_2many_commands('tax_ids', vals['tax_ids']) if taxes and any([tax['use_cash_basis'] for tax in taxes]) and not vals.get('tax_exigible'): vals['tax_exigible'] = False - return super(AccountMoveLine, self).create(vals, apply_taxes=apply_taxes) + return super(AccountMoveLine, self).create(vals) diff --git a/addons/account_tax_cash_basis/models/account_partial_reconcile.py b/addons/account_tax_cash_basis/models/account_partial_reconcile.py index 86b06389516..19ecec4bcb8 100644 --- a/addons/account_tax_cash_basis/models/account_partial_reconcile.py +++ b/addons/account_tax_cash_basis/models/account_partial_reconcile.py @@ -97,7 +97,7 @@ class AccountPartialReconcileCashBasis(models.Model): # probably already sent to the estate. if move_date > self.company_id.period_lock_date: move_vals['date'] = move_date - move = self.env['account.move'].with_context(dont_create_taxes=True).create(move_vals) + move = self.env['account.move'].create(move_vals) # post move move.post() diff --git a/addons/account_voucher/models/account_voucher.py b/addons/account_voucher/models/account_voucher.py index 6fdcf913faf..d621d73dcfa 100644 --- a/addons/account_voucher/models/account_voucher.py +++ b/addons/account_voucher/models/account_voucher.py @@ -259,7 +259,7 @@ class AccountVoucher(models.Model): 'amount_currency': line.price_subtotal if current_currency != company_currency else 0.0, } - self.env['account.move.line'].create(move_line) + self.env['account.move.line'].with_context(apply_taxes=True).create(move_line) return line_total @api.multi diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 95afee9b93d..4b367c4a2b4 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -317,7 +317,7 @@ class PosOrder(models.Model): for value in group_data: all_lines.append((0, 0, value),) if move: # In case no order was changed - move.sudo().with_context(dont_create_taxes=True).write({'line_ids': all_lines}) + move.sudo().write({'line_ids': all_lines}) move.sudo().post() return True @@ -882,4 +882,4 @@ class ReportSaleDetails(models.AbstractModel): date_stop = self.env.context.get('date_stop', False) data = dict(data or {}, date_start=date_start, date_stop=date_stop) data.update(self.get_sale_details(date_start, date_stop, company)) - return self.env['report'].render('point_of_sale.report_saledetails', data) \ No newline at end of file + return self.env['report'].render('point_of_sale.report_saledetails', data)