[IMP] account: non deductible taxes to inventory
Non deductible taxes (ones without an account set), increase the target account of the product. In case of a inventory operation, this means the inventory account. To reflect this stock valuation wise, we need to calculate this incremented values and rely on it during the inventory move price calculation. This commit does exactly that.
This commit is contained in:
@@ -1051,6 +1051,7 @@ class AccountTax(models.Model):
|
||||
RETURN: {
|
||||
'total_excluded': 0.0, # Total without taxes
|
||||
'total_included': 0.0, # Total with taxes
|
||||
'total_void' : 0.0, # Total with those taxes, that don't have an account set
|
||||
'taxes': [{ # One dict for each tax in self and their children
|
||||
'id': int,
|
||||
'name': str,
|
||||
@@ -1094,9 +1095,9 @@ class AccountTax(models.Model):
|
||||
|
||||
base_values = self.env.context.get('base_values')
|
||||
if not base_values:
|
||||
total_excluded = total_included = base = round(price_unit * quantity, prec)
|
||||
total_excluded = total_included = total_void = base = round(price_unit * quantity, prec)
|
||||
else:
|
||||
total_excluded, total_included, base = base_values
|
||||
total_excluded, total_included, total_void, base = base_values
|
||||
|
||||
# Sorting key is mandatory in this case. When no key is provided, sorted() will perform a
|
||||
# search. However, the search method is overridden in account.tax in order to add a domain
|
||||
@@ -1108,11 +1109,12 @@ class AccountTax(models.Model):
|
||||
price_include = self._context.get('force_price_include', tax.price_include)
|
||||
|
||||
if tax.amount_type == 'group':
|
||||
children = tax.children_tax_ids.with_context(base_values=(total_excluded, total_included, base))
|
||||
children = tax.children_tax_ids.with_context(base_values=(total_excluded, total_included, total_void, base))
|
||||
ret = children.compute_all(price_unit, currency, quantity, product, partner)
|
||||
total_excluded = ret['total_excluded']
|
||||
base = ret['base'] if tax.include_base_amount else base
|
||||
total_included = ret['total_included']
|
||||
total_void = ret['total_void']
|
||||
tax_amount = total_included - total_excluded
|
||||
taxes += ret['taxes']
|
||||
continue
|
||||
@@ -1128,6 +1130,10 @@ class AccountTax(models.Model):
|
||||
base -= tax_amount
|
||||
else:
|
||||
total_included += tax_amount
|
||||
# The total_void amount is computed as the sum of total_excluded
|
||||
# with all tax_amount, where tax has an account set
|
||||
if not tax.account_id:
|
||||
total_void += tax_amount
|
||||
|
||||
# Keep base amount used for the current tax
|
||||
tax_base = base
|
||||
@@ -1152,6 +1158,7 @@ class AccountTax(models.Model):
|
||||
'taxes': sorted(taxes, key=lambda k: k['sequence']),
|
||||
'total_excluded': currency.round(total_excluded) if round_total else total_excluded,
|
||||
'total_included': currency.round(total_included) if round_total else total_included,
|
||||
'total_void': currency.round(total_void) if round_total else total_void,
|
||||
'base': base,
|
||||
}
|
||||
|
||||
|
||||
@@ -1730,6 +1730,7 @@ exports.Orderline = Backbone.Model.extend({
|
||||
}
|
||||
var total_excluded = round_pr(price_unit * quantity, currency_rounding);
|
||||
var total_included = total_excluded;
|
||||
var total_void = total_excluded;
|
||||
var base = total_excluded;
|
||||
var taxes_mapped = [];
|
||||
|
||||
@@ -1748,6 +1749,7 @@ exports.Orderline = Backbone.Model.extend({
|
||||
total_excluded = ret.total_excluded;
|
||||
base = ret.total_excluded;
|
||||
total_included = ret.total_included;
|
||||
total_void = ret.total_void;
|
||||
list_taxes = list_taxes.concat(ret.taxes);
|
||||
}
|
||||
else {
|
||||
@@ -1765,6 +1767,9 @@ exports.Orderline = Backbone.Model.extend({
|
||||
if (tax.include_base_amount) {
|
||||
base += tax_amount;
|
||||
}
|
||||
if (!tax.account_id) {
|
||||
total_void += tax_amount;
|
||||
}
|
||||
var data = {
|
||||
id: tax.id,
|
||||
amount: tax_amount,
|
||||
@@ -1777,7 +1782,8 @@ exports.Orderline = Backbone.Model.extend({
|
||||
return {
|
||||
taxes: list_taxes,
|
||||
total_excluded: round_pr(total_excluded, currency_rounding_bak),
|
||||
total_included: round_pr(total_included, currency_rounding_bak)
|
||||
total_included: round_pr(total_included, currency_rounding_bak),
|
||||
total_void: round_pr(total_void, currency_rounding_bak)
|
||||
};
|
||||
},
|
||||
get_all_prices: function(){
|
||||
@@ -1805,6 +1811,7 @@ exports.Orderline = Backbone.Model.extend({
|
||||
return {
|
||||
"priceWithTax": all_taxes.total_included,
|
||||
"priceWithoutTax": all_taxes.total_excluded,
|
||||
"priceSumTaxVoid": all_taxes.total_void,
|
||||
"tax": taxtotal,
|
||||
"taxDetails": taxdetail,
|
||||
};
|
||||
|
||||
@@ -315,7 +315,7 @@ class PurchaseOrderLine(models.Model):
|
||||
if line.taxes_id:
|
||||
price_unit = line.taxes_id.with_context(round=False).compute_all(
|
||||
price_unit, currency=line.order_id.currency_id, quantity=1.0, product=line.product_id, partner=line.order_id.partner_id
|
||||
)['total_excluded']
|
||||
)['total_void']
|
||||
if line.product_uom.id != line.product_id.uom_id.id:
|
||||
price_unit *= line.product_uom.factor / line.product_id.uom_id.factor
|
||||
if order.currency_id != order.company_id.currency_id:
|
||||
|
||||
@@ -42,7 +42,7 @@ class StockMove(models.Model):
|
||||
order = line.order_id
|
||||
price_unit = line.price_unit
|
||||
if line.taxes_id:
|
||||
price_unit = line.taxes_id.with_context(round=False).compute_all(price_unit, currency=line.order_id.currency_id, quantity=1.0)['total_excluded']
|
||||
price_unit = line.taxes_id.with_context(round=False).compute_all(price_unit, currency=line.order_id.currency_id, quantity=1.0)['total_void']
|
||||
if line.product_uom.id != line.product_id.uom_id.id:
|
||||
price_unit *= line.product_uom.factor / line.product_id.uom_id.factor
|
||||
if order.currency_id != order.company_id.currency_id:
|
||||
|
||||
Reference in New Issue
Block a user