diff --git a/erpnext/buying/doctype/quality_inspection/quality_inspection.py b/erpnext/buying/doctype/quality_inspection/quality_inspection.py index da341086d7f..216d1657d04 100644 --- a/erpnext/buying/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/buying/doctype/quality_inspection/quality_inspection.py @@ -8,11 +8,15 @@ import frappe from frappe.model.document import Document class QualityInspection(Document): - def get_item_specification_details(self): self.set('qa_specification_details', []) - specification = frappe.db.sql("select specification, value from `tabItem Quality Inspection Parameter` \ - where parent = '%s' order by idx" % (self.item_code)) + variant_of = frappe.db.get_query("Item", self.item_code, "variant_of") + if variant_of: + specification = frappe.db.sql("select specification, value from `tabItem Quality Inspection Parameter` \ + where parent in (%s, %s) order by idx", (self.item_code, variant_of)) + else: + specification = frappe.db.sql("select specification, value from `tabItem Quality Inspection Parameter` \ + where parent = %s order by idx", self.item_code) for d in specification: child = self.append('qa_specification_details', {}) child.specification = d[0] @@ -21,18 +25,18 @@ class QualityInspection(Document): def on_submit(self): if self.purchase_receipt_no: - frappe.db.sql("""update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 - set t1.qa_no = %s, t2.modified = %s - where t1.parent = %s and t1.item_code = %s and t1.parent = t2.name""", - (self.name, self.modified, self.purchase_receipt_no, + frappe.db.sql("""update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 + set t1.qa_no = %s, t2.modified = %s + where t1.parent = %s and t1.item_code = %s and t1.parent = t2.name""", + (self.name, self.modified, self.purchase_receipt_no, self.item_code)) - + def on_cancel(self): if self.purchase_receipt_no: - frappe.db.sql("""update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 + frappe.db.sql("""update `tabPurchase Receipt Item` t1, `tabPurchase Receipt` t2 set t1.qa_no = '', t2.modified = %s - where t1.parent = %s and t1.item_code = %s and t1.parent = t2.name""", + where t1.parent = %s and t1.item_code = %s and t1.parent = t2.name""", (self.modified, self.purchase_receipt_no, self.item_code)) @@ -45,6 +49,6 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): "start": start, "page_len": page_len }) - return frappe.db.sql("""select item_code from `tab%(from)s` + return frappe.db.sql("""select item_code from `tab%(from)s` where parent='%(parent)s' and docstatus < 2 and item_code like '%%%(txt)s%%' %(mcond)s - order by item_code limit %(start)s, %(page_len)s""" % filters) \ No newline at end of file + order by item_code limit %(start)s, %(page_len)s""" % filters) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index e8f35f1347b..85c14494181 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -8,6 +8,7 @@ from frappe.utils import flt, rounded from erpnext.setup.utils import get_company_currency from erpnext.accounts.party import get_party_details +from erpnext.stock.get_item_details import get_conversion_factor from erpnext.controllers.stock_controller import StockController @@ -194,9 +195,8 @@ class BuyingController(StockController): self.round_floats_in(item) - item.conversion_factor = item.conversion_factor or flt(frappe.db.get_value( - "UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom}, - "conversion_factor")) or 1 + item.conversion_factor = get_conversion_factor(item.item_code, item.uom).get("conversion_factor") + qty_in_stock_uom = flt(item.qty * item.conversion_factor) rm_supp_cost = flt(item.rm_supp_cost) if self.doctype=="Purchase Receipt" else 0.0 diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index e274690f39d..b05ce2579c7 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -12,6 +12,9 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.set_intro(); if (cur_frm.doc.has_variants) { cur_frm.set_intro(__("This Item is a Template and cannot be used in transactions. Item attributes will be copied over into the variants unless 'No Copy' is set")); + cur_frm.add_custom_button(__("Show Variants"), function() { + frappe.set_route("List", "Item", {"variant_of": cur_frm.doc.name}); + }, "icon-list", "btn-default"); } if (cur_frm.doc.variant_of) { cur_frm.set_intro(__("This Item is a Variant of {0} (Template). Attributes will be copied over from the template unless 'No Copy' is set", [cur_frm.doc.variant_of])); @@ -33,7 +36,7 @@ cur_frm.cscript.refresh = function(doc) { if (!doc.__islocal && doc.show_in_website) { cur_frm.set_intro(__("Published on website at: {0}", - [repl('/%(website_route)s', doc.__onload)])); + [repl('/%(website_route)s', doc.__onload)]), true); } erpnext.item.toggle_reqd(cur_frm); @@ -78,7 +81,7 @@ cur_frm.cscript.make_dashboard = function() { cur_frm.cscript.edit_prices_button = function() { cur_frm.add_custom_button(__("Add / Edit Prices"), function() { frappe.set_route("Report", "Item Price", {"item_code": cur_frm.doc.name}); - }, "icon-money"); + }, "icon-money", "btn-default"); } cur_frm.cscript.item_code = function(doc) { diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json index c1a1fe92dea..12ff900667e 100644 --- a/erpnext/stock/doctype/item/item.json +++ b/erpnext/stock/doctype/item/item.json @@ -390,6 +390,7 @@ "read_only": 0 }, { + "description": "Will also apply for variants unless overrridden", "fieldname": "item_reorder", "fieldtype": "Table", "label": "Warehouse-wise Item Reorder", @@ -487,6 +488,7 @@ }, { "depends_on": "eval:doc.is_purchase_item==\"Yes\"", + "description": "Will also apply for variants", "fieldname": "uom_conversion_details", "fieldtype": "Table", "label": "UOM Conversion Details", @@ -619,6 +621,7 @@ "read_only": 0 }, { + "description": "Will also apply for variants", "fieldname": "item_tax", "fieldtype": "Table", "label": "Item Tax1", @@ -652,7 +655,7 @@ }, { "depends_on": "eval:doc.inspection_required==\"Yes\"", - "description": "Quality Inspection Parameters", + "description": "Will also apply to variants", "fieldname": "item_specification_details", "fieldtype": "Table", "label": "Item Quality Inspection Parameter", @@ -862,7 +865,7 @@ "icon": "icon-tag", "idx": 1, "max_attachments": 1, - "modified": "2014-10-03 04:58:39.278047", + "modified": "2014-10-07 05:25:19.921651", "modified_by": "Administrator", "module": "Stock", "name": "Item", diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index c7d9375043e..cf463726963 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -42,6 +42,8 @@ class Item(WebsiteGenerator): if self.image and not self.website_image: self.website_image = self.image + if self.variant_of: + self.copy_attributes_to_variant(frappe.get_doc("Item", self.variant_of), self) self.check_warehouse_is_set_for_stock_item() self.check_stock_uom_with_bin() self.add_default_uom_in_conversion_factor_table() @@ -211,32 +213,54 @@ class Item(WebsiteGenerator): def make_variant(self, item_code): item = frappe.new_doc("Item") - self.copy_attributes_to_variant(item, item_code, insert=True) item.item_code = item_code + self.copy_attributes_to_variant(self, item, insert=True) item.insert() def update_variant(self, item_code): item = frappe.get_doc("Item", item_code) - self.copy_attributes_to_variant(item, item_code) + item.item_code = item_code + self.copy_attributes_to_variant(self, item) item.save() - def copy_attributes_to_variant(self, variant, item_code, insert=False): + def copy_attributes_to_variant(self, template, variant, insert=False): from frappe.model import no_value_fields for field in self.meta.fields: - if field.fieldtype not in no_value_fields and (insert or not field.no_copy): - if variant.get(field.fieldname) != self.get(field.fieldname): - variant.set(field.fieldname, self.get(field.fieldname)) + if field.fieldtype not in no_value_fields and (insert or not field.no_copy)\ + and field.fieldname != "item_code": + if variant.get(field.fieldname) != template.get(field.fieldname): + variant.set(field.fieldname, template.get(field.fieldname)) variant.__dirty = True variant.description += "\n" - for attr in self.variant_attributes[item_code]: + + if not getattr(template, "variant_attributes", None): + template.get_variant_item_codes() + + for attr in template.variant_attributes[variant.item_code]: variant.description += "\n" + attr[0] + ": " + attr[1] if variant.description_html: variant.description_html += "