Merge branch 'master' of github.com:webnotes/erpnext into responsive

Conflicts:
	patches/patch_list.py
	projects/doctype/project/project.py
	utilities/transaction_base.py
This commit is contained in:
Anand Doshi
2013-06-10 15:25:07 +05:30
34 changed files with 989 additions and 114 deletions

View File

@@ -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
@@ -30,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()
@@ -55,12 +61,18 @@ class DocType(SellingController):
msgprint('Please enter valid email id.')
raise Exception
def on_update(self):
if self.doc.contact_date:
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:
@@ -71,27 +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):
# 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()
def get_sender(self, comm):
return webnotes.conn.get_value('Sales Email Settings',None,'email_id')
@@ -100,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()

View File

@@ -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()

View File

@@ -165,6 +165,12 @@ wn.module_page["Selling"] = [
"label":wn._("Item-wise Sales History"),
route: "query-report/Item-wise Sales History",
},
{
"label":wn._("Customers Not Buying Since Long Time"),
route: "query-report/Customers Not Buying Since Long Time",
doctype: "Sales Order"
},
]
}
]

View File

@@ -0,0 +1,10 @@
wn.query_reports["Customers Not Buying Since Long Time"] = {
"filters": [
{
"fieldname":"days_since_last_order",
"label": "Days Since Last Order",
"fieldtype": "Int",
"default": 60
}
]
}

View File

@@ -0,0 +1,75 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from webnotes.utils import getdate, cint
def execute(filters=None):
if not filters: filters ={}
days_since_last_order = filters.get("days_since_last_order")
if cint(days_since_last_order) <= 0:
webnotes.msgprint("Please mention positive value in 'Days Since Last Order' field",raise_exception=1)
columns = get_columns()
customers = get_so_details()
data = []
for cust in customers:
if cust[8] >= days_since_last_order:
cust.insert(7,get_last_so_amt(cust[0]))
data.append(cust)
return columns, data
def get_so_details():
return webnotes.conn.sql("""select
cust.name,
cust.customer_name,
cust.territory,
cust.customer_group,
count(distinct(so.name)) as 'num_of_order',
sum(net_total) as 'total_order_value',
sum(if(so.status = "Stopped",
so.net_total * so.per_delivered/100,
so.net_total)) as 'total_order_considered',
max(so.transaction_date) as 'last_sales_order_date',
DATEDIFF(CURDATE(), max(so.transaction_date)) as 'days_since_last_order'
from `tabCustomer` cust, `tabSales Order` so
where cust.name = so.customer and so.docstatus = 1
group by cust.name
order by 'days_since_last_order' desc """,as_list=1)
def get_last_so_amt(customer):
res = webnotes.conn.sql("""select net_total from `tabSales Order`
where customer ='%(customer)s' and docstatus = 1 order by transaction_date desc
limit 1""" % {'customer':customer})
return res and res[0][0] or 0
def get_columns():
return [
"Customer:Link/Customer:120",
"Customer Name:Data:120",
"Territory::120",
"Customer Group::120",
"Number of Order::120",
"Total Order Value:Currency:120",
"Total Order Considered:Currency:160",
"Last Order Amount:Currency:160",
"Last Sales Order Date:Date:160",
"Days Since Last Order::160"
]

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-07 12:27:07",
"docstatus": 0,
"modified": "2013-06-07 12:27:07",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Sales Order",
"report_name": "Customers Not Buying Since Long Time ",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Customers Not Buying Since Long Time"
}
]