Image feild added to Sales Invoice & Purchase Invoice
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 1280cc0..ce6ac7a 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -50,6 +50,23 @@
"width": "300px"
},
{
+ "fieldname": "image",
+ "fieldtype": "Attach",
+ "hidden": 1,
+ "label": "Image",
+ "permlevel": 0,
+ "precision": ""
+ },
+ {
+ "fieldname": "image_view",
+ "fieldtype": "Image",
+ "label": "Image View",
+ "options": "image",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 1
+ },
+ {
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate",
@@ -452,7 +469,7 @@
],
"idx": 1,
"istable": 1,
- "modified": "2015-06-02 14:18:56.294949",
+ "modified": "2015-07-02 03:00:44.496683",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 4ace40a..6dcd591 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -69,6 +69,23 @@
"width": "200px"
},
{
+ "fieldname": "image",
+ "fieldtype": "Attach",
+ "hidden": 1,
+ "label": "Image",
+ "permlevel": 0,
+ "precision": ""
+ },
+ {
+ "fieldname": "image_view",
+ "fieldtype": "Image",
+ "label": "Image View",
+ "options": "image",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 1
+ },
+ {
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate",
@@ -505,7 +522,7 @@
],
"idx": 1,
"istable": 1,
- "modified": "2015-06-02 14:18:45.176726",
+ "modified": "2015-07-02 02:59:08.413213",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 80965ec..725e020 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -169,3 +169,4 @@
erpnext.patches.v5_0.index_on_account_and_gl_entry
execute:frappe.db.sql("""delete from `tabProject Task`""")
erpnext.patches.v5_0.item_variants
+erpnext.patches.v5_0.update_item_desc_in_invoice
\ No newline at end of file
diff --git a/erpnext/patches/v5_0/update_item_desc_in_invoice.py b/erpnext/patches/v5_0/update_item_desc_in_invoice.py
new file mode 100644
index 0000000..b7a071c
--- /dev/null
+++ b/erpnext/patches/v5_0/update_item_desc_in_invoice.py
@@ -0,0 +1,50 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+import frappe
+from frappe.website.utils import find_first_image
+from frappe.utils import cstr
+import re
+
+def execute():
+ item_details = frappe._dict()
+ for d in frappe.db.sql("select name, description, image from `tabItem`", as_dict=1):
+ description = cstr(d.description).strip()
+ item_details.setdefault(d.name, frappe._dict({
+ "description": description,
+ "image": d.image
+ }))
+
+
+ dt_list= ["Sales Invoice Item","Purchase Invoice Item"]
+ for dt in dt_list:
+ frappe.reload_doctype(dt)
+ records = frappe.db.sql("""select name, item_code, description from `tab{0}`
+ where description is not null """.format(dt), as_dict=1)
+
+ count = 1
+ for d in records:
+ if d.item_code and item_details.get(d.item_code) \
+ and cstr(d.description) == item_details.get(d.item_code).description:
+ desc = item_details.get(d.item_code).description
+ image = item_details.get(d.item_code).image
+ else:
+ desc, image = extract_image_and_description(cstr(d.description))
+
+ if not image:
+ image = item_details.get(d.item_code).image
+
+ frappe.db.sql("""update `tab{0}` set description = %s, image = %s
+ where name = %s """.format(dt), (desc, image, d.name))
+
+ count += 1
+ if count % 500 == 0:
+ frappe.db.commit()
+
+
+def extract_image_and_description(data):
+ image_url = find_first_image(data)
+ desc = data
+ for tag in ("img", "table", "tr", "td"):
+ desc = re.sub("\</*{0}[^>]*\>".format(tag), "", desc)
+ return desc, image_url
\ No newline at end of file