diff --git a/stock_picking_report_valued/__manifest__.py b/stock_picking_report_valued/__manifest__.py index 1ab8755..d739f96 100644 --- a/stock_picking_report_valued/__manifest__.py +++ b/stock_picking_report_valued/__manifest__.py @@ -1,6 +1,6 @@ # Copyright 2014 Pedro M. Baeza - Tecnativa # Copyright 2015 Antonio Espinosa - Tecnativa -# Copyright 2016 Carlos Dauden - Tecnativa +# Copyright 2016-2019 Carlos Dauden - Tecnativa # Copyright 2017 David Vidal - Tecnativa # Copyright 2017 Luis M. Ontalba - Tecnativa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -8,7 +8,7 @@ { "name": "Valued Picking Report", "summary": "Adding Valued Picking on Delivery Slip report", - "version": "11.0.1.0.0", + "version": "11.0.1.0.1", "author": "Tecnativa, " "Odoo Community Association (OCA)", "website": "https://www.tecnativa.com", diff --git a/stock_picking_report_valued/models/stock_picking.py b/stock_picking_report_valued/models/stock_picking.py index da57ddc..77a26e1 100644 --- a/stock_picking_report_valued/models/stock_picking.py +++ b/stock_picking_report_valued/models/stock_picking.py @@ -41,12 +41,38 @@ class StockPicking(models.Model): records...). """ for pick in self: - amount_untaxed = sum(pick.move_line_ids.mapped( - 'sale_price_subtotal')) - amount_tax = sum(pick.move_line_ids.mapped( - 'sale_price_tax')) + sale = pick.sale_id + round_method = sale.company_id.tax_calculation_rounding_method + if round_method == 'round_globally': + amount_untaxed = sum(pick.move_line_ids.mapped( + 'sale_price_subtotal')) + amount_tax = sum(pick.move_line_ids.mapped( + 'sale_price_tax')) + else: + round_curr = sale.currency_id.round + amount_untaxed = amount_tax = 0.0 + for tax_id, tax_group in pick.get_taxes_values().items(): + amount_untaxed += round_curr(tax_group['base']) + amount_tax += round_curr(tax_group['amount']) pick.update({ 'amount_untaxed': amount_untaxed, 'amount_tax': amount_tax, 'amount_total': amount_untaxed + amount_tax, }) + + @api.multi + def get_taxes_values(self): + tax_grouped = {} + for line in self.move_line_ids: + tax = line.sale_line.tax_id + tax_id = tax.id + if tax_id not in tax_grouped: + tax_grouped[tax_id] = { + 'amount': line.sale_price_tax, + 'base': line.sale_price_subtotal, + 'tax': tax, + } + else: + tax_grouped[tax_id]['amount'] += line.sale_price_tax + tax_grouped[tax_id]['base'] += line.sale_price_subtotal + return tax_grouped diff --git a/stock_picking_report_valued/tests/test_stock_picking_valued.py b/stock_picking_report_valued/tests/test_stock_picking_valued.py index 190ec40..99fec2a 100644 --- a/stock_picking_report_valued/tests/test_stock_picking_valued.py +++ b/stock_picking_report_valued/tests/test_stock_picking_valued.py @@ -1,5 +1,6 @@ # Copyright 2017 Tecnativa - David Vidal # Copyright 2017 Tecnativa - Luis M. Ontalba +# Copyright 2019 Tecnativa - Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo.tests import common @@ -10,12 +11,19 @@ class TestStockPickingValued(common.SavepointCase): @classmethod def setUpClass(cls): super(TestStockPickingValued, cls).setUpClass() + company = cls.env.user.company_id cls.tax = cls.env['account.tax'].create({ 'name': 'TAX 15%', 'amount_type': 'percent', 'type_tax_use': 'sale', 'amount': 15.0, }) + cls.tax10 = cls.env['account.tax'].create({ + 'name': 'TAX 10%', + 'amount_type': 'percent', + 'type_tax_use': 'sale', + 'amount': 10.0, + }) cls.product = cls.env['product.product'].create({ 'name': 'Test stuff', 'list_price': 100.0, @@ -31,7 +39,29 @@ class TestStockPickingValued(common.SavepointCase): 'price_unit': 100, 'product_uom_qty': 1, })], - 'company_id': cls.env.user.company_id.id, + 'company_id': company.id, + }) + cls.sale_order2 = cls.env['sale.order'].create({ + 'partner_id': cls.partner.id, + 'order_line': [ + (0, 0, { + 'product_id': cls.product.id, + 'price_unit': 100, + 'product_uom_qty': 1, + }), + (0, 0, { + 'product_id': cls.product.id, + 'price_unit': 100, + 'product_uom_qty': 1, + }), + (0, 0, { + 'product_id': cls.product.id, + 'price_unit': 100, + 'product_uom_qty': 1, + 'tax_id': [(6, 0, cls.tax10.ids)], + }), + ], + 'company_id': company.id, }) cls.sale_order.company_id.tax_calculation_rounding_method = ( 'round_per_line') @@ -66,3 +96,14 @@ class TestStockPickingValued(common.SavepointCase): self.assertEqual(picking.amount_untaxed, 100.0) self.assertEqual(picking.amount_tax, 15.0) self.assertEqual(picking.amount_total, 115.0) + + def test_04_lines_distinct_tax(self): + self.sale_order2.company_id.tax_calculation_rounding_method = ( + 'round_globally') + self.sale_order2.action_confirm() + self.assertTrue(len(self.sale_order2.picking_ids)) + for picking in self.sale_order2.picking_ids: + picking.action_assign() + self.assertEqual(picking.amount_untaxed, 300.0) + self.assertEqual(picking.amount_tax, 40.0) + self.assertEqual(picking.amount_total, 340.0)