From 66df3566a99a0b9b32b449b3d32d7f6f30d3bccc Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 10 Feb 2015 13:05:08 +0530 Subject: [PATCH] html item desc removed from item master, item image added in oppurtunity --- .../crm/doctype/opportunity/opportunity.js | 17 +++++++- .../crm/doctype/opportunity/opportunity.py | 27 ++++++------- .../opportunity_item/opportunity_item.json | 37 ++++++++++++++++-- erpnext/stock/doctype/item/item.js | 24 ------------ erpnext/stock/doctype/item/item.json | 39 +++++++++---------- 5 files changed, 80 insertions(+), 64 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index a0ebcce6eb..8f93b2df85 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -94,8 +94,21 @@ cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { cur_frm.cscript.item_code = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if (d.item_code) { - return get_server_fields('get_item_details', d.item_code, - 'items', doc, cdt, cdn, 1); + return frappe.call({ + method: "erpnext.selling.doctype.opportunity.opportunity.get_item_details", + args: {"item_code":d.item_code}, + callback: function(r, rt) { + if(r.message) { + frappe.model.set_value(d.doctype, d.name, "description", r.message.description); + frappe.model.set_value(d.doctype, d.name, "item_name", r.message.item_name); + frappe.model.set_value(d.doctype, d.name, "brand", r.message.brand); + frappe.model.set_value(d.doctype, d.name, "uom", r.message.uom); + frappe.model.set_value(d.doctype, d.name, "item_group", r.message.item_group); + frappe.model.set_value(d.doctype, d.name, "image", r.message.image); + refresh_field('image_view', d.name, 'items'); + } + } + }) } } diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 31af3cdd26..39dd61439c 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -59,18 +59,6 @@ class Opportunity(TransactionBase): def validate_cust_name(self): self.customer_name = self.customer or self.lead - - def get_item_details(self, item_code): - item = frappe.db.sql("""select item_name, stock_uom, description_html, description, item_group, brand - from `tabItem` where name = %s""", item_code, as_dict=1) - ret = { - 'item_name': item and item[0]['item_name'] or '', - 'uom': item and item[0]['stock_uom'] or '', - 'description': item and item[0]['description_html'] or item[0]['description'] or '', - 'item_group': item and item[0]['item_group'] or '', - 'brand': item and item[0]['brand'] or '' - } - return ret def get_cust_address(self,name): details = frappe.db.sql("""select customer_name, address, territory, customer_group @@ -140,7 +128,20 @@ class Opportunity(TransactionBase): msgprint("Customer is mandatory if 'Opportunity From' is selected as Customer", raise_exception=1) else: self.lead = None - + +@frappe.whitelist() +def get_item_details(item_code): + item = frappe.db.sql("""select item_name, stock_uom, image, description, item_group, brand + from `tabItem` where name = %s""", item_code, as_dict=1) + return { + 'item_name': item and item[0]['item_name'] or '', + 'uom': item and item[0]['stock_uom'] or '', + 'description': item and item[0]['description'] or '', + 'image': item and item[0]['image'] or '', + 'item_group': item and item[0]['item_group'] or '', + 'brand': item and item[0]['brand'] or '' + } + @frappe.whitelist() def make_quotation(source_name, target_doc=None): def set_missing_values(source, target): diff --git a/erpnext/selling/doctype/opportunity_item/opportunity_item.json b/erpnext/selling/doctype/opportunity_item/opportunity_item.json index b6527e0af9..d81b1b7ff7 100644 --- a/erpnext/selling/doctype/opportunity_item/opportunity_item.json +++ b/erpnext/selling/doctype/opportunity_item/opportunity_item.json @@ -14,6 +14,11 @@ "permlevel": 0, "reqd": 0 }, + { + "fieldname": "col_break1", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "fieldname": "item_name", "fieldtype": "Data", @@ -52,9 +57,10 @@ "search_index": 0 }, { - "fieldname": "col_break1", - "fieldtype": "Column Break", - "permlevel": 0 + "fieldname": "section_break_6", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" }, { "fieldname": "description", @@ -68,6 +74,29 @@ "reqd": 1, "width": "300px" }, + { + "fieldname": "column_break_8", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "image", + "fieldtype": "Attach", + "hidden": 0, + "label": "Image", + "options": "", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "image_view", + "fieldtype": "Image", + "label": "Image View", + "options": "image", + "permlevel": 0, + "precision": "" + }, { "fieldname": "quantity_and_rate", "fieldtype": "Section Break", @@ -115,7 +144,7 @@ ], "idx": 1, "istable": 1, - "modified": "2015-01-01 14:29:58.657537", + "modified": "2015-02-10 13:03:39.188558", "modified_by": "Administrator", "module": "Selling", "name": "Opportunity Item", diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 4e82c55898..af7e7f0f24 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -150,22 +150,6 @@ cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) { } } -cur_frm.cscript.add_image = function(doc, dt, dn) { - if(!doc.image) { - msgprint(__('Please select an "Image" first')); - return; - } - - doc.description_html = repl('' + - '' + - '' + - '
%(desc)s
', { - imgurl: frappe.utils.get_file_link(doc.image), - desc: doc.description.replace(/\n/g, "
")}); - - refresh_field('description_html'); -} - // Quotation to validation - either customer or lead mandatory cur_frm.cscript.weight_to_validate = function(doc, cdt, cdn){ if((doc.nett_weight || doc.gross_weight) && !doc.weight_uom) { @@ -195,12 +179,4 @@ cur_frm.cscript.copy_from_item_group = function(doc) { cur_frm.cscript.image = function() { refresh_field("image_view"); - - if(!cur_frm.doc.image) return; - - if(!cur_frm.doc.description_html) - cur_frm.cscript.add_image(cur_frm.doc); - else { - msgprint(__("You may need to update: {0}", [frappe.meta.get_docfield(cur_frm.doc.doctype, "description_html").label])); - } } diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json index 36d2109784..c2f2a9b0d3 100644 --- a/erpnext/stock/doctype/item/item.json +++ b/erpnext/stock/doctype/item/item.json @@ -79,6 +79,12 @@ "read_only": 0, "reqd": 1 }, + { + "fieldname": "column_break0", + "fieldtype": "Column Break", + "permlevel": 0, + "read_only": 0 + }, { "description": "Unit of measurement of this item (e.g. Kg, Unit, No, Pair).", "fieldname": "stock_uom", @@ -112,9 +118,15 @@ "permlevel": 0, "read_only": 0 }, + { + "fieldname": "section_break_11", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "description", - "fieldtype": "Small Text", + "fieldtype": "Text Editor", "in_filter": 0, "in_list_view": 0, "label": "Description", @@ -126,10 +138,10 @@ "search_index": 0 }, { - "fieldname": "column_break0", + "fieldname": "column_break_13", "fieldtype": "Column Break", "permlevel": 0, - "read_only": 0 + "precision": "" }, { "fieldname": "image", @@ -137,7 +149,7 @@ "label": "Image", "options": "", "permlevel": 0, - "read_only": 0 + "precision": "" }, { "fieldname": "image_view", @@ -146,22 +158,7 @@ "label": "Image View", "options": "image", "permlevel": 0, - "read_only": 0 - }, - { - "fieldname": "description_html", - "fieldtype": "Small Text", - "label": "Description HTML", - "permlevel": 0, - "read_only": 0 - }, - { - "description": "Generates HTML to include selected image in the description", - "fieldname": "add_image", - "fieldtype": "Button", - "label": "Generate Description HTML", - "permlevel": 0, - "read_only": 0 + "precision": "" }, { "fieldname": "variants_section", @@ -864,7 +861,7 @@ "icon": "icon-tag", "idx": 1, "max_attachments": 1, - "modified": "2015-02-05 05:11:39.507487", + "modified": "2015-02-10 12:59:15.652054", "modified_by": "Administrator", "module": "Stock", "name": "Item",