From 09480e2241c42dcab64e9dd0daf049389627abc7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 16 Apr 2013 20:57:09 +0530 Subject: [PATCH 1/5] [sitemap] [fixes] --- website/helpers/sitemap.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/website/helpers/sitemap.py b/website/helpers/sitemap.py index 201865a074..c8b6fd0a53 100644 --- a/website/helpers/sitemap.py +++ b/website/helpers/sitemap.py @@ -14,25 +14,40 @@ def generate(domain): import urllib, os import webnotes import webnotes.webutils + from webnotes.utils import nowdate # settings - max_doctypes = 10 max_items = 1000 + count = 0 site_map = '' - page_list = [] - if domain: - # list of all pages in web cache - for doctype in webnotes.webutils.page_map: - d = webnotes.webutils.page_map[doctype]; + today = nowdate() + + # generated pages + for doctype, opts in webnotes.webutils.get_generators().items(): pages = webnotes.conn.sql("""select page_name, `modified` from `tab%s` where ifnull(%s,0)=1 - order by modified desc""" % (doctype, d.condition_field)) + order by modified desc""" % (doctype, opts.get("condition_field"))) for p in pages: + if count >= max_items: break page_url = os.path.join(domain, urllib.quote(p[0])) modified = p[1].strftime('%Y-%m-%d') site_map += link_xml % (page_url, modified) + count += 1 + + if count >= max_items: break + + # standard pages + for page, opts in webnotes.get_config()["web"]["pages"].items(): + if "no_cache" in opts: + continue + + if count >= max_items: break + page_url = os.path.join(domain, urllib.quote(page)) + modified = today + site_map += link_xml % (page_url, modified) + count += 1 - return frame_xml % site_map + return frame_xml % site_map From e776742f5d149982deaf47ccfe3a5e4d4b2882a7 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 17 Apr 2013 13:19:35 +0530 Subject: [PATCH 2/5] [company] [cleanup] on_rename method --- setup/doctype/company/company.py | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py index bee1333554..964b886ed7 100644 --- a/setup/doctype/company/company.py +++ b/setup/doctype/company/company.py @@ -153,7 +153,7 @@ class DocType: for d in acc_list_common: self.add_acc(d) - country = sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'") + country = webnotes.conn.sql("select value from tabSingles where field = 'country' and doctype = 'Control Panel'") country = country and cstr(country[0][0]) or '' # load taxes (only for India) @@ -265,26 +265,31 @@ class DocType: """ Trash accounts and cost centers for this company if no gl entry exists """ - rec = sql("SELECT name from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No' and company = %s", self.doc.name) + rec = webnotes.conn.sql("SELECT name from `tabGL Entry` where ifnull(is_cancelled, 'No') = 'No' and company = %s", self.doc.name) if not rec: # delete gl entry - sql("delete from `tabGL Entry` where company = %s", self.doc.name) + webnotes.conn.sql("delete from `tabGL Entry` where company = %s", self.doc.name) #delete tabAccount - sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name) + webnotes.conn.sql("delete from `tabAccount` where company = %s order by lft desc, rgt desc", self.doc.name) #delete cost center child table - budget detail - sql("delete bd.* from `tabBudget Detail` bd, `tabCost Center` cc where bd.parent = cc.name and cc.company_name = %s", self.doc.name) + webnotes.conn.sql("delete bd.* from `tabBudget Detail` bd, `tabCost Center` cc where bd.parent = cc.name and cc.company_name = %s", self.doc.name) #delete cost center - sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name) + webnotes.conn.sql("delete from `tabCost Center` WHERE company_name = %s order by lft desc, rgt desc", self.doc.name) - webnotes.defaults.clear_default("company", value=self.doc.name) + webnotes.defaults.clear_default("company", value=self.doc.name) + + webnotes.conn.sql("""update `tabSingles` set value="" + where doctype='Global Defaults' and field='default_company' + and value=%s""", self.doc.name) - #update value as blank for tabSingles Global Defaults - sql("update `tabSingles` set value = '' where doctype='Global Defaults' and field = 'default_company' and value = %s", self.doc.name) - def on_rename(self,newdn,olddn): - sql("update `tabCompany` set company_name = '%s' where name = '%s'" %(newdn,olddn)) - sql("update `tabSingles` set value = %s where doctype='Global Defaults' and field = 'default_company' and value = %s", (newdn, olddn)) - if webnotes.defaults.get_global_default('company') == olddn: - webnotes.defaults.set_global_default('company', newdn) \ No newline at end of file + webnotes.conn.sql("""update `tabCompany` set company_name=%s + where name=%s""", (newdn, olddn)) + + webnotes.conn.sql("""update `tabSingles` set value=%s + where doctype='Global Defaults' and field='default_company' + and value=%s""", (newdn, olddn)) + + webnotes.defaults.clear_default("company", value=olddn) \ No newline at end of file From 96dae29144a0e0ca5b03b4448f1a2202b9e2c56f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 17 Apr 2013 13:39:55 +0530 Subject: [PATCH 3/5] [item] [fixes] don't validate for active boms for new items --- stock/doctype/item/item.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index 3486f92027..a16296d18b 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -22,12 +22,10 @@ from webnotes.model.doc import addchild from webnotes.model.bean import getlist from webnotes import msgprint, _ -sql = webnotes.conn.sql - from webnotes.model.controller import DocListController class DocType(DocListController): def get_tax_rate(self, tax_type): - rate = sql("select tax_rate from tabAccount where name = %s", tax_type) + rate = webnotes.conn.sql("select tax_rate from tabAccount where name = %s", tax_type) ret = { 'tax_rate' : rate and flt(rate[0][0]) or 0 } @@ -39,7 +37,7 @@ class DocType(DocListController): # webpage updates self.update_website() - bin = sql("select stock_uom from `tabBin` where item_code = %s", + bin = webnotes.conn.sql("select stock_uom from `tabBin` where item_code = %s", self.doc.item_code) if bin and cstr(bin[0][0]) and cstr(bin[0][0]) != cstr(self.doc.stock_uom): msgprint("Please Update Stock UOM with the help of Stock UOM Replace Utility.") @@ -108,8 +106,8 @@ class DocType(DocListController): # On delete 1. Delete BIN (if none of the corrosponding transactions present, it gets deleted. if present, rolled back due to exception) def on_trash(self): - sql("""delete from tabBin where item_code=%s""", self.doc.item_code) - sql("""delete from `tabStock Ledger Entry` + webnotes.conn.sql("""delete from tabBin where item_code=%s""", self.doc.item_code) + webnotes.conn.sql("""delete from `tabStock Ledger Entry` where item_code=%s and is_cancelled='Yes' """, self.doc.item_code) if self.doc.page_name: @@ -150,7 +148,7 @@ class DocType(DocListController): def check_for_active_boms(self, field_label): if field_label in ['Is Active', 'Is Purchase Item']: - bom_mat = sql("select distinct t1.parent from `tabBOM Item` t1, `tabBOM` t2 where t1.item_code =%s and (t1.bom_no = '' or t1.bom_no is NULL) and t2.name = t1.parent and t2.is_active = 1 and t2.docstatus = 1 and t1.docstatus =1 ", self.doc.name) + bom_mat = webnotes.conn.sql("select distinct t1.parent from `tabBOM Item` t1, `tabBOM` t2 where t1.item_code =%s and (t1.bom_no = '' or t1.bom_no is NULL) and t2.name = t1.parent and t2.is_active = 1 and t2.docstatus = 1 and t1.docstatus =1 ", self.doc.name) if bom_mat and bom_mat[0][0]: msgprint("%s should be 'Yes'. As Item %s is present in one or many Active BOMs." % (cstr(field_label), cstr(self.doc.name))) raise Exception @@ -158,25 +156,27 @@ class DocType(DocListController): and self.doc.is_sub_contracted_item != 'Yes') or (field_label == 'Is Sub Contracted Item' and self.doc.is_manufactured_item != 'Yes')): - bom = sql("select name from `tabBOM` where item = %s and is_active = 1", self.doc.name) + bom = webnotes.conn.sql("select name from `tabBOM` where item = %s and is_active = 1", + (self.doc.name,)) if bom and bom[0][0]: msgprint("%s should be 'Yes'. As Item %s is present in one or many Active BOMs." % (cstr(field_label), cstr(self.doc.name))) raise Exception def validate_barcode(self): if self.doc.barcode: - duplicate = sql("select name from tabItem where barcode = %s and name != %s", (self.doc.barcode, self.doc.name)) + duplicate = webnotes.conn.sql("select name from tabItem where barcode = %s and name != %s", (self.doc.barcode, self.doc.name)) if duplicate: msgprint("Barcode: %s already used in item: %s" % (self.doc.barcode, cstr(duplicate[0][0])), raise_exception = 1) def validate(self): - fl = {'is_manufactured_item' :'Allow Bill of Materials', + if not cint(self.doc.fields.get("__islocal")): + fl = {'is_manufactured_item' :'Allow Bill of Materials', 'is_sub_contracted_item':'Is Sub Contracted Item', 'is_purchase_item' :'Is Purchase Item', 'is_pro_applicable' :'Allow Production Order'} - for d in fl: - if cstr(self.doc.fields.get(d)) != 'Yes': - self.check_for_active_boms(fl[d]) + for d in fl: + if cstr(self.doc.fields.get(d)) != 'Yes': + self.check_for_active_boms(fl[d]) self.check_ref_rate_detail() self.fill_customer_code() self.check_item_tax() @@ -198,7 +198,7 @@ class DocType(DocListController): def check_non_asset_warehouse(self): if self.doc.is_asset_item == "Yes": - existing_qty = sql("select t1.warehouse, t1.actual_qty from tabBin t1, tabWarehouse t2 where t1.item_code=%s and (t2.warehouse_type!='Fixed Asset' or t2.warehouse_type is null) and t1.warehouse=t2.name and t1.actual_qty > 0", self.doc.name) + existing_qty = webnotes.conn.sql("select t1.warehouse, t1.actual_qty from tabBin t1, tabWarehouse t2 where t1.item_code=%s and (t2.warehouse_type!='Fixed Asset' or t2.warehouse_type is null) and t1.warehouse=t2.name and t1.actual_qty > 0", self.doc.name) for e in existing_qty: msgprint("%s Units exist in Warehouse %s, which is not an Asset Warehouse." % (e[1],e[0])) if existing_qty: @@ -207,7 +207,7 @@ class DocType(DocListController): raise Exception def get_file_details(self, arg = ''): - file = sql("select file_group, description from tabFile where name = %s", eval(arg)['file_name'], as_dict = 1) + file = webnotes.conn.sql("select file_group, description from tabFile where name = %s", eval(arg)['file_name'], as_dict = 1) ret = { 'file_group' : file and file[0]['file_group'] or '', @@ -217,11 +217,11 @@ class DocType(DocListController): def check_if_sle_exists(self): - sle = sql("select name from `tabStock Ledger Entry` where item_code = %s and ifnull(is_cancelled, 'No') = 'No'", self.doc.name) + sle = webnotes.conn.sql("select name from `tabStock Ledger Entry` where item_code = %s and ifnull(is_cancelled, 'No') = 'No'", self.doc.name) return sle and 'exists' or 'not exists' def on_rename(self,newdn,olddn): - sql("update tabItem set item_code = %s where name = %s", (newdn, olddn)) + webnotes.conn.sql("update tabItem set item_code = %s where name = %s", (newdn, olddn)) if self.doc.page_name: from webnotes.webutils import clear_cache clear_cache(self.doc.page_name) From d484b380adb7b44fb3a92da936b892181ea8d955 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 17 Apr 2013 15:10:08 +0530 Subject: [PATCH 4/5] [email digest] [sender] sender should be the automail id specified in Email Settings --- setup/doctype/email_digest/email_digest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup/doctype/email_digest/email_digest.py b/setup/doctype/email_digest/email_digest.py index 0b0b21ae17..881e35a8f5 100644 --- a/setup/doctype/email_digest/email_digest.py +++ b/setup/doctype/email_digest/email_digest.py @@ -94,8 +94,7 @@ class DocType(DocListController): msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \ common_msg) from webnotes.utils.email_lib import sendmail - sendmail(recipients=user_id, subject=(self.doc.frequency + " Digest"), - sender="ERPNext Notifications ", + sendmail(recipients=user_id, subject="[ERPNext] " + (self.doc.frequency + " Digest"), msg=msg_for_this_receipient) def get_digest_msg(self): From 58b8d6fdf3d49b04be6fcbff792adeb4388bf796 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 17 Apr 2013 15:22:06 +0530 Subject: [PATCH 5/5] [website settings] [cleanup] removed mandatory check on Home Page --- .../doctype/website_settings/website_settings.txt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/website/doctype/website_settings/website_settings.txt b/website/doctype/website_settings/website_settings.txt index a39144cd6a..0ebc75b2eb 100644 --- a/website/doctype/website_settings/website_settings.txt +++ b/website/doctype/website_settings/website_settings.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-03-07 11:55:11", + "creation": "2013-03-26 06:51:18", "docstatus": 0, - "modified": "2013-03-13 16:25:22", + "modified": "2013-04-17 11:51:24", "modified_by": "Administrator", "owner": "Administrator" }, @@ -50,7 +50,7 @@ "fieldtype": "Link", "label": "Home Page", "options": "Web Page", - "reqd": 1 + "reqd": 0 }, { "description": "The name of your company / website as you want to appear on browser title bar. All pages will have this as the prefix to the title.", @@ -236,13 +236,6 @@ "no_copy": 1, "print_hide": 1 }, - { - "create": 1, - "doctype": "DocPerm", - "permlevel": 0, - "role": "System Manager", - "write": 1 - }, { "create": 1, "doctype": "DocPerm",