From 9c15ef903d608f7c671a37a08fdfcd0370e50f63 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 2 Jul 2015 13:09:57 +0530 Subject: [PATCH] Image feild added to Sales Invoice & Purchase Invoice --- .../purchase_invoice_item.json | 19 ++++++- .../sales_invoice_item.json | 19 ++++++- erpnext/patches.txt | 1 + .../v5_0/update_item_desc_in_invoice.py | 50 +++++++++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v5_0/update_item_desc_in_invoice.py 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 1280cc0c1e..ce6ac7aa3b 100755 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -49,6 +49,23 @@ "read_only": 0, "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", @@ -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 4ace40a672..6dcd59137a 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -68,6 +68,23 @@ "reqd": 1, "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", @@ -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 80965ece06..725e020888 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -169,3 +169,4 @@ erpnext.patches.v5_0.update_material_transferred_for_manufacturing_again 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 0000000000..b7a071cbfe --- /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("\]*\>".format(tag), "", desc) + return desc, image_url \ No newline at end of file