[IMP] stock: propagate orderpoint through moves
Orderpoint reference are only set on the first object that is created from the procurement request. However sometimes we would like to access it from further object or define another behavior if we come from an orderpoint. Now that the we propagate the orderpoint_id, it's important to ignore po line with an orderpoint AND a chained stock move, else the quantities will be counted twice by the orderpoint in a 2 steps receipt scenario Task: 1849912
This commit is contained in:
@@ -60,7 +60,7 @@ class Orderpoint(models.Model):
|
||||
def _quantity_in_progress(self):
|
||||
res = super(Orderpoint, self)._quantity_in_progress()
|
||||
for op in self:
|
||||
for pr in self.env['purchase.requisition'].search([('state','=','draft'),('origin','=',op.name)]):
|
||||
for prline in pr.line_ids.filtered(lambda l: l.product_id.id == op.product_id.id):
|
||||
for pr in self.env['purchase.requisition'].search([('state', '=', 'draft'), ('origin', '=', op.name)]):
|
||||
for prline in pr.line_ids.filtered(lambda l: l.product_id.id == op.product_id.id and not l.move_dest_id):
|
||||
res[op.id] += prline.product_uom_id._compute_quantity(prline.product_qty, op.product_uom, round=False)
|
||||
return res
|
||||
|
||||
@@ -360,7 +360,7 @@ class PurchaseOrderLine(models.Model):
|
||||
'date': self.order_id.date_order,
|
||||
'date_expected': self.date_planned,
|
||||
'location_id': self.order_id.partner_id.property_stock_supplier.id,
|
||||
'location_dest_id': self.orderpoint_id and self.orderpoint_id.location_id.id or self.order_id._get_destination_location(),
|
||||
'location_dest_id': (self.orderpoint_id and not self.move_dest_ids) and self.orderpoint_id.location_id.id or self.order_id._get_destination_location(),
|
||||
'picking_id': picking.id,
|
||||
'partner_id': self.order_id.dest_address_id.id,
|
||||
'move_dest_ids': [(4, x) for x in self.move_dest_ids.ids],
|
||||
@@ -418,5 +418,9 @@ class PurchaseOrderLine(models.Model):
|
||||
args can be merged. If it returns an empty record then a new line will
|
||||
be created.
|
||||
"""
|
||||
lines = self.filtered(lambda l: l.propagate_date == values['propagate_date'] and l.propagate_date_minimum_delta == values['propagate_date_minimum_delta'] and l.propagate_cancel == values['propagate_cancel'] and l.orderpoint_id == values['orderpoint_id'])
|
||||
lines = self.filtered(
|
||||
lambda l: l.propagate_date == values['propagate_date'] and
|
||||
l.propagate_date_minimum_delta == values['propagate_date_minimum_delta'] and
|
||||
l.propagate_cancel == values['propagate_cancel'] and
|
||||
((values['orderpoint_id'] and not values['move_dest_ids']) and l.orderpoint_id == values['orderpoint_id'] or True))
|
||||
return lines and lines[0] or self.env['purchase.order.line']
|
||||
|
||||
@@ -163,7 +163,7 @@ class Orderpoint(models.Model):
|
||||
|
||||
def _quantity_in_progress(self):
|
||||
res = super(Orderpoint, self)._quantity_in_progress()
|
||||
for poline in self.env['purchase.order.line'].search([('state','in',('draft','sent','to approve')),('orderpoint_id','in',self.ids)]):
|
||||
for poline in self.env['purchase.order.line'].search([('state', 'in', ('draft', 'sent', 'to approve')), ('orderpoint_id', 'in', self.ids), ('move_dest_ids', '=', False)]):
|
||||
res[poline.orderpoint_id.id] += poline.product_uom._compute_quantity(poline.product_qty, poline.orderpoint_id.product_uom, round=False)
|
||||
return res
|
||||
|
||||
|
||||
@@ -126,11 +126,20 @@ class StockRule(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_procurements_to_merge_groupby(self, procurement):
|
||||
return procurement.product_id, procurement.product_uom, procurement.values['propagate_date'], procurement.values['propagate_date_minimum_delta'], procurement.values['propagate_cancel']
|
||||
# Do not group procument from different orderpoint. 1. _quantity_in_progress
|
||||
# directly depends from the orderpoint_id on the line. 2. The stock move
|
||||
# generated from the order line has the orderpoint's location as
|
||||
# destination location. In case of move_dest_ids those two points are not
|
||||
# necessary anymore since those values are taken from destination moves.
|
||||
return procurement.product_id, procurement.product_uom, procurement.values['propagate_date'],\
|
||||
procurement.values['propagate_date_minimum_delta'], procurement.values['propagate_cancel'],\
|
||||
(procurement.values.get('orderpoint_id') and not procurement.values.get('move_dest_ids')) and procurement.values['orderpoint_id']
|
||||
|
||||
@api.model
|
||||
def _get_procurements_to_merge_sorted(self, procurement):
|
||||
return procurement.product_id.id, procurement.product_uom.id, procurement.values['propagate_date'], procurement.values['propagate_date_minimum_delta'], procurement.values['propagate_cancel']
|
||||
return procurement.product_id.id, procurement.product_uom.id, procurement.values['propagate_date'],\
|
||||
procurement.values['propagate_date_minimum_delta'], procurement.values['propagate_cancel'],\
|
||||
(procurement.values.get('orderpoint_id') and not procurement.values.get('move_dest_ids')) and procurement.values['orderpoint_id']
|
||||
|
||||
@api.model
|
||||
def _get_procurements_to_merge(self, procurements):
|
||||
|
||||
@@ -236,6 +236,6 @@ class TestPurchaseLeadTime(PurchaseTestCommon):
|
||||
po_line = self.env['purchase.order.line'].search([
|
||||
('product_id', '=', product_1.id),
|
||||
])
|
||||
self.assertEqual(len(po_line), 2, 'the purchase order lines are not merged')
|
||||
self.assertEqual(len(po_line), 2, 'the purchase order lines are merged')
|
||||
self.assertEqual(po_line[0].product_qty, 10, 'the purchase order line has a wrong quantity')
|
||||
self.assertEqual(po_line[1].product_qty, 5, 'the purchase order line has a wrong quantity')
|
||||
|
||||
@@ -174,6 +174,7 @@ class StockMove(models.Model):
|
||||
display_assign_serial = fields.Boolean(compute='_compute_display_assign_serial')
|
||||
next_serial = fields.Char('First SN')
|
||||
next_serial_count = fields.Integer('Number of SN')
|
||||
orderpoint_id = fields.Many2one('stock.warehouse.orderpoint', 'Original Reordering Rule', check_company=True)
|
||||
|
||||
@api.onchange('product_id', 'picking_type_id')
|
||||
def onchange_product(self):
|
||||
@@ -1055,6 +1056,7 @@ class StockMove(models.Model):
|
||||
'route_ids': self.route_ids,
|
||||
'warehouse_id': self.warehouse_id or self.picking_id.picking_type_id.warehouse_id or self.picking_type_id.warehouse_id,
|
||||
'priority': self.priority,
|
||||
'orderpoint_id': self.orderpoint_id,
|
||||
}
|
||||
|
||||
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
|
||||
|
||||
@@ -294,6 +294,7 @@ class StockRule(models.Model):
|
||||
'description_picking': product_id._get_description(self.picking_type_id),
|
||||
'priority': values.get('priority', "1"),
|
||||
'delay_alert': self.delay_alert,
|
||||
'orderpoint_id': values.get('orderpoint_id') and values['orderpoint_id'].id,
|
||||
}
|
||||
for field in self._get_custom_move_fields():
|
||||
if field in values:
|
||||
|
||||
Reference in New Issue
Block a user