diff --git a/stock_picking_report_valued/models/stock_move_line.py b/stock_picking_report_valued/models/stock_move_line.py index 02e4077..d7b82a3 100644 --- a/stock_picking_report_valued/models/stock_move_line.py +++ b/stock_picking_report_valued/models/stock_move_line.py @@ -4,8 +4,11 @@ # Copyright 2016-2022 Tecnativa - Carlos Dauden # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from functools import partial + from odoo import fields, models from odoo.tools import float_compare +from odoo.tools.misc import formatLang class StockMoveLine(models.Model): @@ -96,3 +99,50 @@ class StockMoveLine(models.Model): "sale_price_unit": valued_line.price_unit, } ) + + def _get_aggregated_product_quantities(self, **kwargs): + result = super()._get_aggregated_product_quantities(**kwargs) + if self.env.context.get("bypass_modification_valued_report"): + return result + result = self._get_aggregated_product_quantities_delivery_price(result) + return result + + def _get_aggregated_product_quantities_delivery_price(self, aggregated_move_lines): + # sale order can have sold products under different prices + # currently lines on stock.picking will consider only first price + # so total on sale.order and stock.picking will differ + # consider riding of aggregating of lines for stock.picking + fmt = partial( + formatLang, + self.with_context(lang=self.picking_id.partner_id.lang).env, + currency_obj=self.picking_id.currency_id, + ) + + for line in aggregated_move_lines: + product = aggregated_move_lines[line]["product"] + uom = aggregated_move_lines[line]["product_uom"] + sml = self._find_sml(product, uom) + qty = aggregated_move_lines[line]["qty_done"] or sml.move_id.product_uom_qty + aggregated_move_lines[line].update( + { + "unit_price": fmt(sml.sale_price_unit), + "tax": ", ".join( + map( + lambda x: (x.description or x.name), + sml.sale_tax_id, + ) + ), + "total": (sml.sale_price_unit * qty), + } + ) + return aggregated_move_lines + + def _find_sml(self, product, uom_name): + line = fields.first( + self.filtered( + lambda sml: sml.product_id == product + and sml.product_uom_id.name == uom_name + ) + ) + + return line diff --git a/stock_picking_report_valued/readme/ROADMAP.rst b/stock_picking_report_valued/readme/ROADMAP.rst index 2ef668b..43dd5ff 100644 --- a/stock_picking_report_valued/readme/ROADMAP.rst +++ b/stock_picking_report_valued/readme/ROADMAP.rst @@ -1 +1,2 @@ * If the picking is not reserved, values aren't computed. +* Add tax printing by group diff --git a/stock_picking_report_valued/report/stock_picking_report_valued.xml b/stock_picking_report_valued/report/stock_picking_report_valued.xml index ae29d14..68c4030 100644 --- a/stock_picking_report_valued/report/stock_picking_report_valued.xml +++ b/stock_picking_report_valued/report/stock_picking_report_valued.xml @@ -6,19 +6,27 @@ expr="//table[@t-if="o.move_line_ids and o.state=='done'"]/thead/tr" position="inside" > - - - Qty Reserved + + + + Qty Reserved + + Unit Price + + Discount + + Subtotal + Taxes - Unit Price - - Discount - - Subtotal - Taxes - @@ -47,34 +55,39 @@ add="or (o.valued and o.sale_id and o.move_line_ids)" separator=" " /> - + --> - - - - - - - - - - - - - - - - -
Untaxed AmountTaxesTotal
- - - - - -
+ + + + + + + + + + + + + + + + + +
Untaxed AmountTaxesTotal
+ + + + + +
+
@@ -84,22 +97,58 @@ inherit_id="stock.stock_report_delivery_has_serial_move_line" > - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + +