brotherton-erpnext/erpnext/patches/v10_0/item_barcode_childtable_migrate.py

32 lines
754 B
Python
Raw Normal View History

# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
2019-02-17 05:54:51 +00:00
frappe.reload_doc("stock", "doctype", "item_barcode")
2018-02-12 10:29:55 +00:00
2019-02-17 05:54:51 +00:00
items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })
2018-02-12 10:29:55 +00:00
frappe.reload_doc("stock", "doctype", "item")
2019-02-17 05:54:51 +00:00
2018-02-12 10:29:55 +00:00
for item in items_barcode:
barcode = item.barcode.strip()
if barcode and '<' not in barcode:
2019-02-16 15:39:24 +00:00
try:
frappe.get_doc({
'idx': 0,
'doctype': 'Item Barcode',
'barcode': barcode,
'parenttype': 'Item',
'parent': item.name,
'parentfield': 'barcodes'
}).insert()
except (frappe.DuplicateEntryError, frappe.UniqueValidationError):
2019-02-16 15:39:24 +00:00
continue