Merge Request: 恢复刀具房样式和编码 Created By: @谷耀东 Reviewed By: @胡尧 Approved By: @胡尧 Accepted By: @谷耀东 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/2219
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
import logging
|
|
from odoo import api, SUPERUSER_ID
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
def migrate(cr, version):
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
|
sf_shelf_model = env["sf.shelf"]
|
|
sf_shelf_location_model = env["sf.shelf.location"]
|
|
|
|
preproduction_shelf_ids = sf_shelf_location_model.get_preproduction_shelf_ids()
|
|
|
|
shelves = sf_shelf_model.search([])
|
|
for shelf in shelves:
|
|
if shelf.id not in preproduction_shelf_ids:
|
|
continue
|
|
|
|
shelf_barcode = shelf.barcode or ""
|
|
if not shelf_barcode:
|
|
continue
|
|
# 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):
|
|
new_barcode = f"{shelf_barcode}-{index:03d}"
|
|
location.barcode = new_barcode
|
|
cr.commit()
|
|
_logger.info('货架【%s】的%d个货位被更新' % (shelf.name, len(locations))) |