mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
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
This commit is contained in:
@@ -4,7 +4,6 @@ from odoo import api, fields, models
|
|||||||
|
|
||||||
|
|
||||||
class StockWarehouse(models.Model):
|
class StockWarehouse(models.Model):
|
||||||
|
|
||||||
_inherit = "stock.warehouse"
|
_inherit = "stock.warehouse"
|
||||||
|
|
||||||
average_daily_sale_root_location_id = fields.Many2one(
|
average_daily_sale_root_location_id = fields.Many2one(
|
||||||
@@ -13,8 +12,8 @@ class StockWarehouse(models.Model):
|
|||||||
compute="_compute_average_daily_sale_root_location_id",
|
compute="_compute_average_daily_sale_root_location_id",
|
||||||
store=True,
|
store=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
required=True,
|
|
||||||
precompute=True,
|
precompute=True,
|
||||||
|
check_company=True,
|
||||||
help="This is the root location for daily sale average stock computations",
|
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(
|
for warehouse in self.filtered(
|
||||||
lambda w: not w.average_daily_sale_root_location_id
|
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
|
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
|
||||||
|
|||||||
@@ -10,7 +10,11 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//group[1]" position="after">
|
<xpath expr="//group[1]" position="after">
|
||||||
<group string="Average Sales" name="average_sale_reporting">
|
<group string="Average Sales" name="average_sale_reporting">
|
||||||
<field name="average_daily_sale_root_location_id" />
|
<field name="lot_stock_id" invisible="1" />
|
||||||
|
<field
|
||||||
|
name="average_daily_sale_root_location_id"
|
||||||
|
attrs="{'required': [('lot_stock_id', '!=', False)]}"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user