修改migrate脚本,解决更新慢的问题
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
|
import logging
|
||||||
from odoo import api, SUPERUSER_ID
|
from odoo import api, SUPERUSER_ID
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def migrate(cr, version):
|
def migrate(cr, version):
|
||||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||||
sf_shelf_model = env["sf.shelf"]
|
sf_shelf_model = env["sf.shelf"]
|
||||||
@@ -9,7 +12,10 @@ def migrate(cr, version):
|
|||||||
shelf_barcode = shelf.barcode or ""
|
shelf_barcode = shelf.barcode or ""
|
||||||
if not shelf_barcode:
|
if not shelf_barcode:
|
||||||
continue
|
continue
|
||||||
locations = sf_shelf_location_model.search([("shelf_id", "=", shelf.id)], order="id asc")
|
# locations = sf_shelf_location_model.search([("shelf_id", "=", shelf.id)], order="id asc")
|
||||||
|
locations = shelf.location_ids.sorted('id')
|
||||||
for index, location in enumerate(locations, start=1):
|
for index, location in enumerate(locations, start=1):
|
||||||
new_barcode = f"{shelf_barcode}-{index:03d}"
|
new_barcode = f"{shelf_barcode}-{index:03d}"
|
||||||
location.barcode = new_barcode
|
location.barcode = new_barcode
|
||||||
|
cr.commit()
|
||||||
|
_logger.info('货架【%s】的%d个货位被更新' % (shelf.name, len(locations)))
|
||||||
Reference in New Issue
Block a user