Merge pull request #4554 from umairsy/develop
Updated Articles
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index b10b72f..2a6ab88 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -140,7 +140,7 @@
clear_doctype_notifications(self)
def on_submit(self):
- if self.has_drop_ship_item():
+ if self.is_against_so():
self.update_status_updater()
super(PurchaseOrder, self).on_submit()
@@ -157,8 +157,10 @@
purchase_controller.update_last_purchase_rate(self, is_submit = 1)
def on_cancel(self):
- if self.has_drop_ship_item():
+ if self.is_against_so():
self.update_status_updater()
+
+ if self.has_drop_ship_item():
self.update_delivered_qty_in_sales_order()
pc_obj = frappe.get_doc('Purchase Common')
@@ -222,13 +224,10 @@
so.notify_update()
def has_drop_ship_item(self):
- is_drop_ship = False
-
- for item in self.items:
- if item.delivered_by_supplier == 1:
- is_drop_ship = True
-
- return is_drop_ship
+ return any([d.delivered_by_supplier for d in self.items])
+
+ def is_against_so(self):
+ return any([d.prevdoc_doctype for d in self.items if d.prevdoc_doctype=="Sales Order"])
def set_received_qty_for_drop_ship_items(self):
for item in self.items:
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index 5890b5d..a8f69ca 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -12,7 +12,7 @@
class ItemTemplateCannotHaveStock(frappe.ValidationError): pass
@frappe.whitelist()
-def get_variant(item, args):
+def get_variant(variant, template, args):
"""Validates Attributes and their Values, then looks for an exactly matching Item Variant
:param item: Template Item
@@ -24,9 +24,9 @@
if not args:
frappe.throw(_("Please specify at least one attribute in the Attributes table"))
- validate_item_variant_attributes(item, args)
+ validate_item_variant_attributes(template, args)
- return find_variant(item, args)
+ return find_variant(variant, template, args)
def validate_item_variant_attributes(item, args):
attribute_values = {}
@@ -65,7 +65,7 @@
frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values").format(
value, attribute))
-def find_variant(item, args):
+def find_variant(variant_item_code, template, args):
conditions = ["""(iv_attribute.attribute="{0}" and iv_attribute.attribute_value="{1}")"""\
.format(frappe.db.escape(key), frappe.db.escape(cstr(value))) for key, value in args.items()]
@@ -79,8 +79,8 @@
where variant_of=%s and exists (
select name from `tabItem Variant Attribute` iv_attribute
where iv_attribute.parent=item.name
- and ({conditions})
- )""".format(conditions=conditions), item)
+ and ({conditions}) and parent != %s
+ )""".format(conditions=conditions), (template, variant_item_code))
for variant in possible_variants:
variant = frappe.get_doc("Item", variant)
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 8e6b2c6..e3c275a 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -23,6 +23,7 @@
setup_wizard_requires = "assets/erpnext/js/setup_wizard.js"
setup_wizard_complete = "erpnext.setup.setup_wizard.setup_wizard.setup_complete"
+before_install = "erpnext.setup.install.check_setup_wizard_not_completed"
after_install = "erpnext.setup.install.after_install"
boot_session = "erpnext.startup.boot.boot_session"
diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py
index dcb6eb3..b4e19da 100644
--- a/erpnext/setup/install.py
+++ b/erpnext/setup/install.py
@@ -17,6 +17,14 @@
add_web_forms()
frappe.db.commit()
+def check_setup_wizard_not_completed():
+ if frappe.db.get_default('desktop:home_page') == 'desktop':
+ print
+ print "ERPNext can only be installed on a fresh site where the setup wizard is not completed"
+ print "You can reinstall this site (after saving your data) using: bench --site [sitename] reinstall"
+ print
+ return False
+
def feature_setup():
"""save global defaults and features setup"""
doc = frappe.get_doc("Features Setup", "Features Setup")
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 4d4cc6d..9892e71 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -106,8 +106,23 @@
}).insert()
# Bank Account
+ create_bank_account(args)
args["curr_fiscal_year"] = curr_fiscal_year
+
+def create_bank_account(args):
+ if args.get("bank_account"):
+ bank_account_group = frappe.db.get_value("Account",
+ {"account_type": "Bank", "is_group": 1, "root_type": "Asset"})
+ if bank_account_group:
+ frappe.get_doc({
+ "doctype": "Account",
+ 'account_name': args.get("bank_account"),
+ 'parent_account': bank_account_group,
+ 'is_group':0,
+ 'company':args.get('company_name').strip(),
+ "account_type": "Bank",
+ }).insert()
def create_price_lists(args):
for pl_type, pl_name in (("Selling", _("Standard Selling")), ("Buying", _("Standard Buying"))):
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 55295f4..d6e4748 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -320,6 +320,10 @@
frm.toggle_display("attributes", frm.doc.has_variants || frm.doc.variant_of);
frm.fields_dict.attributes.grid.toggle_reqd("attribute_value", frm.doc.variant_of ? 1 : 0);
frm.fields_dict.attributes.grid.set_column_disp("attribute_value", frm.doc.variant_of ? 1 : 0);
+
+ frm.toggle_enable("attributes", !frm.doc.variant_of);
+ frm.fields_dict.attributes.grid.toggle_enable("attribute", !frm.doc.variant_of);
+ frm.fields_dict.attributes.grid.toggle_enable("attribute_value", !frm.doc.variant_of);
}
});
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index dfe17e8..1004f91 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -563,11 +563,10 @@
frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
args[d.attribute] = d.attribute_value
- if self.variant_of:
- # test this during insert because naming is based on item_code and we cannot use condition like self.name != variant
- variant = get_variant(self.variant_of, args)
- if variant and self.get("__islocal"):
- frappe.throw(_("Item variant {0} exists with same attributes").format(variant), ItemVariantExistsError)
+ variant = get_variant(self.name, self.variant_of, args)
+ if variant:
+ frappe.throw(_("Item variant {0} exists with same attributes")
+ .format(variant), ItemVariantExistsError)
def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1):
if (not end_of_life) or (disabled is None):
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index bd6fe28..f8b6393 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -107,6 +107,7 @@
# doing it again should raise error
variant = create_variant("_Test Variant Item", {"Test Size": "Large"})
+ variant.item_code = "_Test Variant Item-L-duplicate"
self.assertRaises(ItemVariantExistsError, variant.save)
def test_make_item_variant_with_numeric_values(self):