From f78f2c82477c93d46292a55b6fa8b63e46d39308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Fri, 11 Sep 2020 15:25:14 +0000 Subject: [PATCH] [FIX] stock: forecasted take the reservation in account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Rémy Voet --- addons/stock/report/report_stock_forecasted.py | 16 ++++++++++++++-- addons/stock/report/report_stock_forecasted.xml | 3 +++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/stock/report/report_stock_forecasted.py b/addons/stock/report/report_stock_forecasted.py index f9ffe29e46c..bb4dcc5c9a6 100644 --- a/addons/stock/report/report_stock_forecasted.py +++ b/addons/stock/report/report_stock_forecasted.py @@ -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 diff --git a/addons/stock/report/report_stock_forecasted.xml b/addons/stock/report/report_stock_forecasted.xml index 0bbe734791b..61748f6c020 100644 --- a/addons/stock/report/report_stock_forecasted.xml +++ b/addons/stock/report/report_stock_forecasted.xml @@ -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"/> + + Reserved from stock + Inventory On Hand Free Stock