blob: 7794444e2758ad44a4ea77b81485964ed9ade4cb [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Anand Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053018import webnotes
Anand Doshi1dde46a2013-05-15 21:15:57 +053019from webnotes import msgprint, _
Anand Doshiee3d5cc2013-03-13 12:58:54 +053020from webnotes.utils import load_json, cstr, flt, now_datetime
Anand Doshi0fd99e72012-11-30 16:38:04 +053021from webnotes.model.doc import addchild
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053022
Nabin Hait0feebc12013-06-03 16:45:38 +053023from controllers.status_updater import StatusUpdater
Anand Doshi756dca72013-01-15 18:39:21 +053024
Nabin Hait0feebc12013-06-03 16:45:38 +053025class TransactionBase(StatusUpdater):
Anand Doshi99100a42013-07-04 17:13:53 +053026 def get_default_address_and_contact(self, party_field, party_name=None):
Anand Doshiedc5f2e2013-04-26 17:21:49 +053027 """get a dict of default field values of address and contact for a given party type
28 party_type can be one of: customer, supplier"""
Anand Doshi99100a42013-07-04 17:13:53 +053029 if not party_name:
30 party_name = self.doc.fields.get(party_field)
Anand Doshiedc5f2e2013-04-26 17:21:49 +053031
Anand Doshi99100a42013-07-04 17:13:53 +053032 return get_default_address_and_contact(party_field, party_name,
33 fetch_shipping_address=True if self.meta.get_field("shipping_address_name") else False)
34
35 def get_customer_defaults(self):
36 out = self.get_default_address_and_contact("customer")
37
38 customer = webnotes.doc("Customer", self.doc.customer)
39 for f in ['customer_name', 'customer_group', 'territory']:
40 out[f] = customer.fields.get(f)
Anand Doshiedc5f2e2013-04-26 17:21:49 +053041
Anand Doshi99100a42013-07-04 17:13:53 +053042 # fields prepended with default in Customer doctype
43 for f in ['sales_partner', 'commission_rate', 'currency', 'price_list']:
44 out[f] = customer.fields.get("default_" + f)
45
46 return out
47
48 def set_customer_defaults(self):
49 """
50 For a customer:
51 1. Sets default address and contact
52 2. Sets values like Territory, Customer Group, etc.
53 3. Clears existing Sales Team and fetches the one mentioned in Customer
54 """
55 customer_defaults = self.get_customer_defaults()
56
57 # hack! TODO - add shipping_address_field in Delivery Note
58 if self.doc.doctype == "Delivery Note":
59 customer_defaults["customer_address"] = customer_defaults["shipping_address_name"]
60 customer_defaults["address_display"] = customer_defaults["shipping_address"]
61
62 customer_defaults["price_list"] = customer_defaults["price_list"] or \
63 webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \
64 self.doc.price_list
65
66 self.doc.fields.update(customer_defaults)
67
68 if self.meta.get_field("sales_team"):
69 self.set_sales_team_for_customer()
70
71 def set_sales_team_for_customer(self):
72 from webnotes.model import default_fields
73
74 # clear table
75 self.doclist = self.doc.clear_table(self.doclist, "sales_team")
76
77 sales_team = webnotes.conn.sql("""select * from `tabSales Team`
78 where parenttype="Customer" and parent=%s""", self.doc.customer, as_dict=True)
79 for i, sales_person in enumerate(sales_team):
80 # remove default fields
81 for fieldname in default_fields:
82 if fieldname in sales_person:
83 del sales_person[fieldname]
84
85 sales_person.update({
86 "doctype": "Sales Team",
87 "parentfield": "sales_team",
88 "idx": i+1
89 })
90
91 # add child
92 self.doclist.append(sales_person)
Anand Doshiedc5f2e2013-04-26 17:21:49 +053093
Anand Doshi99100a42013-07-04 17:13:53 +053094 def get_lead_defaults(self):
95 out = self.get_default_address_and_contact("lead")
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053096
Anand Doshi99100a42013-07-04 17:13:53 +053097 lead = webnotes.conn.get_value("Lead", self.doc.lead,
98 ["territory", "company_name", "lead_name"], as_dict=True) or {}
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053099
Anand Doshi99100a42013-07-04 17:13:53 +0530100 out["territory"] = lead.get("territory")
101 out["customer_name"] = lead.get("company_name") or lead.get("lead_name")
102
103 return out
104
105 def set_lead_defaults(self):
106 self.doc.fields.update(self.get_lead_defaults())
107
108
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530109 # Get Customer Address
110 # -----------------------
111 def get_customer_address(self, args):
112 args = load_json(args)
113 address_text, address_name = self.get_address_text(address_name=args['address'])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530114 ret = {
115 'customer_address' : address_name,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530116 'address_display' : address_text,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530117 }
Anand Doshiae30e012012-10-26 15:01:22 +0530118
119 ret.update(self.get_contact_text(contact_name=args['contact']))
120
Nabin Hait06c4de82011-08-16 16:38:11 +0530121 return ret
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530122
123 # Get Address Text
124 # -----------------------
125 def get_address_text(self, customer=None, address_name=None, supplier=None, is_shipping_address=None):
126 if customer:
127 cond = customer and 'customer="%s"' % customer or 'name="%s"' % address_name
128 elif supplier:
129 cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % address_name
130 else:
131 cond = 'name="%s"' % address_name
132
133 if is_shipping_address:
Nabin Hait7f599132012-09-26 13:10:37 +0530134 details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone, fax from `tabAddress` where %s and docstatus != 2 order by is_shipping_address desc, is_primary_address desc limit 1" % cond, as_dict = 1)
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530135 else:
Nabin Hait65353652012-03-21 17:07:42 +0530136 details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone, fax from `tabAddress` where %s and docstatus != 2 order by is_primary_address desc limit 1" % cond, as_dict = 1)
Anand Doshi99100a42013-07-04 17:13:53 +0530137
138 address_display = ""
139
140 if details:
141 address_display = get_address_display(details[0])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530142
143 address_name = details and details[0]['name'] or ''
Anand Doshi99100a42013-07-04 17:13:53 +0530144
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530145 return address_display, address_name
146
147 # Get Contact Text
148 # -----------------------
149 def get_contact_text(self, customer=None, contact_name=None, supplier=None):
150 if customer:
151 cond = customer and 'customer="%s"' % customer or 'name="%s"' % contact_name
152 elif supplier:
153 cond = supplier and 'supplier="%s"' % supplier or 'name="%s"' % contact_name
154 else:
155 cond = 'name="%s"' % contact_name
156
Anand Doshi74d1b652012-01-27 12:25:09 +0530157 details = webnotes.conn.sql("select name, first_name, last_name, email_id, phone, mobile_no, department, designation from `tabContact` where %s and docstatus != 2 order by is_primary_contact desc limit 1" % cond, as_dict = 1)
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530158
159 extract = lambda x: details and details[0] and details[0].get(x,'') or ''
Anand Doshi97bd3662012-01-17 14:22:09 +0530160 contact_fields = [('','first_name'),(' ','last_name')]
161 contact_display = ''.join([a[0]+cstr(extract(a[1])) for a in contact_fields if extract(a[1])])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530162 if contact_display.startswith('\n'): contact_display = contact_display[1:]
163
Anand Doshiae30e012012-10-26 15:01:22 +0530164 return {
165 "contact_display": contact_display,
166 "contact_person": details and details[0]["name"] or "",
167 "contact_email": details and details[0]["email_id"] or "",
168 "contact_mobile": details and details[0]["mobile_no"] or "",
169 "contact_designation": details and details[0]["designation"] or "",
170 "contact_department": details and details[0]["department"] or "",
171 }
172
Anand Doshi99100a42013-07-04 17:13:53 +0530173 # TODO deprecate this - used only in sales_order.js
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530174 def get_shipping_address(self, name):
Nabin Hait7f599132012-09-26 13:10:37 +0530175 details = webnotes.conn.sql("select name, address_line1, address_line2, city, country, pincode, state, phone from `tabAddress` where customer = '%s' and docstatus != 2 order by is_shipping_address desc, is_primary_address desc limit 1" %(name), as_dict = 1)
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530176
Anand Doshi99100a42013-07-04 17:13:53 +0530177 address_display = ""
178 if details:
179 address_display = get_address_display(details[0])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530180
181 ret = {
182 'shipping_address_name' : details and details[0]['name'] or '',
183 'shipping_address' : address_display
184 }
Nabin Hait06c4de82011-08-16 16:38:11 +0530185 return ret
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530186
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530187 # Get Supplier Default Primary Address - first load
188 # -----------------------
189 def get_default_supplier_address(self, args):
Anand Doshi923d41d2013-05-28 17:23:36 +0530190 if isinstance(args, basestring):
191 args = load_json(args)
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530192 address_text, address_name = self.get_address_text(supplier=args['supplier'])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530193 ret = {
194 'supplier_address' : address_name,
195 'address_display' : address_text,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530196 }
Anand Doshiae30e012012-10-26 15:01:22 +0530197 ret.update(self.get_contact_text(supplier=args['supplier']))
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530198 ret.update(self.get_supplier_details(args['supplier']))
Nabin Hait06c4de82011-08-16 16:38:11 +0530199 return ret
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530200
201 # Get Supplier Address
202 # -----------------------
203 def get_supplier_address(self, args):
204 args = load_json(args)
205 address_text, address_name = self.get_address_text(address_name=args['address'])
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530206 ret = {
207 'supplier_address' : address_name,
Anand Doshif2f5c942012-07-18 20:13:52 +0530208 'address_display' : address_text,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530209 }
Anand Doshiae30e012012-10-26 15:01:22 +0530210 ret.update(self.get_contact_text(contact_name=args['contact']))
Nabin Hait06c4de82011-08-16 16:38:11 +0530211 return ret
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530212
213 # Get Supplier Details
214 # -----------------------
Anand Doshif2f5c942012-07-18 20:13:52 +0530215 def get_supplier_details(self, name):
216 supplier_details = webnotes.conn.sql("""\
217 select supplier_name, default_currency
218 from `tabSupplier`
219 where name = %s and docstatus < 2""", name, as_dict=1)
220 if supplier_details:
221 return {
222 'supplier_name': (supplier_details[0]['supplier_name']
223 or self.doc.fields.get('supplier_name')),
224 'currency': (supplier_details[0]['default_currency']
225 or self.doc.fields.get('currency')),
226 }
227 else:
228 return {}
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530229
230 # Get Sales Person Details of Customer
231 # ------------------------------------
232 def get_sales_person(self, name):
Anand Doshi8ae5ba92012-06-25 20:05:35 +0530233 self.doclist = self.doc.clear_table(self.doclist,'sales_team')
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530234 idx = 0
Anand Doshi74d1b652012-01-27 12:25:09 +0530235 for d in webnotes.conn.sql("select sales_person, allocated_percentage, allocated_amount, incentives from `tabSales Team` where parent = '%s'" % name):
Anand Doshif5d90ab2012-12-24 17:02:38 +0530236 ch = addchild(self.doc, 'sales_team', 'Sales Team', self.doclist)
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +0530237 ch.sales_person = d and cstr(d[0]) or ''
238 ch.allocated_percentage = d and flt(d[1]) or 0
239 ch.allocated_amount = d and flt(d[2]) or 0
240 ch.incentives = d and flt(d[3]) or 0
241 ch.idx = idx
242 idx += 1
Nabin Hait41cc3272012-04-30 14:36:18 +0530243
Rushabh Mehta35c017a2012-11-30 10:57:28 +0530244 def load_notification_message(self):
245 dt = self.doc.doctype.lower().replace(" ", "_")
246 if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
247 self.doc.fields["__notification_message"] = \
248 webnotes.conn.get_value("Notification Control", None, dt + "_message")
249
Rushabh Mehtac4e7b682012-11-26 18:18:10 +0530250 def add_communication_list(self):
251 # remove communications if present
252 self.doclist = webnotes.doclist(self.doclist).get({
253 "doctype": ["!=", "Communcation"]})
254
255 comm_list = webnotes.conn.sql("""select * from tabCommunication
256 where %s=%s order by modified desc limit 20""" \
257 % (self.doc.doctype.replace(" ", "_").lower(), "%s"),
Anand Doshi060d9242013-06-12 17:40:36 +0530258 self.doc.name, as_dict=1, update={"doctype":"Communication"})
Rushabh Mehtac4e7b682012-11-26 18:18:10 +0530259
260 self.doclist.extend(webnotes.doclist([webnotes.doc(fielddata=d) \
Anand Doshiee3d5cc2013-03-13 12:58:54 +0530261 for d in comm_list]))
262
263 def validate_posting_time(self):
264 if not self.doc.posting_time:
Anand Doshiacec0222013-03-26 12:33:43 +0530265 self.doc.posting_time = now_datetime().strftime('%H:%M:%S')
Anand Doshie53a81d2013-06-10 15:15:40 +0530266
Anand Doshi670199b2013-06-10 15:38:01 +0530267 def add_calendar_event(self, opts, force=False):
Anand Doshie53a81d2013-06-10 15:15:40 +0530268 if self.doc.contact_by != cstr(self._prev.contact_by) or \
Anand Doshi670199b2013-06-10 15:38:01 +0530269 self.doc.contact_date != cstr(self._prev.contact_date) or force:
Anand Doshie53a81d2013-06-10 15:15:40 +0530270
271 self.delete_events()
272 self._add_calendar_event(opts)
273
274 def delete_events(self):
275 webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
276 where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name)))
277
278 def _add_calendar_event(self, opts):
279 opts = webnotes._dict(opts)
280
281 if self.doc.contact_date:
282 event_doclist = [{
283 "doctype": "Event",
284 "owner": opts.owner or self.doc.owner,
285 "subject": opts.subject,
286 "description": opts.description,
287 "starts_on": self.doc.contact_date + " 10:00:00",
288 "event_type": "Private",
289 "ref_type": self.doc.doctype,
290 "ref_name": self.doc.name
291 }]
292
293 if webnotes.conn.exists("Profile", self.doc.contact_by):
294 event_doclist.append({
295 "doctype": "Event User",
296 "parentfield": "event_individuals",
297 "person": self.doc.contact_by
298 })
299
300 webnotes.bean(event_doclist).insert()
Anand Doshi99100a42013-07-04 17:13:53 +0530301
302def get_default_address_and_contact(party_field, party_name, fetch_shipping_address=False):
303 out = {}
304
305 # get addresses
306 billing_address = get_address_dict(party_field, party_name)
307 if billing_address:
308 out[party_field + "_address"] = billing_address["name"]
309 out["address_display"] = get_address_display(billing_address)
310 else:
311 out[party_field + "_address"] = out["address_display"] = None
312
313 if fetch_shipping_address:
314 shipping_address = get_address_dict(party_field, party_name, is_shipping_address=True)
315 if shipping_address:
316 out["shipping_address_name"] = shipping_address["name"]
317 out["shipping_address"] = get_address_display(shipping_address)
318 else:
319 out["shipping_address_name"] = out["shipping_address"] = None
320
321 # get contact
322 if party_field == "lead":
323 out["customer_address"] = out.get("lead_address")
324 out.update(map_lead_fields(party_name))
325 else:
326 out.update(map_contact_fields(party_field, party_name))
327
328 return out
329
330def get_address_dict(party_field, party_name, is_shipping_address=None):
331 order_by = "is_shipping_address desc, is_primary_address desc, name asc" if \
332 is_shipping_address else "is_primary_address desc, name asc"
333
334 address = webnotes.conn.sql("""select * from `tabAddress` where `%s`=%s order by %s
335 limit 1""" % (party_field, "%s", order_by), party_name, as_dict=True,
336 update={"doctype": "Address"})
337
338 return address[0] if address else None
Anand Doshiedbf3e12013-07-02 11:40:16 +0530339
340def get_address_display(address_dict):
Anand Doshi99100a42013-07-04 17:13:53 +0530341 def _prepare_for_display(a_dict, sequence):
342 display = ""
343 for separator, fieldname in sequence:
344 if a_dict.get(fieldname):
345 display += separator + a_dict.get(fieldname)
346
347 return display.strip()
348
Anand Doshiedbf3e12013-07-02 11:40:16 +0530349 meta = webnotes.get_doctype("Address")
350 address_sequence = (("", "address_line1"), ("\n", "address_line2"), ("\n", "city"),
351 ("\n", "state"), ("\n" + meta.get_label("pincode") + ": ", "pincode"), ("\n", "country"),
352 ("\n" + meta.get_label("phone") + ": ", "phone"), ("\n" + meta.get_label("fax") + ": ", "fax"))
353
Anand Doshi99100a42013-07-04 17:13:53 +0530354 return _prepare_for_display(address_dict, address_sequence)
355
356def map_lead_fields(party_name):
357 out = {}
358 for fieldname in ["contact_display", "contact_email", "contact_mobile", "contact_phone"]:
359 out[fieldname] = None
360
361 lead = webnotes.conn.sql("""select * from `tabLead` where name=%s""", party_name, as_dict=True)
362 if lead:
363 lead = lead[0]
364 out.update({
365 "contact_display": lead.get("lead_name"),
366 "contact_email": lead.get("email_id"),
367 "contact_mobile": lead.get("mobile_no"),
368 "contact_phone": lead.get("phone"),
369 })
370
371 return out
372
373def map_contact_fields(party_field, party_name):
374 out = {}
375 for fieldname in ["contact_person", "contact_display", "contact_email",
376 "contact_mobile", "contact_phone", "contact_designation", "contact_department"]:
377 out[fieldname] = None
378
379 contact = webnotes.conn.sql("""select * from `tabContact` where `%s`=%s
380 order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"),
381 (party_name,), as_dict=True)
382 if contact:
383 contact = contact[0]
384 out.update({
385 "contact_person": contact.get("name"),
386 "contact_display": " ".join(filter(None,
387 [contact.get("first_name"), contact.get("last_name")])),
388 "contact_email": contact.get("email_id"),
389 "contact_mobile": contact.get("mobile_no"),
390 "contact_phone": contact.get("phone"),
391 "contact_designation": contact.get("designation"),
392 "contact_department": contact.get("department")
393 })
394
395 return out
396
397def get_address_territory(address_doc):
398 territory = None
399 for fieldname in ("city", "state", "country"):
400 value = address_doc.fields.get(fieldname)
401 if value:
402 territory = webnotes.conn.get_value("Territory", value.strip())
403 if territory:
404 break
405
406 return territory
Anand Doshi1dde46a2013-05-15 21:15:57 +0530407
408def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
409 """common validation for currency and price list currency"""
410 if conversion_rate == 0:
411 msgprint(conversion_rate_label + _(' cannot be 0'), raise_exception=True)
412
413 company_currency = webnotes.conn.get_value("Company", company, "default_currency")
414
415 # parenthesis for 'OR' are necessary as we want it to evaluate as
416 # mandatory valid condition and (1st optional valid condition
417 # or 2nd optional valid condition)
418 valid_conversion_rate = (conversion_rate and
419 ((currency == company_currency and conversion_rate == 1.00)
420 or (currency != company_currency and conversion_rate != 1.00)))
421
422 if not valid_conversion_rate:
423 msgprint(_('Please enter valid ') + conversion_rate_label + (': ')
424 + ("1 %s = [?] %s" % (currency, company_currency)),
425 raise_exception=True)
426
427def validate_item_fetch(args, item):
428 from stock.utils import validate_end_of_life
429 validate_end_of_life(item.name, item.end_of_life)
430
431 # validate company
432 if not args.company:
433 msgprint(_("Please specify Company"), raise_exception=True)
434
Anand Doshif3096132013-05-21 19:35:06 +0530435def validate_currency(args, item, meta=None):
Anand Doshifc777182013-05-27 19:29:07 +0530436 from webnotes.model.meta import get_field_precision
Anand Doshif3096132013-05-21 19:35:06 +0530437 if not meta:
438 meta = webnotes.get_doctype(args.doctype)
Anand Doshifc777182013-05-27 19:29:07 +0530439
Anand Doshif3096132013-05-21 19:35:06 +0530440 # validate conversion rate
Anand Doshi1dde46a2013-05-15 21:15:57 +0530441 if meta.get_field("currency"):
Anand Doshi1dde46a2013-05-15 21:15:57 +0530442 validate_conversion_rate(args.currency, args.conversion_rate,
443 meta.get_label("conversion_rate"), args.company)
Anand Doshifc777182013-05-27 19:29:07 +0530444
445 # round it
446 args.conversion_rate = flt(args.conversion_rate,
Anand Doshie961af42013-05-31 14:30:46 +0530447 get_field_precision(meta.get_field("conversion_rate"),
448 webnotes._dict({"fields": args})))
Anand Doshi1dde46a2013-05-15 21:15:57 +0530449
Anand Doshif3096132013-05-21 19:35:06 +0530450 # validate price list conversion rate
451 if meta.get_field("price_list_currency") and args.price_list_name and \
452 args.price_list_currency:
453 validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
Anand Doshifc777182013-05-27 19:29:07 +0530454 meta.get_label("plc_conversion_rate"), args.company)
455
456 # round it
457 args.plc_conversion_rate = flt(args.plc_conversion_rate,
Anand Doshie961af42013-05-31 14:30:46 +0530458 get_field_precision(meta.get_field("plc_conversion_rate"),
459 webnotes._dict({"fields": args})))
Anand Doshi097ac352013-06-10 15:38:31 +0530460
Anand Doshi11d31132013-06-17 12:51:36 +0530461def delete_events(ref_type, ref_name):
462 webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
Anand Doshib5fd7882013-06-17 12:55:05 +0530463 where ref_type=%s and ref_name=%s""", (ref_type, ref_name)), for_reload=True)