From 23ef79f69b1f941fb144e56d7ba405edf41c0d4a Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 2 Sep 2021 08:08:57 +0000 Subject: [PATCH] [IMP] stock: link to source origin in reception report Make it so the (sales order) of a picking is also a clickable link in the reception report. This was done in a flexible way so it should work in theory for any stock.move._get_source_document() record, but it is only applicable to sales orders for now. Part of Task: 2632884 X-original-commit: d8cd091c3b61ac212fe9e92d532af7cefcf315a6 Part-of: odoo/odoo#79408 --- addons/stock/report/report_stock_reception.py | 18 +++++++++++------- addons/stock/report/report_stock_reception.xml | 16 ++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/addons/stock/report/report_stock_reception.py b/addons/stock/report/report_stock_reception.py index a3ad9f58378..f973b033093 100644 --- a/addons/stock/report/report_stock_reception.py +++ b/addons/stock/report/report_stock_reception.py @@ -86,10 +86,12 @@ class ReceptionReport(models.AbstractModel): # show potential moves that can be assigned for product_id, outs in products_to_outs.items(): for out in outs: - # only show pickings or MOs, no SOs - source = out.picking_id if out.picking_id else out._get_source_document() + # we expect len(source) = 2 when picking + origin [e.g. SO] and len() = 1 otherwise [e.g. MO] + source = (out._get_source_document(),) if not source: continue + if out.picking_id and source[0] != out.picking_id: + source = (out.picking_id, source[0]) qty_to_reserve = out.product_qty product_uom = out.product_id.uom_id @@ -114,14 +116,14 @@ class ReceptionReport(models.AbstractModel): break if not float_is_zero(qty_done, precision_rounding=product_uom.rounding): - sources_to_lines[source].append(self._prepare_report_line(qty_done, product_id, out, source, move_ins=self.env['stock.move'].browse(moves_in_ids))) + sources_to_lines[source].append(self._prepare_report_line(qty_done, product_id, out, source[0], move_ins=self.env['stock.move'].browse(moves_in_ids))) # draft qtys can be shown but not assigned qty_expected = product_to_qty_draft.get(product_id, 0) if float_compare(qty_to_reserve, qty_done, precision_rounding=product_uom.rounding) > 0 and\ not float_is_zero(qty_expected, precision_rounding=product_uom.rounding): to_expect = min(qty_expected, qty_to_reserve - qty_done) - sources_to_lines[source].append(self._prepare_report_line(to_expect, product_id, out, source, is_qty_assignable=False)) + sources_to_lines[source].append(self._prepare_report_line(to_expect, product_id, out, source[0], is_qty_assignable=False)) product_to_qty_draft[product_id] -= to_expect # show already assigned moves @@ -135,17 +137,19 @@ class ReceptionReport(models.AbstractModel): # it is possible there are different in moves linked to the same out moves due to batch # => we guess as to which outs correspond to this report... continue - source = out_move.picking_id if out_move.picking_id else out_move._get_source_document() + source = (out_move._get_source_document(),) if not source: continue + if out_move.picking_id and source[0] != out_move.picking_id: + source = (out_move.picking_id, source[0]) qty_assigned = min(total_assigned, out_move.product_qty) sources_to_lines[source].append( - self._prepare_report_line(qty_assigned, product_id, out_move, source, is_assigned=True, move_ins=moves_in)) + self._prepare_report_line(qty_assigned, product_id, out_move, source[0], is_assigned=True, move_ins=moves_in)) # dates aren't auto-formatted when printed in report :( sources_to_formatted_scheduled_date = defaultdict(list) for source, dummy in sources_to_lines.items(): - sources_to_formatted_scheduled_date[source] = self._get_formatted_scheduled_date(source) + sources_to_formatted_scheduled_date[source] = self._get_formatted_scheduled_date(source[0]) return { 'data': data, diff --git a/addons/stock/report/report_stock_reception.xml b/addons/stock/report/report_stock_reception.xml index 21614217410..c11818d9dc6 100644 --- a/addons/stock/report/report_stock_reception.xml +++ b/addons/stock/report/report_stock_reception.xml @@ -62,17 +62,17 @@ - - - - () + + + + () - : + : + t-out="source[0].partner_id.name"/> Expected Delivery: