mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
stock_location_tray: Optimize creation of xmlids in batch
Use the multi creation on records to create all the xmlids at once.
This commit is contained in:
committed by
Hai Lang
parent
41c0581390
commit
b008f3bd58
@@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Location Trays",
|
"name": "Location Trays",
|
||||||
"summary": "Organize a location as a matrix of cells",
|
"summary": "Organize a location as a matrix of cells",
|
||||||
"version": "13.0.1.0.0",
|
"version": "13.0.1.0.1",
|
||||||
"category": "Stock",
|
"category": "Stock",
|
||||||
"author": "Camptocamp, Odoo Community Association (OCA)",
|
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
|
|||||||
@@ -241,6 +241,13 @@ class StockLocation(models.Model):
|
|||||||
|
|
||||||
Called from stock_location_tray/demo/stock_location_demo.xml.
|
Called from stock_location_tray/demo/stock_location_demo.xml.
|
||||||
"""
|
"""
|
||||||
|
xmlids_to_create = []
|
||||||
|
|
||||||
|
def has_ref(xmlid):
|
||||||
|
ModelData = self.env["ir.model.data"]
|
||||||
|
__, res_id = ModelData.xmlid_to_res_model_res_id(xmlid)
|
||||||
|
return bool(res_id)
|
||||||
|
|
||||||
for location in self:
|
for location in self:
|
||||||
if not location.cell_in_tray_type_id:
|
if not location.cell_in_tray_type_id:
|
||||||
continue
|
continue
|
||||||
@@ -260,8 +267,8 @@ class StockLocation(models.Model):
|
|||||||
tray_name, location.posx, location.posy
|
tray_name, location.posx, location.posy
|
||||||
)
|
)
|
||||||
cell_xmlid = "{}.{}".format(module, cell_external_id)
|
cell_xmlid = "{}.{}".format(module, cell_external_id)
|
||||||
if not self.env.ref(cell_xmlid, raise_if_not_found=False):
|
if not has_ref(cell_xmlid):
|
||||||
self.env["ir.model.data"].create(
|
xmlids_to_create.append(
|
||||||
{
|
{
|
||||||
"name": cell_external_id,
|
"name": cell_external_id,
|
||||||
"module": module,
|
"module": module,
|
||||||
@@ -270,3 +277,5 @@ class StockLocation(models.Model):
|
|||||||
"noupdate": tray_external.noupdate,
|
"noupdate": tray_external.noupdate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.env["ir.model.data"].create(xmlids_to_create)
|
||||||
|
|||||||
Reference in New Issue
Block a user