[FIX] stock: add SM without scheduled date

If a user adds a new SM to a picking without any scheduled date,
traceback will appear

To reproduce the issue:
1.  create a new picking and remove the scheduled_date.
2.  try to add a new storable product in move lines.

Error: A traceback appears: "TypeError: '>' not supported between
instances of 'datetime.datetime' and 'bool'"

On the picking form, the default SM date is the scheduled date of the
picking:
https://github.com/odoo/odoo/blob/2c3f53d5a0380e7de27977f56f20307ff2bccabf/addons/stock/views/stock_picking_views.xml#L358
Therefore, in the above use case, when triggering the onchange/compute
methods, the field `date` of the SM will not be defined. At some
point, we need to get the forecasted quantities of the SM product
(see the method updated by this commit) and, to do so, we compare
the SM date with `now`. Since this date is `False`, it will lead to the
above traceback

sentry-3979281197

closes odoo/odoo#124352

X-original-commit: e6179a5147a33dc53ce4ffbdace2585f13f18a14
Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
This commit is contained in:
smna-odoo
2023-06-09 09:35:02 +02:00
committed by Adrien Widart (awt)
parent 4a711f24a0
commit db0d943b0f
+1 -1
View File
@@ -480,7 +480,7 @@ Please change the quantity done or the rounding precision of your unit of measur
def key_virtual_available(move, incoming=False):
warehouse_id = move.location_dest_id.warehouse_id.id if incoming else move.location_id.warehouse_id.id
return warehouse_id, max(move.date, now)
return warehouse_id, max(move.date or now, now)
# Prefetch efficiently virtual_available for _is_consuming draft move.
prefetch_virtual_available = defaultdict(set)