From 83572e00ccd5a2055fac07be8984e99dfb4b7b98 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 28 Jun 2017 15:48:03 +0200 Subject: [PATCH] [FIX] point_of_sale: fix included taxes Really apply commit a9ce4ffb225 to POS orders. Since the creation of a POS order in the backend is a feature which nearly not used, we rewrite everything related to onchanges. To avoid breaking the compatibility, the old onchange code is kept. As long as the user doesn't upgrade the module it will be used instead of the new onchange. opw-746827 --- addons/point_of_sale/point_of_sale.py | 36 +++++++++++++-------- addons/point_of_sale/point_of_sale_view.xml | 16 ++++----- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 370e150295d..6eb63c79089 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -1506,6 +1506,22 @@ class pos_order_line(osv.osv): line[2]['tax_ids'] = [(6, 0, [x.id for x in product.taxes_id])] return line + @api.onchange('product_id') + def _onchange_product_id(self): + if not self.product_id: + return + if not self.order_id.pricelist_id: + raise UserError( + _('You have to select a pricelist in the sale form !\n' \ + 'Please set one before choosing a product.')) + + self.tax_ids = self.product_id.taxes_id.filtered(lambda r: not self.company_id or r.company_id == self.company_id) + fpos = self.order_id.fiscal_position_id + tax_ids_after_fiscal_position = fpos.map_tax(self.tax_ids) if fpos else self.tax_ids + price = self.order_id.pricelist_id.price_get( + self.product_id.id, self.qty or 1.0, self.order_id.partner_id.id)[self.order_id.pricelist_id.id] + self.price_unit = self.env['account.tax']._fix_tax_included_price(price, self.product_id.taxes_id, tax_ids_after_fiscal_position) + def onchange_product_id(self, cr, uid, ids, pricelist, product_id, qty=0, partner_id=False, context=None): context = context or {} if not product_id: @@ -1597,20 +1613,14 @@ class pos_order_line(osv.osv): @api.depends('price_unit', 'tax_ids', 'qty', 'discount', 'product_id') def _compute_amount_line_all(self): for line in self: - currency = line.order_id.pricelist_id.currency_id - taxes = line.tax_ids.filtered(lambda tax: tax.company_id.id == line.order_id.company_id.id) - fiscal_position_id = line.order_id.fiscal_position_id - if fiscal_position_id: - taxes = fiscal_position_id.map_tax(taxes) + fpos = line.order_id.fiscal_position_id + tax_ids_after_fiscal_position = fpos.map_tax(line.tax_ids) if fpos else line.tax_ids price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) - line.price_subtotal = line.price_subtotal_incl = price * line.qty - if taxes: - taxes = taxes.compute_all(price, currency, line.qty, product=line.product_id, partner=line.order_id.partner_id or False) - line.price_subtotal = taxes['total_excluded'] - line.price_subtotal_incl = taxes['total_included'] - - line.price_subtotal = currency.round(line.price_subtotal) - line.price_subtotal_incl = currency.round(line.price_subtotal_incl) + taxes = tax_ids_after_fiscal_position.compute_all(price, line.order_id.pricelist_id.currency_id, line.qty, product=line.product_id, partner=line.order_id.partner_id) + line.update({ + 'price_subtotal_incl': taxes['total_included'], + 'price_subtotal': taxes['total_excluded'], + }) # DEPRECATED, REMOVE ME IN v10 def _amount_line_all(self, cr, uid, ids, field_names, arg, context=None): diff --git a/addons/point_of_sale/point_of_sale_view.xml b/addons/point_of_sale/point_of_sale_view.xml index c3e20ee40b1..4450111e5af 100644 --- a/addons/point_of_sale/point_of_sale_view.xml +++ b/addons/point_of_sale/point_of_sale_view.xml @@ -35,10 +35,10 @@ - - - - + + + + @@ -46,10 +46,10 @@
- - - - + + + +