[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
This commit is contained in:
qdp-odoo
2016-09-16 11:13:51 +02:00
parent f4fc3985b6
commit 89cbef8540
8 changed files with 12 additions and 18 deletions
@@ -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:
-1
View File
@@ -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)
+4 -9
View File
@@ -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
+1 -1
View File
@@ -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)
@@ -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)
@@ -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()
@@ -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
+2 -2
View File
@@ -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)
return self.env['report'].render('point_of_sale.report_saledetails', data)