From 81ba4dbd623a2af18ca3b585d98b91418d264b93 Mon Sep 17 00:00:00 2001 From: AlexPForgeFlow Date: Wed, 20 Sep 2023 16:21:41 +0200 Subject: [PATCH] [FIX] stock_inventory: fix allowed fields to be written in stock-quants and the case of shared location between several companies --- stock_inventory/models/stock_quant.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stock_inventory/models/stock_quant.py b/stock_inventory/models/stock_quant.py index b53d7d8a1525..bea534f330b6 100644 --- a/stock_inventory/models/stock_quant.py +++ b/stock_inventory/models/stock_quant.py @@ -1,4 +1,4 @@ -from odoo import fields, models +from odoo import _, fields, models class StockQuant(models.Model): @@ -22,15 +22,23 @@ def _apply_inventory(self): [ ("product_id", "=", rec.product_id.id), ("lot_id", "=", rec.lot_id.id), - ("company_id", "=", rec.company_id.id), "|", ("location_id", "=", rec.location_id.id), ("location_dest_id", "=", rec.location_id.id), ], order="create_date asc", + ).filtered( + lambda x: not x.company_id.id + or not rec.company_id.id + or rec.company_id.id == x.company_id.id ) + if len(moves) == 0: + raise ValueError(_("No move lines have been created")) move = moves[len(moves) - 1] adjustment.stock_move_ids |= move move.inventory_adjustment_id = adjustment rec.to_do = False return res + + def _get_inventory_fields_write(self): + return super()._get_inventory_fields_write() + ["to_do"]