From 6164b89e9588b1047c3687e10458bc656bef09f6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 6 Jun 2013 17:18:38 +0530 Subject: [PATCH 01/13] [report] listing on home page --- accounts/page/accounts_home/accounts_home.js | 15 +++++---------- .../item_wise_sales_register.py | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js index 7f623d7115..b920bfdbab 100644 --- a/accounts/page/accounts_home/accounts_home.js +++ b/accounts/page/accounts_home/accounts_home.js @@ -127,16 +127,6 @@ wn.module_page["Accounts"] = [ right: true, icon: "icon-table", items: [ - { - "label":wn._("Customer Account Head"), - route: "query-report/Customer Account Head", - doctype: "Account" - }, - { - "label":wn._("Supplier Account Head"), - route: "query-report/Supplier Account Head", - doctype: "Account" - }, { "label":wn._("General Ledger"), page: "general-ledger" @@ -247,6 +237,11 @@ wn.module_page["Accounts"] = [ route: "query-report/Customer Account Head", doctype: "Account" }, + { + "label":wn._("Supplier Account Head"), + route: "query-report/Supplier Account Head", + doctype: "Account" + }, { "label":wn._("Item-wise Sales Register"), route: "query-report/Item-wise Sales Register", diff --git a/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/accounts/report/item_wise_sales_register/item_wise_sales_register.py index f6e26af350..f3ed2a1242 100644 --- a/accounts/report/item_wise_sales_register/item_wise_sales_register.py +++ b/accounts/report/item_wise_sales_register/item_wise_sales_register.py @@ -59,7 +59,7 @@ def get_conditions(filters): def get_items(filters): conditions = get_conditions(filters) return webnotes.conn.sql("""select si.name, si.posting_date, si.debit_to, si.project_name, - si.customer, si.remarks, si.territory, si_item.item_code, si_item.item_name, + si.customer, si.remarks, si.territory, si.company, si_item.item_code, si_item.item_name, si_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account, si_item.qty, si_item.basic_rate, si_item.amount from `tabSales Invoice` si, `tabSales Invoice Item` si_item From 4bb0eee41117cf6ea17b7e79428bf7cf58c90011 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 7 Jun 2013 17:06:39 +0530 Subject: [PATCH 02/13] [fixes] outstanding for jv --- accounts/doctype/gl_entry/gl_entry.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/accounts/doctype/gl_entry/gl_entry.py b/accounts/doctype/gl_entry/gl_entry.py index 112e449f97..a2ef25a777 100644 --- a/accounts/doctype/gl_entry/gl_entry.py +++ b/accounts/doctype/gl_entry/gl_entry.py @@ -160,13 +160,13 @@ class DocType: def update_outstanding_amt(self): # get final outstanding amt bal = flt(sql("""select sum(debit) - sum(credit) from `tabGL Entry` - where against_voucher=%s and against_voucher_type=%s - and ifnull(is_cancelled,'No') = 'No'""", - (self.doc.against_voucher, self.doc.against_voucher_type))[0][0] or 0.0) - + where against_voucher=%s and against_voucher_type=%s and account = %s + and ifnull(is_cancelled,'No') = 'No'""", (self.doc.against_voucher, + self.doc.against_voucher_type, self.doc.account))[0][0] or 0.0) + if self.doc.against_voucher_type == 'Purchase Invoice': bal = -bal - + elif self.doc.against_voucher_type == "Journal Voucher": against_voucher_amount = flt(webnotes.conn.sql("""select sum(debit) - sum(credit) from `tabGL Entry` where voucher_type = 'Journal Voucher' and voucher_no = %s From b2dc1aeca99c26a577ace74802288520e141b932 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 12:34:31 +0530 Subject: [PATCH 03/13] [lead] [next contact] [fix] create event --- selling/doctype/lead/lead.py | 59 ++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index 571cdfd516..d80f84362b 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -17,8 +17,7 @@ from __future__ import unicode_literals import webnotes from webnotes import _ -from webnotes.utils import cstr, validate_email_add -from webnotes.model.doc import Document, addchild +from webnotes.utils import cstr, validate_email_add, cint from webnotes import session, msgprint sql = webnotes.conn.sql @@ -54,11 +53,17 @@ class DocType(SellingController): if not validate_email_add(self.doc.email_id): msgprint('Please enter valid email id.') raise Exception + + self._prev = webnotes._dict({ + "contact_date": webnotes.conn.get_value("Lead", self.doc.name, "contact_date") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + "contact_by": webnotes.conn.get_value("Lead", self.doc.name, "contact_by") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + }) def on_update(self): - if self.doc.contact_date: - self.add_calendar_event() + self.add_calendar_event() self.check_email_id_is_unique() @@ -73,25 +78,33 @@ class DocType(SellingController): ", ".join(items), raise_exception=True) def add_calendar_event(self): - # delete any earlier event by this lead - sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name) - - # create new event - ev = Document('Event') - ev.owner = self.doc.lead_owner - ev.description = ('Contact ' + cstr(self.doc.lead_name)) + \ - (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ - (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') - ev.event_date = self.doc.contact_date - ev.event_hour = '10:00' - ev.event_type = 'Private' - ev.ref_type = 'Lead' - ev.ref_name = self.doc.name - ev.save(1) - - event_user = addchild(ev, 'event_individuals', 'Event User') - event_user.person = self.doc.contact_by - event_user.save() + if self.doc.contact_by != cstr(self._prev.contact_by) or \ + self.doc.contact_date != cstr(self._prev.contact_date): + # delete any earlier event by this lead + for name in webnotes.conn.sql_list("""select name from `tabEvent` + where ref_type="Lead" and ref_name=%s""", self.doc.name): + webnotes.delete_doc("Event", name) + + if self.doc.contact_date: + webnotes.bean([ + { + "doctype": "Event", + "owner": self.doc.lead_owner or self.doc.owner, + "subject": ('Contact ' + cstr(self.doc.lead_name)), + "description": ('Contact ' + cstr(self.doc.lead_name)) + \ + (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ + (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or ''), + "starts_on": self.doc.contact_date + " 10:00:00", + "event_type": "Private", + "ref_type": "Lead", + "ref_name": self.doc.name + }, + { + "doctype": "Event User", + "parentfield": "event_individuals", + "person": self.doc.contact_by + } + ]).insert() def get_sender(self, comm): return webnotes.conn.get_value('Sales Email Settings',None,'email_id') From e53a81dceacbd20375276c068c2f05666ca8d72c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 15:15:40 +0530 Subject: [PATCH 04/13] [event] [lead, opportunity, project] [fix] create events --- .../p04_fix_event_for_lead_oppty_project.py | 21 ++++++ patches/patch_list.py | 1 + projects/doctype/project/project.py | 70 ++++++++----------- selling/doctype/lead/lead.py | 58 +++++---------- selling/doctype/opportunity/opportunity.py | 65 ++++++++--------- .../maintenance_schedule.py | 39 ++++++----- utilities/transaction_base.py | 36 +++++++++- 7 files changed, 157 insertions(+), 133 deletions(-) create mode 100644 patches/june_2013/p04_fix_event_for_lead_oppty_project.py diff --git a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py new file mode 100644 index 0000000000..a6449c528a --- /dev/null +++ b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py @@ -0,0 +1,21 @@ +import webnotes + +def execute(): + # delete orphaned Event User + webnotes.conn.sql("""delete from `tabEvent User` + where not exists(select name from `tabEvent` where `tabEvent`.name = `tabEvent User`.parent)""") + + for dt in ["Lead", "Opportunity", "Project"]: + for ref_name in webnotes.conn.sql_list("""select ref_name + from `tabEvent` where ref_type=%s and ifnull(starts_on, '')='' """, dt): + if webnotes.conn.exists(dt, ref_name): + controller = webnotes.get_obj(dt, ref_name) + if dt == "Project": + controller.add_calendar_event() + else: + controller.delete_events() + controller._add_calendar_event() + else: + # remove events where ref doc doesn't exist + webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` + where ref_type=%s and ref_name=%s""", (dt, ref_name))) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index d8b84da8f8..6b88955a10 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -254,4 +254,5 @@ patch_list = [ "patches.may_2013.p05_update_cancelled_gl_entries", "patches.june_2013.p01_update_bom_exploded_items", "execute:webnotes.delete_doc('DocType', 'System Console')", + "patches.june_2013.p04_fix_event_for_lead_oppty_project", ] \ No newline at end of file diff --git a/projects/doctype/project/project.py b/projects/doctype/project/project.py index 1de551c753..b519224ab9 100644 --- a/projects/doctype/project/project.py +++ b/projects/doctype/project/project.py @@ -18,24 +18,17 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import flt, getdate -from webnotes.model import db_exists -from webnotes.model.doc import Document -from webnotes.model.bean import copy_doclist from webnotes import msgprint -sql = webnotes.conn.sql - - - class DocType: - def __init__(self, doc, doclist=[]): + def __init__(self, doc, doclist=None): self.doc = doc self.doclist = doclist # Get Customer Details along with its primary contact details # ============================================================== def get_customer_details(self): - details =sql("select address, territory, customer_group,customer_name from `tabCustomer` where name=%s and docstatus!=2",(self.doc.customer),as_dict=1) + details =webnotes.conn.sql("select address, territory, customer_group,customer_name from `tabCustomer` where name=%s and docstatus!=2",(self.doc.customer),as_dict=1) if details: ret = { 'customer_address' : details and details[0]['address'] or '', @@ -44,7 +37,7 @@ class DocType: 'customer_name' : details and details[0]['customer_name'] or '' } #get primary contact details(this is done separately coz. , if join query used & no primary contact thn it would not be able to fetch customer details) - contact_det = sql("select contact_name, phone, email_id from `tabContact` where customer_name='%s' and is_customer=1 and is_primary_contact=1 and docstatus!=2" %(self.doc.customer), as_dict = 1) + contact_det = webnotes.conn.sql("select contact_name, phone, email_id from `tabContact` where customer_name='%s' and is_customer=1 and is_primary_contact=1 and docstatus!=2" %(self.doc.customer), as_dict = 1) ret['contact_person'] = contact_det and contact_det[0]['contact_name'] or '' ret['contact_no'] = contact_det and contact_det[0]['phone'] or '' ret['email_id'] = contact_det and contact_det[0]['email_id'] or '' @@ -52,21 +45,7 @@ class DocType: else: msgprint("Customer : %s does not exist in system." % (self.doc.customer)) raise Exception - - # Get customer's contact person details - # ============================================================== - def get_contact_details(self): - contact = sql("select contact_no, email_id from `tabContact` where contact_name = '%s' and customer_name = '%s' and docstatus != 2" %(self.doc,contact_person,self.doc.customer), as_dict=1) - if contact: - ret = { - 'contact_no' : contact and contact[0]['contact_no'] or '', - 'email_id' : contact and contact[0]['email_id'] or '' - } - return ret - else: - msgprint("Contact Person : %s does not exist in the system." % (self.doc,contact_person)) - raise Exception - + #calculate gross profit #============================================= def get_gross_profit(self): @@ -86,20 +65,29 @@ class DocType: raise Exception def on_update(self): - # update milestones - webnotes.conn.sql("""delete from tabEvent where ref_type='Project' and ref_name=%s""", - self.doc.name) - for d in self.doclist: - if d.doctype=='Project Milestone' and d.docstatus!=2: - self.add_calendar_event(d.milestone, d.milestone_date) + self.add_calendar_event() - def add_calendar_event(self, milestone, date): - """ Add calendar event for task in calendar of Allocated person""" - event = Document('Event') - event.description = milestone + ' for ' + self.doc.name - event.event_date = date - event.event_hour = '10:00' - event.event_type = 'Public' - event.ref_type = 'Project' - event.ref_name = self.doc.name - event.save(1) + def add_calendar_event(self): + # delete any earlier event for this project + self.delete_events() + + # add events + for milestone in self.doclist.get({"parentfield": "project_milestones"}): + description = milestone.milestone + " for " + self.doc.name + webnotes.bean({ + "doctype": "Event", + "owner": self.doc.owner, + "subject": description, + "description": description, + "starts_on": milestone.milestone_date + " 10:00:00", + "event_type": "Private", + "ref_type": self.doc.doctype, + "ref_name": self.doc.name + }).insert() + + def on_trash(self): + self.delete_events() + + def delete_events(self): + webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` + where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name))) \ No newline at end of file diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index d80f84362b..0e27261a26 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -29,6 +29,13 @@ class DocType(SellingController): self.doc = doc self.doclist = doclist + self._prev = webnotes._dict({ + "contact_date": webnotes.conn.get_value("Lead", self.doc.name, "contact_date") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + "contact_by": webnotes.conn.get_value("Lead", self.doc.name, "contact_by") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + }) + def onload(self): self.add_communication_list() @@ -53,19 +60,19 @@ class DocType(SellingController): if not validate_email_add(self.doc.email_id): msgprint('Please enter valid email id.') raise Exception - - self._prev = webnotes._dict({ - "contact_date": webnotes.conn.get_value("Lead", self.doc.name, "contact_date") if \ - (not cint(self.doc.fields.get("__islocal"))) else None, - "contact_by": webnotes.conn.get_value("Lead", self.doc.name, "contact_by") if \ - (not cint(self.doc.fields.get("__islocal"))) else None, - }) - def on_update(self): - self.add_calendar_event() - self.check_email_id_is_unique() + self.add_calendar_event() + + def add_calendar_event(self, opts=None): + super(DocType, self).add_calendar_event({ + "owner": self.doc.lead_owner, + "subject": ('Contact ' + cstr(self.doc.lead_name)), + "description": ('Contact ' + cstr(self.doc.lead_name)) + \ + (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ + (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') + }) def check_email_id_is_unique(self): if self.doc.email_id: @@ -76,35 +83,6 @@ class DocType(SellingController): items = [e[0] for e in email_list if e[0]!=self.doc.name] webnotes.msgprint(_("""Email Id must be unique, already exists for: """) + \ ", ".join(items), raise_exception=True) - - def add_calendar_event(self): - if self.doc.contact_by != cstr(self._prev.contact_by) or \ - self.doc.contact_date != cstr(self._prev.contact_date): - # delete any earlier event by this lead - for name in webnotes.conn.sql_list("""select name from `tabEvent` - where ref_type="Lead" and ref_name=%s""", self.doc.name): - webnotes.delete_doc("Event", name) - - if self.doc.contact_date: - webnotes.bean([ - { - "doctype": "Event", - "owner": self.doc.lead_owner or self.doc.owner, - "subject": ('Contact ' + cstr(self.doc.lead_name)), - "description": ('Contact ' + cstr(self.doc.lead_name)) + \ - (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ - (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or ''), - "starts_on": self.doc.contact_date + " 10:00:00", - "event_type": "Private", - "ref_type": "Lead", - "ref_name": self.doc.name - }, - { - "doctype": "Event User", - "parentfield": "event_individuals", - "person": self.doc.contact_by - } - ]).insert() def get_sender(self, comm): return webnotes.conn.get_value('Sales Email Settings',None,'email_id') @@ -113,3 +91,5 @@ class DocType(SellingController): webnotes.conn.sql("""update tabCommunication set lead=null where lead=%s""", self.doc.name) webnotes.conn.sql("""update `tabSupport Ticket` set lead='' where lead=%s""", self.doc.name) + + self.delete_events() \ No newline at end of file diff --git a/selling/doctype/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py index 75a7cd270d..0540ac9881 100644 --- a/selling/doctype/opportunity/opportunity.py +++ b/selling/doctype/opportunity/opportunity.py @@ -17,9 +17,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import add_days, cstr, getdate -from webnotes.model import db_exists -from webnotes.model.doc import Document, addchild +from webnotes.utils import add_days, cstr, getdate, cint from webnotes.model.bean import getlist from webnotes import msgprint @@ -34,6 +32,13 @@ class DocType(TransactionBase): self.fname = 'enq_details' self.tname = 'Opportunity Item' + self._prev = webnotes._dict({ + "contact_date": webnotes.conn.get_value("Opportunity", self.doc.name, "contact_date") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + "contact_by": webnotes.conn.get_value("Opportunity", self.doc.name, "contact_by") if \ + (not cint(self.doc.fields.get("__islocal"))) else None, + }) + def onload(self): self.add_communication_list() @@ -84,48 +89,34 @@ class DocType(TransactionBase): def on_update(self): # Add to calendar if self.doc.contact_date and self.doc.contact_date_ref != self.doc.contact_date: - if self.doc.contact_by: - self.add_calendar_event() webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date) - webnotes.conn.set(self.doc, 'status', 'Draft') - def add_calendar_event(self): - desc='' - user_lst =[] + self.add_calendar_event() + + def add_calendar_event(self, opts=None): + if not opts: + opts = webnotes._dict() + + opts.description = "" + if self.doc.customer: if self.doc.contact_person: - desc = 'Contact '+cstr(self.doc.contact_person) + opts.description = 'Contact '+cstr(self.doc.contact_person) else: - desc = 'Contact customer '+cstr(self.doc.customer) + opts.description = 'Contact customer '+cstr(self.doc.customer) elif self.doc.lead: if self.doc.contact_display: - desc = 'Contact '+cstr(self.doc.contact_display) + opts.description = 'Contact '+cstr(self.doc.contact_display) else: - desc = 'Contact lead '+cstr(self.doc.lead) - desc = desc+ '. By : ' + cstr(self.doc.contact_by) + opts.description = 'Contact lead '+cstr(self.doc.lead) + + opts.subject = opts.description + opts.description += '. By : ' + cstr(self.doc.contact_by) if self.doc.to_discuss: - desc = desc+' To Discuss : ' + cstr(self.doc.to_discuss) + opts.description += ' To Discuss : ' + cstr(self.doc.to_discuss) - ev = Document('Event') - ev.description = desc - ev.event_date = self.doc.contact_date - ev.event_hour = '10:00' - ev.event_type = 'Private' - ev.ref_type = 'Opportunity' - ev.ref_name = self.doc.name - ev.save(1) - - user_lst.append(self.doc.owner) - - chk = sql("select t1.name from `tabProfile` t1, `tabSales Person` t2 where t2.email_id = t1.name and t2.name=%s",self.doc.contact_by) - if chk: - user_lst.append(chk[0][0]) - - for d in user_lst: - ch = addchild(ev, 'event_individuals', 'Event User') - ch.person = d - ch.save(1) + super(DocType, self).add_calendar_event(opts) def set_last_contact_date(self): if self.doc.contact_date_ref and self.doc.contact_date_ref != self.doc.contact_date: @@ -159,6 +150,9 @@ class DocType(TransactionBase): self.set_last_contact_date() self.validate_item_details() self.validate_lead_cust() + + if not self.doc.status: + self.doc.status = "Draft" def on_submit(self): webnotes.conn.set(self.doc, 'status', 'Submitted') @@ -180,3 +174,6 @@ class DocType(TransactionBase): webnotes.conn.set(self.doc, 'status', 'Opportunity Lost') webnotes.conn.set(self.doc, 'order_lost_reason', arg) return 'true' + + def on_trash(self): + self.delete_events() \ No newline at end of file diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py index 60962b1d52..06c5a47aff 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -18,7 +18,7 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import add_days, cstr, getdate -from webnotes.model.doc import Document, addchild +from webnotes.model.doc import addchild from webnotes.model.bean import getlist from webnotes.model.code import get_obj from webnotes import msgprint @@ -100,23 +100,21 @@ class DocType(TransactionBase): for key in scheduled_date: if email_map[d.incharge_name]: - self.add_calender_event(key["scheduled_date"],email_map[d.incharge_name],d.item_code) + description = "Reference: %s, Item Code: %s and Customer: %s" % \ + (self.doc.name, d.item_code, self.doc.customer) + webnotes.bean({ + "doctype": "Event", + "owner": email_map[d.incharge_name] or self.doc.owner, + "subject": description, + "description": description, + "starts_on": key["scheduled_date"] + " 10:00:00", + "event_type": "Private", + "ref_type": self.doc.doctype, + "ref_name": self.doc.name + }).insert() + webnotes.conn.set(self.doc, 'status', 'Submitted') - - def add_calender_event(self,scheduled_date,incharge_email,item_code): - """ Add calendar event for Maintenece Schedule in calendar of Allocated person""" - event = Document('Event') - event.owner = incharge_email - event.description = "Reference:%s, Item Code:%s and Customer: %s" %(self.doc.name, item_code, self.doc.customer) - event.event_date = scheduled_date - event.event_hour = '10:00' - event.event_type = 'Private' - event.ref_type = 'Maintenance Schedule' - event.ref_name = self.doc.name - event.save(1) - - #get schedule dates #---------------------- def create_schedule_list(self, start_date, end_date, no_of_visit): @@ -329,8 +327,13 @@ class DocType(TransactionBase): if d.serial_no: self.update_amc_date(d.serial_no, '') webnotes.conn.set(self.doc, 'status', 'Cancelled') - sql("delete from `tabEvent` where ref_type='Maintenance Schedule' and ref_name='%s' " %(self.doc.name)) + self.delete_events() + def on_trash(self): - sql("delete from `tabEvent` where ref_type='Maintenance Schedule' and ref_name='%s' " %(self.doc.name)) + self.delete_events() + + def delete_events(self): + webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` + where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name))) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 5d7d1a84b1..4c70eba2d7 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -268,4 +268,38 @@ class TransactionBase(DocListController): def validate_posting_time(self): if not self.doc.posting_time: self.doc.posting_time = now_datetime().strftime('%H:%M:%S') - \ No newline at end of file + + def add_calendar_event(self, opts): + if self.doc.contact_by != cstr(self._prev.contact_by) or \ + self.doc.contact_date != cstr(self._prev.contact_date): + + self.delete_events() + self._add_calendar_event(opts) + + def delete_events(self): + webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` + where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name))) + + def _add_calendar_event(self, opts): + opts = webnotes._dict(opts) + + if self.doc.contact_date: + event_doclist = [{ + "doctype": "Event", + "owner": opts.owner or self.doc.owner, + "subject": opts.subject, + "description": opts.description, + "starts_on": self.doc.contact_date + " 10:00:00", + "event_type": "Private", + "ref_type": self.doc.doctype, + "ref_name": self.doc.name + }] + + if webnotes.conn.exists("Profile", self.doc.contact_by): + event_doclist.append({ + "doctype": "Event User", + "parentfield": "event_individuals", + "person": self.doc.contact_by + }) + + webnotes.bean(event_doclist).insert() From dec9a165ac2c31c51a4bacd4eb763e4790e502c1 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 15:26:54 +0530 Subject: [PATCH 05/13] [patch] [fix] events for project, lead, oppty --- patches/june_2013/p04_fix_event_for_lead_oppty_project.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py index a6449c528a..6929eedcdd 100644 --- a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py +++ b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py @@ -9,12 +9,7 @@ def execute(): for ref_name in webnotes.conn.sql_list("""select ref_name from `tabEvent` where ref_type=%s and ifnull(starts_on, '')='' """, dt): if webnotes.conn.exists(dt, ref_name): - controller = webnotes.get_obj(dt, ref_name) - if dt == "Project": - controller.add_calendar_event() - else: - controller.delete_events() - controller._add_calendar_event() + webnotes.get_obj(dt, ref_name).add_calendar_event() else: # remove events where ref doc doesn't exist webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` From 670199b9c62180044b387a8b9a205986f19e53c3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 15:38:01 +0530 Subject: [PATCH 06/13] [patch] [fix] event for project, oppty, lead --- patches/june_2013/p04_fix_event_for_lead_oppty_project.py | 5 ++++- selling/doctype/lead/lead.py | 4 ++-- selling/doctype/opportunity/opportunity.py | 4 ++-- utilities/transaction_base.py | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py index 6929eedcdd..3f66d8bfbb 100644 --- a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py +++ b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py @@ -9,7 +9,10 @@ def execute(): for ref_name in webnotes.conn.sql_list("""select ref_name from `tabEvent` where ref_type=%s and ifnull(starts_on, '')='' """, dt): if webnotes.conn.exists(dt, ref_name): - webnotes.get_obj(dt, ref_name).add_calendar_event() + if dt in ["Lead", "Opportunity"]: + webnotes.get_obj(dt, ref_name).add_calendar_event(force=True) + else: + webnotes.get_obj(dt, ref_name).add_calendar_event() else: # remove events where ref doc doesn't exist webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent` diff --git a/selling/doctype/lead/lead.py b/selling/doctype/lead/lead.py index 0e27261a26..a54343a907 100644 --- a/selling/doctype/lead/lead.py +++ b/selling/doctype/lead/lead.py @@ -65,14 +65,14 @@ class DocType(SellingController): self.check_email_id_is_unique() self.add_calendar_event() - def add_calendar_event(self, opts=None): + def add_calendar_event(self, opts=None, force=False): super(DocType, self).add_calendar_event({ "owner": self.doc.lead_owner, "subject": ('Contact ' + cstr(self.doc.lead_name)), "description": ('Contact ' + cstr(self.doc.lead_name)) + \ (self.doc.contact_by and ('. By : ' + cstr(self.doc.contact_by)) or '') + \ (self.doc.remark and ('.To Discuss : ' + cstr(self.doc.remark)) or '') - }) + }, force) def check_email_id_is_unique(self): if self.doc.email_id: diff --git a/selling/doctype/opportunity/opportunity.py b/selling/doctype/opportunity/opportunity.py index 0540ac9881..9fb061b228 100644 --- a/selling/doctype/opportunity/opportunity.py +++ b/selling/doctype/opportunity/opportunity.py @@ -93,7 +93,7 @@ class DocType(TransactionBase): self.add_calendar_event() - def add_calendar_event(self, opts=None): + def add_calendar_event(self, opts=None, force=False): if not opts: opts = webnotes._dict() @@ -116,7 +116,7 @@ class DocType(TransactionBase): if self.doc.to_discuss: opts.description += ' To Discuss : ' + cstr(self.doc.to_discuss) - super(DocType, self).add_calendar_event(opts) + super(DocType, self).add_calendar_event(opts, force) def set_last_contact_date(self): if self.doc.contact_date_ref and self.doc.contact_date_ref != self.doc.contact_date: diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 4c70eba2d7..f9af912737 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -269,9 +269,9 @@ class TransactionBase(DocListController): if not self.doc.posting_time: self.doc.posting_time = now_datetime().strftime('%H:%M:%S') - def add_calendar_event(self, opts): + def add_calendar_event(self, opts, force=False): if self.doc.contact_by != cstr(self._prev.contact_by) or \ - self.doc.contact_date != cstr(self._prev.contact_date): + self.doc.contact_date != cstr(self._prev.contact_date) or force: self.delete_events() self._add_calendar_event(opts) From f09a9f68e4a7834649e9df9b41f03778b38a72bd Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 15:57:52 +0530 Subject: [PATCH 07/13] [project] [event] fix in creation of event --- projects/doctype/project/project.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/projects/doctype/project/project.py b/projects/doctype/project/project.py index b519224ab9..94b6787312 100644 --- a/projects/doctype/project/project.py +++ b/projects/doctype/project/project.py @@ -73,17 +73,18 @@ class DocType: # add events for milestone in self.doclist.get({"parentfield": "project_milestones"}): - description = milestone.milestone + " for " + self.doc.name - webnotes.bean({ - "doctype": "Event", - "owner": self.doc.owner, - "subject": description, - "description": description, - "starts_on": milestone.milestone_date + " 10:00:00", - "event_type": "Private", - "ref_type": self.doc.doctype, - "ref_name": self.doc.name - }).insert() + if milestone.milestone_date: + description = (milestone.milestone or "Milestone") + " for " + self.doc.name + webnotes.bean({ + "doctype": "Event", + "owner": self.doc.owner, + "subject": description, + "description": description, + "starts_on": milestone.milestone_date + " 10:00:00", + "event_type": "Private", + "ref_type": self.doc.doctype, + "ref_name": self.doc.name + }).insert() def on_trash(self): self.delete_events() From 0175fbd47026daa45333829637285a0e74bfcadb Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 16:27:29 +0530 Subject: [PATCH 08/13] [buying] [purchase taxes] get cost center from taxes master --- buying/doctype/purchase_common/purchase_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index d5b563b3c5..2b6ca27acc 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -432,6 +432,7 @@ class DocType(BuyingController): d.account_head = other['account_head'] d.rate = flt(other['rate']) d.tax_amount = flt(other['tax_amount']) + d.cost_center = other["cost_center"] d.idx = idx idx += 1 return obj.doclist From 89e2ac4f477ee6f5c1de170e253188212437df2c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 10 Jun 2013 17:58:33 +0530 Subject: [PATCH 09/13] [voucher import tool] [fix] validate account columns only for voucher import of type Multiple Accounts --- .../voucher_import_tool.py | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/accounts/page/voucher_import_tool/voucher_import_tool.py b/accounts/page/voucher_import_tool/voucher_import_tool.py index 7634e5bf84..a3790a8fe1 100644 --- a/accounts/page/voucher_import_tool/voucher_import_tool.py +++ b/accounts/page/voucher_import_tool/voucher_import_tool.py @@ -59,7 +59,7 @@ def upload(): if not company_abbr: webnotes.msgprint(_("Company is missing or entered incorrect value"), raise_exception=1) - data, start_idx = get_data(rows, company_abbr) + data, start_idx = get_data(rows, company_abbr, rows[0][0]) except Exception, e: err_msg = webnotes.message_log and "
".join(webnotes.message_log) or cstr(e) messages.append("""

%s

""" % (err_msg or "No message")) @@ -213,10 +213,11 @@ def get_common_values(rows): return common_values -def get_data(rows, company_abbr): +def get_data(rows, company_abbr, import_type): start_row = 0 data = [] start_row_idx = 0 + accounts = None for i in xrange(len(rows)): r = rows[i] if r[0]: @@ -257,17 +258,19 @@ def get_data(rows, company_abbr): columns = [c.replace(" ", "_").lower() for c in rows[i+1] if not c.endswith(" - " + company_abbr)] - accounts = [c for c in rows[i+1] if c.endswith(" - " + company_abbr)] + + if import_type == "Voucher Import: Multiple Accounts": + accounts = [c for c in rows[i+1] if c.endswith(" - " + company_abbr)] - if not accounts: - webnotes.msgprint(_("""No Account found in csv file, - May be company abbreviation is not correct"""), raise_exception=1) + if not accounts: + webnotes.msgprint(_("""No Account found in csv file, + May be company abbreviation is not correct"""), raise_exception=1) - if accounts and (len(columns) != rows[i+1].index(accounts[0])): - webnotes.msgprint(_("""All account columns should be after \ - standard columns and on the right. - If you entered it properly, next probable reason \ - could be wrong account name. - Please rectify it in the file and try again."""), raise_exception=1) + if accounts and (len(columns) != rows[i+1].index(accounts[0])): + webnotes.msgprint(_("""All account columns should be after \ + standard columns and on the right. + If you entered it properly, next probable reason \ + could be wrong account name. + Please rectify it in the file and try again."""), raise_exception=1) return data, start_row_idx \ No newline at end of file From 49af8754d558c4acf867775391528b96cc75bbad Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 11 Jun 2013 12:40:46 +0530 Subject: [PATCH 10/13] [auto inventory accounting] [general ledger entry] calculate valuation amount without rounding --- accounts/doctype/purchase_invoice/purchase_invoice.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index 95b56dc4ff..32a46cf58f 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -466,9 +466,8 @@ class DocType(BuyingController): # expense will be booked in sales invoice stock_item_and_auto_inventory_accounting = True - valuation_amt = (flt(item.amount, self.precision.item.amount) + - flt(item.item_tax_amount, self.precision.item.item_tax_amount) + - flt(item.rm_supp_cost, self.precision.item.rm_supp_cost)) + valuation_amt = (flt(item.amount) + flt(item.item_tax_amount) + + flt(item.rm_supp_cost)) gl_entries.append( self.get_gl_dict({ From 433047b2e284a707165fc1ae623d402f44a4cd64 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 11 Jun 2013 14:28:42 +0530 Subject: [PATCH 11/13] [customer] [permlevel] changed fields/perms with permlevel 2 to permlevel 1 --- selling/doctype/customer/customer.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/selling/doctype/customer/customer.txt b/selling/doctype/customer/customer.txt index a221daa599..d7cecdd1bf 100644 --- a/selling/doctype/customer/customer.txt +++ b/selling/doctype/customer/customer.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-23 19:57:18", + "creation": "2013-06-11 14:26:44", "docstatus": 0, - "modified": "2013-01-29 16:28:03", + "modified": "2013-06-11 14:27:57", "modified_by": "Administrator", "owner": "Administrator" }, @@ -270,7 +270,7 @@ "label": "Credit Days", "oldfieldname": "credit_days", "oldfieldtype": "Int", - "permlevel": 2 + "permlevel": 1 }, { "doctype": "DocField", @@ -280,7 +280,7 @@ "oldfieldname": "credit_limit", "oldfieldtype": "Currency", "options": "Company:company:default_currency", - "permlevel": 2 + "permlevel": 1 }, { "doctype": "DocField", @@ -339,7 +339,7 @@ }, { "doctype": "DocPerm", - "permlevel": 2, + "permlevel": 1, "role": "Sales User" }, { @@ -355,7 +355,7 @@ }, { "doctype": "DocPerm", - "permlevel": 2, + "permlevel": 1, "role": "Sales Master Manager", "write": 1 } From 2e0cc41fc6634403d392d3c41fe203e1e2e9dacf Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 11 Jun 2013 17:33:37 +0530 Subject: [PATCH 12/13] [chart of accounts/cost center] [add account/cost center] fix in permission issue --- accounts/utils.py | 2 -- buying/doctype/supplier/supplier.py | 19 ++++++++++++------- selling/doctype/customer/customer.py | 16 +++++++++------- setup/doctype/company/company.py | 6 ++++-- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/accounts/utils.py b/accounts/utils.py index 31e622166e..eb240e796c 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -125,7 +125,6 @@ def add_ac(args=None): ac.doc.doctype = "Account" ac.doc.old_parent = "" ac.doc.freeze_account = "No" - ac.ignore_permissions = 1 ac.insert() return ac.doc.name @@ -138,7 +137,6 @@ def add_cc(args=None): cc = webnotes.bean(args) cc.doc.doctype = "Cost Center" cc.doc.old_parent = "" - cc.ignore_permissions = 1 cc.insert() return cc.doc.name diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py index d41b86c32c..f506439bad 100644 --- a/buying/doctype/supplier/supplier.py +++ b/buying/doctype/supplier/supplier.py @@ -24,7 +24,6 @@ from webnotes.model.doc import make_autoname sql = webnotes.conn.sql -from accounts.utils import add_ac from utilities.transaction_base import TransactionBase class DocType(TransactionBase): @@ -71,14 +70,16 @@ class DocType(TransactionBase): return g def add_account(self, ac, par, abbr): - ac = add_ac({ + ac_bean = webnotes.bean({ + "doctype": "Account", 'account_name':ac, 'parent_account':par, 'group_or_ledger':'Group', 'company':self.doc.company, - 'account_type':'', - 'tax_rate':'0' + "freeze_account": "No", }) + ac_bean.ignore_permissions = True + ac_bean.insert() msgprint(_("Created Group ") + ac) @@ -109,8 +110,8 @@ class DocType(TransactionBase): parent_account = self.get_parent_account(abbr) if not sql("select name from tabAccount where name=%s", (self.doc.name + " - " + abbr)): - - ac = add_ac({ + ac_bean = webnotes.bean({ + "doctype": "Account", 'account_name': self.doc.name, 'parent_account': parent_account, 'group_or_ledger':'Ledger', @@ -119,8 +120,12 @@ class DocType(TransactionBase): 'tax_rate': '0', 'master_type': 'Supplier', 'master_name': self.doc.name, + "freeze_account": "No" }) - msgprint(_("Created Account Head: ") + ac) + ac_bean.ignore_permissions = True + ac_bean.insert() + + msgprint(_("Created Account Head: ") + ac_bean.doc.name) else: self.check_parent_account(parent_account, abbr) else : diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index 72e12b7942..65ac865304 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -115,18 +115,20 @@ class DocType(TransactionBase): if not webnotes.conn.exists("Account", (self.doc.name + " - " + abbr)): parent_account = self.get_receivables_group() # create - from accounts.utils import add_ac - ac = add_ac({ - 'account_name':self.doc.name, + ac_bean = webnotes.bean({ + "doctype": "Account", + 'account_name': self.doc.name, 'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company, - 'account_type':'', - 'tax_rate':'0', 'master_type':'Customer', - 'master_name':self.doc.name + 'master_name':self.doc.name, + "freeze_account": "No" }) - msgprint("Account Head: %s created" % ac) + ac_bean.ignore_permissions = True + ac_bean.insert() + + msgprint("Account Head: %s created" % ac_bean.doc.name) else : msgprint("Please Select Company under which you want to create account head") diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py index 9863d7d28b..2564503833 100644 --- a/setup/doctype/company/company.py +++ b/setup/doctype/company/company.py @@ -222,7 +222,6 @@ class DocType: # Create default cost center # --------------------------------------------------- def create_default_cost_center(self): - from accounts.utils import add_cc cc_list = [ { 'cost_center_name':'Root', @@ -244,7 +243,10 @@ class DocType: } ] for cc in cc_list: - add_cc(cc) + cc.update({"doctype": "Cost Center"}) + cc_bean = webnotes.bean(cc) + cc_bean.ignore_permissions = True + cc_bean.insert() webnotes.conn.set_value("Company", self.doc.name, "cost_center", "Default CC Ledger - " + self.doc.abbr) From 0865f606735715b80ee4abb359cc30dfebf5083a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 11 Jun 2013 17:48:59 +0530 Subject: [PATCH 13/13] [chart of accounts/cost center] [fix] check permission before enabling add child --- accounts/page/accounts_browser/accounts_browser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/page/accounts_browser/accounts_browser.js b/accounts/page/accounts_browser/accounts_browser.js index 2e8cc820a6..3541fcbf1f 100644 --- a/accounts/page/accounts_browser/accounts_browser.js +++ b/accounts/page/accounts_browser/accounts_browser.js @@ -131,7 +131,7 @@ erpnext.AccountsChart = Class.extend({ if (wn.model.can_read(this.ctype) !== -1) { node_links.push('Edit'); } - if (data.expandable) { + if (data.expandable && wn.boot.profile.in_create.indexOf(this.ctype) !== -1) { node_links.push('Add Child'); } else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) { node_links.push('View Ledger');