[FIX] sale_mrp: fix picking creation issue for bom with kit type

Currently, if the product type is set to 'product' and recurring_invoice is
true, and the product has a bill of materials (BOM) with the type 'kit'
the picking was not created after the first invoice.

Producing steps:
- Create a subscription product with the type set to 'product'
- Create a BOM for that product with the BOM type set to 'kit'
- In the component, add any product with the type 'product'
- Create a sale order with the products that are created and generate an invoice
- Upon creating the next invoice for the subscription product,
  the picking was not being generated.

With this commit, we are ensuring that the picking for subscription products
is now correctly created when generating an invoice.

task-3681597

closes odoo/odoo#163243

X-original-commit: ee15fc0c45f08c1fbef9d9062041ea8ff9bb0f59
Related: odoo/enterprise#61415
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
This commit is contained in:
Gurpreet Singh
2024-04-26 17:17:57 +00:00
parent 76c0b98119
commit e1c623127f
+14 -4
View File
@@ -112,6 +112,19 @@ class SaleOrderLine(models.Model):
components[product] = {'qty': qty, 'uom': to_uom.id}
return components
@api.model
def _get_incoming_outgoing_moves_filter(self):
""" Method to be override: will get incoming moves and outgoing moves.
:return: Dictionary with incoming moves and outgoing moves
:rtype: dict
"""
return {
'incoming_moves': lambda m: m.location_dest_id.usage == 'customer' and \
(not m.origin_returned_move_id or (m.origin_returned_move_id and m.to_refund)),
'outgoing_moves': lambda m: m.location_dest_id.usage != 'customer' and m.to_refund
}
def _get_qty_procurement(self, previous_product_uom_qty=False):
self.ensure_one()
# Specific case when we change the qty on a SO for a kit product.
@@ -120,10 +133,7 @@ class SaleOrderLine(models.Model):
bom = self.env['mrp.bom']._bom_find(self.product_id, bom_type='phantom')[self.product_id]
if bom:
moves = self.move_ids.filtered(lambda r: r.state != 'cancel' and not r.scrapped)
filters = {
'incoming_moves': lambda m: m.location_dest_id.usage == 'customer' and (not m.origin_returned_move_id or (m.origin_returned_move_id and m.to_refund)),
'outgoing_moves': lambda m: m.location_dest_id.usage != 'customer' and m.to_refund
}
filters = self._get_incoming_outgoing_moves_filter()
order_qty = previous_product_uom_qty.get(self.id, 0) if previous_product_uom_qty else self.product_uom_qty
order_qty = self.product_uom._compute_quantity(order_qty, bom.product_uom_id)
qty = moves._compute_kit_quantities(self.product_id, order_qty, bom, filters)