diff --git a/stock_account_product_run_fifo_hook/model/__init__.py b/stock_account_product_run_fifo_hook/model/__init__.py index 9649db77a159..3e46e947420a 100644 --- a/stock_account_product_run_fifo_hook/model/__init__.py +++ b/stock_account_product_run_fifo_hook/model/__init__.py @@ -1 +1,2 @@ from . import product +from . import stock_valuation_layer diff --git a/stock_account_product_run_fifo_hook/model/stock_valuation_layer.py b/stock_account_product_run_fifo_hook/model/stock_valuation_layer.py new file mode 100644 index 000000000000..9b55fe5f194f --- /dev/null +++ b/stock_account_product_run_fifo_hook/model/stock_valuation_layer.py @@ -0,0 +1,20 @@ +# Copyright 2024 ForgeFlow, S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from odoo import api, models + + +class StockValuationLayer(models.Model): + _inherit = "stock.valuation.layer" + + @api.model_create_multi + def create(self, values): + if any("taken_data" in val.keys() for val in values): + taken_data = [ + "taken_data" in val.keys() and val.pop("taken_data") or {} + for val in values + ] + return super( + StockValuationLayer, self.with_context(taken_data=taken_data) + ).create(values) + else: + return super().create(values) diff --git a/stock_valuation_layer_usage/models/stock_valuation_layer.py b/stock_valuation_layer_usage/models/stock_valuation_layer.py index bded38c22b14..ff868269f42c 100644 --- a/stock_valuation_layer_usage/models/stock_valuation_layer.py +++ b/stock_valuation_layer_usage/models/stock_valuation_layer.py @@ -81,8 +81,8 @@ def _process_taken_data(self, taken_data, rec): def create(self, values): recs = self.browse() for val in values: - taken_data = "taken_data" in val.keys() and val.pop("taken_data") or {} - rec = super(StockValuationLayer, self).create(val) + rec = super(StockValuationLayer, self).create([val]) + taken_data = rec.env.context.get("taken_data", [{}])[0] # There are cases in which the transformation # comes from a return process, # such as sales returns or production unbuilds.