[IMP] sale_stock: refactoring for rental pickings
Refactored _action_launch_stock_rule to create _create_procurement_group. Needed for rental pickings. task 3109952 closes odoo/odoo#135425 Related: odoo/enterprise#47376 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
@@ -272,6 +272,12 @@ class SaleOrderLine(models.Model):
|
||||
'partner_id': self.order_id.partner_shipping_id.id,
|
||||
}
|
||||
|
||||
def _create_procurement(self, product_qty, procurement_uom, values):
|
||||
self.ensure_one()
|
||||
return self.env['procurement.group'].Procurement(
|
||||
self.product_id, product_qty, procurement_uom, self.order_id.partner_shipping_id.property_stock_customer,
|
||||
self.product_id.display_name, self.order_id.name, self.order_id.company_id, values)
|
||||
|
||||
def _action_launch_stock_rule(self, previous_product_uom_qty=False):
|
||||
"""
|
||||
Launch procurement group run method with required/custom fields generated by a
|
||||
@@ -311,10 +317,7 @@ class SaleOrderLine(models.Model):
|
||||
line_uom = line.product_uom
|
||||
quant_uom = line.product_id.uom_id
|
||||
product_qty, procurement_uom = line_uom._adjust_uom_quantities(product_qty, quant_uom)
|
||||
procurements.append(self.env['procurement.group'].Procurement(
|
||||
line.product_id, product_qty, procurement_uom,
|
||||
line.order_id.partner_shipping_id.property_stock_customer,
|
||||
line.product_id.display_name, line.order_id.name, line.order_id.company_id, values))
|
||||
procurements.append(line._create_procurement(product_qty, procurement_uom, values))
|
||||
if procurements:
|
||||
self.env['procurement.group'].run(procurements)
|
||||
|
||||
|
||||
@@ -36,6 +36,22 @@ class StockMove(models.Model):
|
||||
res = super()._get_source_document()
|
||||
return self.sale_line_id.order_id or res
|
||||
|
||||
def _get_sale_order_lines(self):
|
||||
""" Return all possible sale order lines for one or multiple stock moves. """
|
||||
def _get_origin_moves(move):
|
||||
origin_moves = move.move_orig_ids
|
||||
if origin_moves:
|
||||
origin_moves += _get_origin_moves(origin_moves)
|
||||
return origin_moves
|
||||
|
||||
def _get_destination_moves(move):
|
||||
destination_moves = move.move_dest_ids
|
||||
if destination_moves:
|
||||
destination_moves += _get_destination_moves(destination_moves)
|
||||
return destination_moves
|
||||
|
||||
return (self + _get_origin_moves(self) + _get_destination_moves(self)).sale_line_id
|
||||
|
||||
def _assign_picking_post_process(self, new=False):
|
||||
super(StockMove, self)._assign_picking_post_process(new=new)
|
||||
if new:
|
||||
|
||||
Reference in New Issue
Block a user