diff --git a/stock_picking_report_valued_sale_mrp/__manifest__.py b/stock_picking_report_valued_sale_mrp/__manifest__.py index b647ce1..d626354 100644 --- a/stock_picking_report_valued_sale_mrp/__manifest__.py +++ b/stock_picking_report_valued_sale_mrp/__manifest__.py @@ -10,11 +10,6 @@ "author": "Tecnativa, Odoo Community Association (OCA)", "maintainers": ["chienandalu"], "license": "AGPL-3", - "depends": [ - "stock_picking_report_valued", - "sale_mrp", - ], - "data": [ - "report/stock_picking_report_valued.xml", - ], + "depends": ["stock_picking_report_valued", "sale_mrp"], + "data": ["report/stock_picking_report_valued.xml"], } diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move.py b/stock_picking_report_valued_sale_mrp/models/stock_move.py index c81369d..1b8fa3e 100644 --- a/stock_picking_report_valued_sale_mrp/models/stock_move.py +++ b/stock_picking_report_valued_sale_mrp/models/stock_move.py @@ -4,7 +4,7 @@ from odoo import models class StockMove(models.Model): - _inherit = 'stock.move' + _inherit = "stock.move" def _get_components_per_kit(self): """Compute how many kit components were demanded from this line. We @@ -16,13 +16,9 @@ class StockMove(models.Model): return 0 component_demand = sum( sale_line.move_ids.filtered( - lambda x: x.product_id == self.product_id and - not x.origin_returned_move_id and - ( - x.state != "cancel" or ( - x.state == "cancel" and x.backorder_id - ) - ) + lambda x: x.product_id == self.product_id + and not x.origin_returned_move_id + and (x.state != "cancel" or (x.state == "cancel" and x.backorder_id)) ).mapped("product_uom_qty") ) return component_demand / sale_line.product_uom_qty diff --git a/stock_picking_report_valued_sale_mrp/models/stock_move_line.py b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py index 3cf1699..9bf6778 100644 --- a/stock_picking_report_valued_sale_mrp/models/stock_move_line.py +++ b/stock_picking_report_valued_sale_mrp/models/stock_move_line.py @@ -4,7 +4,7 @@ from odoo import api, fields, models class StockMoveLine(models.Model): - _inherit = 'stock.move.line' + _inherit = "stock.move.line" phantom_product_id = fields.Many2one( comodel_name="product.product", @@ -14,20 +14,18 @@ class StockMoveLine(models.Model): readonly=True, ) phantom_line = fields.Boolean( - compute="_compute_sale_order_line_fields", - compute_sudo=True, + compute="_compute_sale_order_line_fields", compute_sudo=True, ) phantom_delivered_qty = fields.Float( - compute="_compute_sale_order_line_fields", - compute_sudo=True, + compute="_compute_sale_order_line_fields", compute_sudo=True, ) @api.depends("sale_line") def _compute_phantom_product_id(self): """Relate every line with its kit product""" for line in self.filtered( - lambda x: x.sale_line and - x.sale_line.product_id._is_phantom_bom()): + lambda x: x.sale_line and x.sale_line.product_id._is_phantom_bom() + ): line.phantom_product_id = line.sale_line.product_id def _compute_sale_order_line_fields(self): @@ -37,8 +35,7 @@ class StockMoveLine(models.Model): super()._compute_sale_order_line_fields() kit_lines = self.filtered("phantom_product_id") for sale_line in kit_lines.mapped("sale_line"): - move_lines = kit_lines.filtered( - lambda x: x.sale_line == sale_line) + move_lines = kit_lines.filtered(lambda x: x.sale_line == sale_line) # Deduct the kit quantity from the first component in the picking. # If the the kit is partially delivered, this could lead to an # unacurate value. @@ -47,42 +44,52 @@ class StockMoveLine(models.Model): continue price_unit = ( sale_line.price_subtotal / sale_line.product_uom_qty - if sale_line.product_uom_qty else sale_line.price_reduce) + if sale_line.product_uom_qty + else sale_line.price_reduce + ) # Compute how many kits were delivered from the components and # the original demand. Note that if the qty is edited in the sale # order this could lead to inconsitencies. components_per_kit = phantom_line.move_id._get_components_per_kit() - phantom_line_qty_done = sum(move_lines.filtered( - lambda x: x.product_id == phantom_line.product_id - ).mapped("qty_done")) + phantom_line_qty_done = sum( + move_lines.filtered( + lambda x: x.product_id == phantom_line.product_id + ).mapped("qty_done") + ) quantity = phantom_line_qty_done / components_per_kit taxes = phantom_line.sale_tax_id.compute_all( price_unit=price_unit, currency=phantom_line.currency_id, quantity=quantity, product=phantom_line.product_id, - partner=sale_line.order_id.partner_shipping_id) + 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', [])) + "round_globally" + ): + price_tax = sum(t.get("amount", 0.0) for t in taxes.get("taxes", [])) else: - price_tax = taxes['total_included'] - taxes['total_excluded'] - phantom_line.update({ - 'sale_tax_description': ', '.join( - t.name or t.description for t in phantom_line.sale_tax_id), - 'sale_price_subtotal': taxes['total_excluded'], - 'sale_price_tax': price_tax, - 'sale_price_total': taxes['total_included'], - 'phantom_line': True, - 'phantom_delivered_qty': quantity, - }) + price_tax = taxes["total_included"] - taxes["total_excluded"] + phantom_line.update( + { + "sale_tax_description": ", ".join( + t.name or t.description for t in phantom_line.sale_tax_id + ), + "sale_price_subtotal": taxes["total_excluded"], + "sale_price_tax": price_tax, + "sale_price_total": taxes["total_included"], + "phantom_line": True, + "phantom_delivered_qty": quantity, + } + ) # Remove the other lines redundant_lines = move_lines[1:] if redundant_lines: - redundant_lines.update({ - 'sale_tax_description': '', - 'sale_price_subtotal': 0, - 'sale_price_tax': 0, - 'sale_price_total': 0, - }) + redundant_lines.update( + { + "sale_tax_description": "", + "sale_price_subtotal": 0, + "sale_price_tax": 0, + "sale_price_total": 0, + } + ) diff --git a/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml index 16b3258..b66f4c9 100644 --- a/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml +++ b/stock_picking_report_valued_sale_mrp/report/stock_picking_report_valued.xml @@ -1,48 +1,78 @@ - + -