From 9e6f342e06e73c723d0dc194875d5ac8f014076e Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 13 Aug 2019 12:54:58 +0000 Subject: [PATCH] [FIX] {purchase,sale}_stock: Not possible to see a SN on an other company Steps to reproduce the bug: - Let's consider two company C1 and C2 and a user U allowed for this two companies - Create a storable product P tracked by serial number - Create a PO in C1 with P and deliver it with a serial number SN - Go to Inventory>Master data>Lots/Serial Numbers - Change your current company to C2 - Click on SN Bug: An access rights error was raised because the system tried to compute SO and PO linked to SN with the moves of all the companies. So the record rule "stock_move multi-company" was raised. opw-2049093 closes #35694 Signed-off-by: Nicolas Lempereur (nle) --- addons/purchase_stock/models/stock.py | 3 ++- addons/sale_stock/models/stock.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/stock.py b/addons/purchase_stock/models/stock.py index 15f2ecee538..73e551344e3 100644 --- a/addons/purchase_stock/models/stock.py +++ b/addons/purchase_stock/models/stock.py @@ -210,7 +210,8 @@ class ProductionLot(models.Model): stock_moves = self.env['stock.move.line'].search([ ('lot_id', '=', lot.id), ('state', '=', 'done') - ]).mapped('move_id').filtered( + ]).mapped('move_id') + stock_moves = stock_moves.search([('id', 'in', stock_moves.ids)]).filtered( lambda move: move.picking_id.location_id.usage == 'supplier' and move.state == 'done') lot.purchase_order_ids = stock_moves.mapped('purchase_line_id.order_id') lot.purchase_order_count = len(lot.purchase_order_ids) diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index f622c61820e..a346b815d20 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -120,7 +120,8 @@ class ProductionLot(models.Model): stock_moves = self.env['stock.move.line'].search([ ('lot_id', '=', lot.id), ('state', '=', 'done') - ]).mapped('move_id').filtered( + ]).mapped('move_id') + stock_moves = stock_moves.search([('id', 'in', stock_moves.ids)]).filtered( lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done') lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id') lot.sale_order_count = len(lot.sale_order_ids)