[FIX] stock: forecasted take the reservation in account

Add reservation information in the forecasted report.
Also this information is used by the forecasted information in
stock move.

closes odoo/odoo#57814

X-original-commit: 87b16dab35c2326220d5bbd51bb7f07e876352d1
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com>
This commit is contained in:
Rémy Voet (ryv)
2020-09-16 10:21:10 +00:00
parent 8b5603bad0
commit f78f2c8247
2 changed files with 17 additions and 2 deletions
+14 -2
View File
@@ -109,7 +109,7 @@ class ReplenishmentReport(models.AbstractModel):
res['lines'] = self._get_report_lines(product_template_ids, product_variant_ids, wh_location_ids)
return res
def _prepare_report_line(self, quantity, move_out=None, move_in=None, replenishment_filled=True, product=False):
def _prepare_report_line(self, quantity, move_out=None, move_in=None, replenishment_filled=True, product=False, reservation=False):
timezone = self._context.get('tz')
product = product or (move_out.product_id if move_out else move_in.product_id)
is_late = move_out.date < move_in.date if (move_out and move_in) else False
@@ -128,6 +128,7 @@ class ReplenishmentReport(models.AbstractModel):
'quantity': quantity,
'move_out': move_out,
'move_in': move_in,
'reservation': reservation,
}
def _get_report_lines(self, product_template_ids, product_variant_ids, wh_location_ids):
@@ -146,10 +147,21 @@ class ReplenishmentReport(models.AbstractModel):
lines = []
for product in (ins | outs).product_id:
for out in outs_per_product[product.id]:
if out.state not in ('partially_available', 'assigned'):
continue
current = currents[out.product_id.id]
reserved = out.product_uom._compute_quantity(out.reserved_availability, product.uom_id)
currents[product.id] -= reserved
lines.append(self._prepare_report_line(reserved, move_out=out, reservation=True))
for out in outs_per_product[product.id]:
# Reconcile with the current stock.
current = currents[out.product_id.id]
demand = out.product_qty
reserved = 0.0
if out.state in ('partially_available', 'assigned'):
reserved = out.product_uom._compute_quantity(out.reserved_availability, product.uom_id)
demand = out.product_qty - reserved
taken_from_stock = min(demand, current)
if not float_is_zero(taken_from_stock, precision_rounding=product.uom_id.rounding):
currents[product.id] -= taken_from_stock
@@ -117,6 +117,9 @@
class="font-weight-bold" view-type="form"
t-att-res-model="line['document_in']._name"
t-att-res-id="line['document_in'].id"/>
<t t-elif="line['reservation']">
Reserved from stock
</t>
<t t-elif="line['replenishment_filled']">
<t t-if="line['document_out']">Inventory On Hand</t>
<t t-else="">Free Stock</t>