From d29977ded627acd45fd5f0841a78300e56dd43bb Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Thu, 13 Jun 2019 18:36:28 +0200 Subject: [PATCH 1/3] [FIX] stock_picking_report_valued: division_by_zero when unrelated sale order --- stock_picking_report_valued/__manifest__.py | 2 +- stock_picking_report_valued/models/stock_move_line.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stock_picking_report_valued/__manifest__.py b/stock_picking_report_valued/__manifest__.py index 9f64b9c..deacb9b 100644 --- a/stock_picking_report_valued/__manifest__.py +++ b/stock_picking_report_valued/__manifest__.py @@ -8,7 +8,7 @@ { "name": "Valued Picking Report", "summary": "Adding Valued Picking on Delivery Slip report", - "version": "11.0.1.0.2", + "version": "11.0.1.0.3", "author": "Tecnativa, " "Odoo Community Association (OCA)", "website": "https://www.tecnativa.com", diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py index 64d4ba0..5d28d9b 100644 --- a/stock_picking_report_valued/models/stock_move_line.py +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -63,9 +63,11 @@ class StockMoveLine(models.Model): records...). """ for line in self: + price_unit = ( + line.sale_line.price_subtotal / line.sale_line.product_uom_qty + if line.sale_line.product_uom_qty else 0.0) taxes = line.sale_tax_id.compute_all( - price_unit=line.sale_line.price_subtotal / ( - line.sale_line.product_uom_qty or 0.0), + price_unit=price_unit, currency=line.currency_id, quantity=line.qty_done or line.product_qty, product=line.product_id, From d071ab29fecee1bbb88d9b1a649a4f1c25d55671 Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Thu, 13 Jun 2019 19:05:01 +0200 Subject: [PATCH 2/3] [FIX] stock_picking_report_valued: Improve code --- stock_picking_report_valued/models/stock_move_line.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py index 5d28d9b..92e8143 100644 --- a/stock_picking_report_valued/models/stock_move_line.py +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -63,16 +63,17 @@ class StockMoveLine(models.Model): records...). """ for line in self: + sale_line = line.sale_line price_unit = ( - line.sale_line.price_subtotal / line.sale_line.product_uom_qty - if line.sale_line.product_uom_qty else 0.0) + sale_line.price_subtotal / sale_line.product_uom_qty + if sale_line.product_uom_qty else sale_line.price_reduce) taxes = line.sale_tax_id.compute_all( price_unit=price_unit, currency=line.currency_id, quantity=line.qty_done or line.product_qty, product=line.product_id, - partner=line.sale_line.order_id.partner_shipping_id) - if line.sale_line.company_id.tax_calculation_rounding_method == ( + partner=sale_line.order_id.partner_shipping_id) + if sale_line.company_id.tax_calculation_rounding_method == ( 'round_globally'): price_tax = sum( t.get('amount', 0.0) for t in taxes.get('taxes', [])) From 1dfdeb59ea85944f07a0549e01d0c6bc8e10d4a4 Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Thu, 13 Jun 2019 21:39:18 +0200 Subject: [PATCH 3/3] [FIX] stock_picking_report_valued: Multiple taxes in sale line (WIP) --- .../models/stock_picking.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/stock_picking_report_valued/models/stock_picking.py b/stock_picking_report_valued/models/stock_picking.py index abf9165..0aef97e 100644 --- a/stock_picking_report_valued/models/stock_picking.py +++ b/stock_picking_report_valued/models/stock_picking.py @@ -42,10 +42,11 @@ class StockPicking(models.Model): """ for pick in self: round_curr = pick.sale_id.currency_id.round - amount_untaxed = amount_tax = 0.0 + 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']) + amount_untaxed = sum( + l.sale_price_subtotal for l in pick.move_line_ids) pick.update({ 'amount_untaxed': amount_untaxed, 'amount_tax': amount_tax, @@ -56,15 +57,17 @@ class StockPicking(models.Model): 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 + for tax in line.sale_line.tax_id: + tax_id = tax.id + if tax_id not in tax_grouped: + tax_grouped[tax_id] = { + 'base': line.sale_price_subtotal, + 'tax': tax, + } + else: + tax_grouped[tax_id]['base'] += line.sale_price_subtotal + for tax_id, tax_group in tax_grouped.items(): + tax_grouped[tax_id]['amount'] = tax_group['tax'].compute_all( + tax_group['base'], self.sale_id.currency_id + )['taxes'][0]['amount'] return tax_grouped