Merge pull request #3550 from neilLasrado/item-desc
Image feild added to Sales Invoice & Purchase Invoice
This commit is contained in:
commit
04fb1c7fe4
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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
|
50
erpnext/patches/v5_0/update_item_desc_in_invoice.py
Normal file
50
erpnext/patches/v5_0/update_item_desc_in_invoice.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user