
from __future__ import unicode_literals

import frappe


def execute():
	items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })

	frappe.reload_doc("stock", "doctype", "item")
	frappe.reload_doc("stock", "doctype", "item_barcode")

	for item in items_barcode:
		barcode = item.barcode.strip()

		if barcode and '<' not in barcode:
			try:
				frappe.get_doc({
					'idx': 0,
					'doctype': 'Item Barcode',
					'barcode': barcode,
					'parenttype': 'Item',
					'parent': item.name,
					'parentfield': 'barcodes'
				}).insert()
			except frappe.DuplicateEntryError:
				continue


from __future__ import unicode_literals

import frappe


def execute():
	frappe.reload_doc("stock", "doctype", "item_barcode")

	items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })
	frappe.reload_doc("stock", "doctype", "item")



	for item in items_barcode:
		barcode = item.barcode.strip()

		if barcode and '<' not in barcode:
			try:
				frappe.get_doc({
					'idx': 0,
					'doctype': 'Item Barcode',
					'barcode': barcode,
					'parenttype': 'Item',
					'parent': item.name,
					'parentfield': 'barcodes'
				}).insert()
			except frappe.DuplicateEntryError:
				continue

Move reload doc before get query
Move reload doc before get query

  
  from __future__ import unicode_literals
  
  import frappe
  
  
  def execute():
+ 	frappe.reload_doc("stock", "doctype", "item_barcode")
+ 
  	items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })
+ 	frappe.reload_doc("stock", "doctype", "item")
  
+ 
- 	frappe.reload_doc("stock", "doctype", "item")
- 	frappe.reload_doc("stock", "doctype", "item_barcode")
  
  	for item in items_barcode:
  		barcode = item.barcode.strip()
  
  		if barcode and '<' not in barcode:
  			try:
  				frappe.get_doc({
  					'idx': 0,
  					'doctype': 'Item Barcode',
  					'barcode': barcode,
  					'parenttype': 'Item',
  					'parent': item.name,
  					'parentfield': 'barcodes'
  				}).insert()
  			except frappe.DuplicateEntryError:
  				continue
  
Move reload doc before get query
## Code Before:

from __future__ import unicode_literals

import frappe


def execute():
	items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })

	frappe.reload_doc("stock", "doctype", "item")
	frappe.reload_doc("stock", "doctype", "item_barcode")

	for item in items_barcode:
		barcode = item.barcode.strip()

		if barcode and '<' not in barcode:
			try:
				frappe.get_doc({
					'idx': 0,
					'doctype': 'Item Barcode',
					'barcode': barcode,
					'parenttype': 'Item',
					'parent': item.name,
					'parentfield': 'barcodes'
				}).insert()
			except frappe.DuplicateEntryError:
				continue

## Instruction:
Move reload doc before get query
## Code After:

from __future__ import unicode_literals

import frappe


def execute():
	frappe.reload_doc("stock", "doctype", "item_barcode")

	items_barcode = frappe.get_all('Item', ['name', 'barcode'], { 'barcode': ('!=', '') })
	frappe.reload_doc("stock", "doctype", "item")



	for item in items_barcode:
		barcode = item.barcode.strip()

		if barcode and '<' not in barcode:
			try:
				frappe.get_doc({
					'idx': 0,
					'doctype': 'Item Barcode',
					'barcode': barcode,
					'parenttype': 'Item',
					'parent': item.name,
					'parentfield': 'barcodes'
				}).insert()
			except frappe.DuplicateEntryError:
				continue
