Skip to content

Commit

Permalink
[FIX] stock_picking_report_valued: Wrong taxes amount if round global…
Browse files Browse the repository at this point in the history
…ly (#56)
  • Loading branch information
carlosdauden authored and pedrobaeza committed May 15, 2019
1 parent 8d0c7d8 commit ee563b6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
4 changes: 2 additions & 2 deletions stock_picking_report_valued/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright 2014 Pedro M. Baeza - Tecnativa <pedro.baeza@tecnativa.com>
# Copyright 2015 Antonio Espinosa - Tecnativa <antonio.espinosa@tecnativa.com>
# Copyright 2016 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# Copyright 2016-2019 Carlos Dauden - Tecnativa <carlos.dauden@tecnativa.com>
# Copyright 2017 David Vidal - Tecnativa <david.vidal@tecnativa.com>
# Copyright 2017 Luis M. Ontalba - Tecnativa <luis.martinez@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"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",
Expand Down
34 changes: 30 additions & 4 deletions stock_picking_report_valued/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,38 @@ def _compute_amount_all(self):
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
43 changes: 42 additions & 1 deletion stock_picking_report_valued/tests/test_stock_picking_valued.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -31,7 +39,29 @@ def setUpClass(cls):
'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')
Expand Down Expand Up @@ -66,3 +96,14 @@ def test_03_tax_rounding_method(self):
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)

0 comments on commit ee563b6

Please sign in to comment.