Migration: Error in account warehouse patch

Sir,
I am getting this error on migrate database.Kindly help how to resolve this issue.

Migrating site1.local
Executing erpnext.patches.v8_0.move_account_head_from_account_to_warehouse_for_inventory in site1.local (1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 91, in
main()
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 17, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in _func
ret = f(frappe._dict(ctx.obj), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/site.py”, line 216, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/user/frappe-bench/apps/frappe/frappe/migrate.py”, line 31, in migrate
frappe.modules.patch_handler.run_all()
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 29, in run_all
if not run_single(patchmodule = patch):
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 63, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 83, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/user/frappe-bench/apps/erpnext/erpnext/patches/v8_0/move_account_head_from_account_to_warehouse_for_inventory.py”, line 15, in execute
warehouse = tabWarehouse.name and is_group = 0)""")
File “/home/user/frappe-bench/apps/frappe/frappe/database.py”, line 150, in sql
self._cursor.execute(query)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 250, in execute
self.errorhandler(self, exc, value)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/MySQLdb/connections.py”, line 42, in defaulterrorhandler
raise errorvalue
_mysql_exceptions.OperationalError: (1242, ‘Subquery returns more than 1 row’)

Thank you,

Check if there are multiple accounts in your Chart of Accounts for the same warehouse.
Issue is raised because the system expects only one Account for the warehouse, in your case it looks like there is more than one.

Hi @Prashanta_Mahato

Have fixed this issue, pull latest update and check

I have pull the latest, Now I am getting error Doctype Domain not found.

Executing erpnext.patches.v8_0.create_domain_docs #16-05-2017 in site1.local (1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 91, in
main()
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 17, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in _func
ret = f(frappe.dict(ctx.obj), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/site.py”, line 216, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/user/frappe-bench/apps/frappe/frappe/migrate.py”, line 31, in migrate
frappe.modules.patch_handler.run_all()
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 29, in run_all
if not run_single(patchmodule = patch):
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 63, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 83, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/user/frappe-bench/apps/erpnext/erpnext/patches/v8_0/create_domain_docs.py”, line 13, in execute
doc = frappe.new_doc(“Domain”)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 582, in new_doc
return get_new_doc(doctype, parent_doc, parentfield, as_dict=as_dict)
File “/home/user/frappe-bench/apps/frappe/frappe/model/create_new.py”, line 19, in get_new_doc
frappe.local.new_doc_templates[doctype] = make_new_doc(doctype)
File “/home/user/frappe-bench/apps/frappe/frappe/model/create_new.py”, line 37, in make_new_doc
“docstatus”: 0
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 606, in get_doc
return frappe.model.document.get_doc(arg1, arg2)
File “/home/user/frappe-bench/apps/frappe/frappe/model/document.py”, line 51, in get_doc
return controller(arg1, arg2)
File “/home/user/frappe-bench/apps/frappe/frappe/model/document.py”, line 88, in init
self.init_valid_columns()
File “/home/user/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 228, in init_valid_columns
for key in self.get_valid_columns():
File “/home/user/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 238, in get_valid_columns
valid = self.meta.get_valid_columns()
File “/home/user/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 62, in meta
self.meta = frappe.get_meta(self.doctype)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 623, in get_meta
return frappe.model.meta.get_meta(doctype, cached=cached)
File “/home/user/frappe-bench/apps/frappe/frappe/model/meta.py”, line 31, in get_meta
return frappe.cache().hget(“meta”, doctype, lambda: Meta(doctype))
File “/home/user/frappe-bench/apps/frappe/frappe/utils/redis_wrapper.py”, line 171, in hget
value = generator()
File “/home/user/frappe-bench/apps/frappe/frappe/model/meta.py”, line 31, in
return frappe.cache().hget(“meta”, doctype, lambda: Meta(doctype))
File “/home/user/frappe-bench/apps/frappe/frappe/model/meta.py”, line 66, in init
super(Meta, self).init(“DocType”, doctype)
File “/home/user/frappe-bench/apps/frappe/frappe/model/document.py”, line 84, in init
self.load_from_db()
File “/home/user/frappe-bench/apps/frappe/frappe/model/meta.py”, line 71, in load_from_db
super(Meta, self).load_from_db()
File “/home/user/frappe-bench/apps/frappe/frappe/model/document.py”, line 115, in load_from_db
frappe.throw(
("{0} {1} not found").format(
(self.doctype), self.name), frappe.DoesNotExistError)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 316, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 306, in msgprint
_raise_exception()
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 279, in _raise_exception
raise raise_exception, encode(msg)
frappe.exceptions.DoesNotExistError: DocType Domain not found

Hi @Prashanta_Mahato

Kindly pull the latest update again and check

Hi @rohit_w,
After pull I am getting Attribute error none type object has no attributes ‘replace’

Executing erpnext.patches.v8_0.create_domain_docs #16-05-2017 in site1.local (1bd3e0294da19198)
Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 91, in
main()
File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 17, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in func
ret = f(frappe.dict(ctx.obj), *args, **kwargs)
File “/home/user/frappe-bench/apps/frappe/frappe/commands/site.py”, line 216, in migrate
migrate(context.verbose, rebuild_website=rebuild_website)
File “/home/user/frappe-bench/apps/frappe/frappe/migrate.py”, line 31, in migrate
frappe.modules.patch_handler.run_all()
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 29, in run_all
if not run_single(patchmodule = patch):
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 63, in run_single
return execute_patch(patchmodule, method, methodargs)
File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 83, in execute_patch
frappe.get_attr(patchmodule.split()[0] + “.execute”)()
File “/home/user/frappe-bench/apps/erpnext/erpnext/patches/v8_0/create_domain_docs.py”, line 10, in execute
frappe.reload_doctype(“Domain”)
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 650, in reload_doctype
reload_doc(scrub(db.get_value(“DocType”, doctype, “module”)), “doctype”, scrub(doctype),
File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 676, in scrub
return txt.replace(’ ‘,’
’).replace(’-’, '
’).lower()
AttributeError: ‘NoneType’ object has no attribute ‘replace’

@Prashanta_Mahato,

Please try to pull the latest changes in frappe and erpnext app using

git pull --rebase upstream develop

then run the bench migrate app

Thanks,
Makarand

I have run the following commands, but the error remain same.

user@user-H81M-WW:~/frappe-bench/apps/frappe$ git pull --rebase upstream develop
From https://github.com/frappe/frappe

  • branch develop -> FETCH_HEAD
    Current branch develop is up to date.
    user@user-H81M-WW:~/frappe-bench/apps/frappe$ cd ~/frappe-bench/apps/erpnext/
    user@user-H81M-WW:~/frappe-bench/apps/erpnext$ git pull --rebase upstream develop
    From https://github.com/frappe/erpnext
  • branch develop -> FETCH_HEAD
    Current branch develop is up to date.
    user@user-H81M-WW:~/frappe-bench/apps/erpnext$ cd ~/frappe-bench/
    user@user-H81M-WW:~/frappe-bench$ bench migrate
    Migrating site1.local
    Executing erpnext.patches.v8_0.create_domain_docs #16-05-2017 in site1.local (1bd3e0294da19198)
    Traceback (most recent call last):
    File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
    main”, fname, loader, pkg_name)
    File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
    exec code in run_globals
    File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 91, in
    main()
    File “/home/user/frappe-bench/apps/frappe/frappe/utils/bench_helper.py”, line 17, in main
    click.Group(commands=commands)(prog_name=‘bench’)
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
    return self.main(*args, **kwargs)
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
    rv = self.invoke(ctx)
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
    return callback(*args, **kwargs)
    File “/home/user/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py”, line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
    File “/home/user/frappe-bench/apps/frappe/frappe/commands/init.py”, line 24, in func
    ret = f(frappe.dict(ctx.obj), *args, **kwargs)
    File “/home/user/frappe-bench/apps/frappe/frappe/commands/site.py”, line 216, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
    File “/home/user/frappe-bench/apps/frappe/frappe/migrate.py”, line 31, in migrate
    frappe.modules.patch_handler.run_all()
    File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 29, in run_all
    if not run_single(patchmodule = patch):
    File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 63, in run_single
    return execute_patch(patchmodule, method, methodargs)
    File “/home/user/frappe-bench/apps/frappe/frappe/modules/patch_handler.py”, line 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + “.execute”)()
    File “/home/user/frappe-bench/apps/erpnext/erpnext/patches/v8_0/create_domain_docs.py”, line 10, in execute
    frappe.reload_doctype(“Domain”)
    File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 650, in reload_doctype
    reload_doc(scrub(db.get_value(“DocType”, doctype, “module”)), “doctype”, scrub(doctype),
    File “/home/user/frappe-bench/apps/frappe/frappe/init.py”, line 676, in scrub
    return txt.replace(’ ‘,’
    ’).replace(’-’, '
    ’).lower()
    AttributeError: ‘NoneType’ object has no attribute ‘replace’

Did your problem solved?..i have also facing similar problem …

Manually I have link the warehouse with account.then git pull and bench update.

@Prashanta_Mahato, i have got in Employee Appraisal. can you help me to solved this issue.

Traceback (most recent call last):
File “/home/erp/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/erp/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/erp/apps/frappe/frappe/handler.py”, line 30, in execute_cmd
method = get_attr(cmd)
File “/home/erp/apps/frappe/frappe/handler.py”, line 114, in get_attr
method = frappe.get_attr(cmd)
File “/home/erp/apps/frappe/frappe/init.py”, line 859, in get_attr
return getattr(get_module(modulename), methodname)
AttributeError: ‘module’ object has no attribute 'fetch_appraisal_template

check your appraisal.py file for fetch_appraisal_template method. if method is not there then your Erpnext installation is not correct. run git pull from erpnext folder. then run the update & migrate command.

@Prashanta_Mahato, i have method in appraisal.:

my python code:

from __future__ import unicode_literals
import frappe

from frappe.utils import flt, getdate

from frappe import _
from frappe.model.mapper import get_mapped_doc
from frappe.model.document import Document
from erpnext.hr.utils import set_employee_name

class Appraisal(Document):
	def validate(self):
		if not self.status:
			self.status = "Draft"

		set_employee_name(self)
		self.validate_dates()
		self.validate_existing_appraisal()
		self.calculate_total()

	def get_employee_name(self):
		self.employee_name = frappe.db.get_value("Employee", self.employee, "employee_name")
		return self.employee_name

	def validate_dates(self):
		if getdate(self.start_date) > getdate(self.end_date):
			frappe.throw(_("End Date can not be less than Start Date"))

	def validate_existing_appraisal(self):
		chk = frappe.db.sql("""select name from `tabAppraisal` where employee=%s
			and (status='Submitted' or status='Completed')
			and ((start_date>=%s and start_date<=%s)
			or (end_date>=%s and end_date<=%s))""",
			(self.employee,self.start_date,self.end_date,self.start_date,self.end_date))
		if chk:
			frappe.throw(_("Appraisal {0} created for Employee {1} in the given date range").format(chk[0][0], self.employee_name))

	def calculate_total(self):
		total, total_w  = 0, 0
		for d in self.get('goals'):
			if d.score:
				d.score_earned = flt(d.score) * flt(d.per_weightage) / 100
				total = total + d.score_earned
			total_w += flt(d.per_weightage)

		if int(total_w) != 100:
			frappe.throw(_("Total weightage assigned should be 100%. It is {0}").format(str(total_w) + "%"))

		if frappe.db.get_value("Employee", self.employee, "user_id") != \
				frappe.session.user and total == 0:
			frappe.throw(_("Total cannot be zero"))

		self.total_score = total

	def on_submit(self):
		frappe.db.set(self, 'status', 'Submitted')

	def on_cancel(self):
		frappe.db.set(self, 'status', 'Cancelled')

@frappe.whitelist()
def fetch_appraisal_template(source_name, target_doc=None):
	target_doc = get_mapped_doc("Appraisal Template", source_name, {
		"Appraisal Template": {
			"doctype": "Appraisal",
		},
		"Appraisal Template Goal": {
			"doctype": "Appraisal Goal",
		}
	}, target_doc)

	return target_doc

can you share your error code with your erpnext version? when the error is occurred during update, migrate or when your are creating a new appraisal template?

@Prashanta_Mahato
erpnext version:
erpnext 7.0.34
frappe 7.0.30

when i select appraisal template from dropdown option, it give error

and when i used this code in .js it give error.

cur_frm.cscript.kra_template = function(doc, dt, dn) {
	erpnext.utils.map_current_doc({
		method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template",
		source_name: cur_frm.doc.kra_template,
		frm: cur_frm
	});
}

the script working fine for me. I have tried witch a custom doctype by adding two fields Appraisal Template (type link) and Goals (type table). I think you need to upgrade your ErpNext Version.