diff --git a/addons/account/account.py b/addons/account/account.py index e598d9fce4b..bd3e015f2c7 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2163,6 +2163,13 @@ class account_tax(osv.osv): total += r['amount'] return res + def _fix_tax_included_price(self, cr, uid, price, prod_taxes, line_taxes): + """Subtract tax amount from price when corresponding "price included" taxes do not apply""" + incl_tax = [tax for tax in prod_taxes if tax.id not in line_taxes and tax.price_include] + if incl_tax: + return self._unit_compute_inv(cr, uid, incl_tax, price)[0]['price_unit'] + return price + def _unit_compute_inv(self, cr, uid, taxes, price_unit, product=None, partner=None): taxes = self._applicable(cr, uid, taxes, price_unit, product, partner) res = [] diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 355d1235290..51c815b0998 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -737,7 +737,7 @@ class account_invoice(models.Model): if self.currency_id != company_currency: currency = self.currency_id.with_context(date=self.date_invoice or fields.Date.context_today(self)) line['currency_id'] = currency.id - line['amount_currency'] = line['price'] + line['amount_currency'] = currency.round(line['price']) line['price'] = currency.compute(line['price'], company_currency) else: line['currency_id'] = False diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml index dd99a854135..80e6e7a2249 100644 --- a/addons/account/partner_view.xml +++ b/addons/account/partner_view.xml @@ -23,11 +23,11 @@ - +
- + diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 9cac67f0634..1ac80be885a 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -449,7 +449,7 @@ class pos_session(osv.osv): bank_statement_ids.append(statement_id) values.update({ - 'name': self.pool['ir.sequence'].next_by_code(cr, uid, 'pos.session'), + 'name': self.pool['ir.sequence'].next_by_code(cr, uid, 'pos.session', context=context), 'statement_ids' : [(6, 0, bank_statement_ids)], 'config_id': config_id }) diff --git a/addons/point_of_sale/report/pos_details.py b/addons/point_of_sale/report/pos_details.py index bb784b98a45..005c2cc8d83 100644 --- a/addons/point_of_sale/report/pos_details.py +++ b/addons/point_of_sale/report/pos_details.py @@ -47,7 +47,7 @@ class pos_details(report_sxw.rml_parse): user_ids = form['user_ids'] or self._get_all_users() company_id = user_obj.browse(self.cr, self.uid, self.uid).company_id.id pos_ids = pos_obj.search(self.cr, self.uid, [('date_order','>=',form['date_start'] + ' 00:00:00'),('date_order','<=',form['date_end'] + ' 23:59:59'),('user_id','in',user_ids),('state','in',['done','paid','invoiced']),('company_id','=',company_id)]) - for pos in pos_obj.browse(self.cr, self.uid, pos_ids): + for pos in pos_obj.browse(self.cr, self.uid, pos_ids, context=self.localcontext): for pol in pos.lines: result = { 'code': pol.product_id.default_code, diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index fccebe9e9df..3a977732467 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -1217,6 +1217,7 @@ class purchase_order_line(osv.osv): taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id)) fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes) + price = self.pool['account.tax']._fix_tax_included_price(cr, uid, price, product.supplier_taxes_id, taxes_ids) res['value'].update({'price_unit': price, 'taxes_id': taxes_ids}) return res diff --git a/addons/purchase/tests/__init__.py b/addons/purchase/tests/__init__.py index ce452e2c94e..267ff6a4070 100644 --- a/addons/purchase/tests/__init__.py +++ b/addons/purchase/tests/__init__.py @@ -20,3 +20,4 @@ ############################################################################## from . import test_purchase_to_invoice +from . import test_onchange_product_id diff --git a/addons/purchase/tests/test_onchange_product_id.py b/addons/purchase/tests/test_onchange_product_id.py new file mode 100644 index 00000000000..9abf7f1cb68 --- /dev/null +++ b/addons/purchase/tests/test_onchange_product_id.py @@ -0,0 +1,44 @@ +from openerp.tests.common import TransactionCase + +class TestOnchangeProductId(TransactionCase): + """Test that when an included tax is mapped by a fiscal position, the included tax must be + subtracted to the price of the product. + """ + + def setUp(self): + super(TestOnchangeProductId, self).setUp() + self.fiscal_position_model = self.registry('account.fiscal.position') + self.fiscal_position_tax_model = self.registry('account.fiscal.position.tax') + self.tax_model = self.registry('account.tax') + self.pricelist_model = self.registry('product.pricelist') + self.res_partner_model = self.registry('res.partner') + self.product_tmpl_model = self.registry('product.template') + self.product_model = self.registry('product.product') + self.product_uom_model = self.registry('product.uom') + self.so_line_model = self.registry('purchase.order.line') + + def test_onchange_product_id(self): + cr, uid = self.cr, self.uid + uom_id = self.product_uom_model.search(cr, uid, [('name', '=', 'Unit(s)')])[0] + pricelist = self.pricelist_model.search(cr, uid, [('name', '=', 'Public Pricelist')])[0] + partner_id = self.res_partner_model.create(cr, uid, dict(name="George")) + tax_include_id = self.tax_model.create(cr, uid, dict(name="Include tax", + type='percent', + amount='0.21', + price_include=True)) + tax_exclude_id = self.tax_model.create(cr, uid, dict(name="Exclude tax", + type='percent', + amount='0.00')) + product_tmpl_id = self.product_tmpl_model.create(cr, uid, dict(name="Voiture", + list_price='121', + supplier_taxes_id=[(6, 0, [tax_include_id])])) + product_id = self.product_model.create(cr, uid, dict(product_tmpl_id=product_tmpl_id)) + fp_id = self.fiscal_position_model.create(cr, uid, dict(name="fiscal position", + sequence=1)) + fp_tax_id = self.fiscal_position_tax_model.create(cr, uid, dict(position_id=fp_id, + tax_src_id=tax_include_id, + tax_dest_id=tax_exclude_id)) + res = self.so_line_model.onchange_product_id(cr, uid, [], pricelist, product_id, 1.0, uom_id, partner_id, + fiscal_position_id=fp_id) + + self.assertEquals(100, res['value']['price_unit'], "The included tax must be subtracted to the price") diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 762fe0a70cb..cb1597d5e34 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1052,7 +1052,7 @@ class sale_order_line(osv.osv): date_order=order['date_order'], fiscal_position=order['fiscal_position'][0] if order['fiscal_position'] else False, flag=False, # Force name update - context=context + context=dict(context or {}, company_id=values.get('company_id')) )['value'] if defaults.get('tax_id'): defaults['tax_id'] = [[6, 0, defaults['tax_id']]] @@ -1108,8 +1108,8 @@ class sale_order_line(osv.osv): # The superuser is used by website_sale in order to create a sale order. We need to make # sure we only select the taxes related to the company of the partner. This should only # apply if the partner is linked to a company. - if uid == SUPERUSER_ID and partner.company_id: - taxes = product_obj.taxes_id.filtered(lambda r: r.company_id == partner.company_id) + if uid == SUPERUSER_ID and context.get('company_id'): + taxes = product_obj.taxes_id.filtered(lambda r: r.company_id.id == context['company_id']) else: taxes = product_obj.taxes_id result['tax_id'] = self.pool['account.fiscal.position'].map_tax(cr, uid, fpos, taxes) @@ -1162,6 +1162,8 @@ class sale_order_line(osv.osv): product, qty or 1.0, partner_id, ctx)[pricelist] else: price = Product.price_get(cr, uid, [product], ptype='list_price', context=ctx_product)[product] or False + if update_tax: + price = self.pool['account.tax']._fix_tax_included_price(cr, uid, price, product_obj.taxes_id, result['tax_id']) if context.get('uom_qty_change', False): result, domain = {}, {} result.update({'price_unit': price}) diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 4e054ad1bdc..900dadf999a 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -141,17 +141,17 @@