From fe2ac11e8e75fbeb82df9eb946f396f30a0ba829 Mon Sep 17 00:00:00 2001 From: twalter-c2c Date: Tue, 27 Aug 2024 16:00:49 +0200 Subject: [PATCH] stock_average_daily_sale: Set default root location on WH Set default average_daily_sale_root_location on WH create. Default stock location of the new WH is used for this purpose --- .../models/stock_warehouse.py | 16 ++++++++++++++-- .../views/stock_warehouse.xml | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/stock_average_daily_sale/models/stock_warehouse.py b/stock_average_daily_sale/models/stock_warehouse.py index 2d34710..26d8dec 100644 --- a/stock_average_daily_sale/models/stock_warehouse.py +++ b/stock_average_daily_sale/models/stock_warehouse.py @@ -4,7 +4,6 @@ from odoo import api, fields, models class StockWarehouse(models.Model): - _inherit = "stock.warehouse" average_daily_sale_root_location_id = fields.Many2one( @@ -13,8 +12,8 @@ class StockWarehouse(models.Model): compute="_compute_average_daily_sale_root_location_id", store=True, readonly=False, - required=True, precompute=True, + check_company=True, help="This is the root location for daily sale average stock computations", ) @@ -26,4 +25,17 @@ class StockWarehouse(models.Model): for warehouse in self.filtered( lambda w: not w.average_daily_sale_root_location_id ): + if not warehouse.lot_stock_id: + continue warehouse.average_daily_sale_root_location_id = warehouse.lot_stock_id + + @api.model_create_multi + def create(self, vals_list): + # set the lot_stock_id of a newly created WH as an Average Daily Sale Root Location + warehouses = super().create(vals_list) + for warehouse, vals in zip(warehouses, vals_list): + if vals.get("lot_stock_id") and not vals.get( + "average_daily_sale_root_location_id" + ): + warehouse.average_daily_sale_root_location_id = vals["lot_stock_id"] + return warehouses diff --git a/stock_average_daily_sale/views/stock_warehouse.xml b/stock_average_daily_sale/views/stock_warehouse.xml index 9715f01..dc70ab5 100644 --- a/stock_average_daily_sale/views/stock_warehouse.xml +++ b/stock_average_daily_sale/views/stock_warehouse.xml @@ -10,7 +10,11 @@ - + +