This commit is contained in:
Saurabh 2013-06-14 16:48:41 +05:30
commit 606d8383ff
19 changed files with 218 additions and 177 deletions

View File

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

View File

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

View File

@ -131,7 +131,7 @@ erpnext.AccountsChart = Class.extend({
if (wn.model.can_read(this.ctype) !== -1) {
node_links.push('<a onclick="erpnext.account_chart.open();">Edit</a>');
}
if (data.expandable) {
if (data.expandable && wn.boot.profile.in_create.indexOf(this.ctype) !== -1) {
node_links.push('<a onclick="erpnext.account_chart.new_node();">Add Child</a>');
} else if (this.ctype === 'Account' && wn.boot.profile.can_read.indexOf("GL Entry") !== -1) {
node_links.push('<a onclick="erpnext.account_chart.show_ledger();">View Ledger</a>');

View File

@ -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",

View File

@ -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 "<br>".join(webnotes.message_log) or cstr(e)
messages.append("""<p style='color: red'>%s</p>""" % (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

View File

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

View File

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

View File

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

View File

@ -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 :

View File

@ -0,0 +1,19 @@
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):
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`
where ref_type=%s and ref_name=%s""", (dt, ref_name)))

View File

@ -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",
]

View File

@ -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,30 @@ 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"}):
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()
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)))

View File

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

View File

@ -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
}

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, 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:
@ -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, force=False):
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, force)
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

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

View File

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

View File

@ -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')
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) or force:
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()