blob: 30a40da7ba533a973874f132072fc4f950d63ddf [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()
Nabin Hait2bd37772013-07-08 19:00:29 +0530301
302 def validate_with_previous_doc(self, source_dt, ref):
303 for key, val in ref.items():
304 ref_doc = {}
305 for d in self.doclist.get({"doctype": source_dt}):
Nabin Hait253de852013-07-09 11:36:00 +0530306 if d.fields.get(val["ref_dn_field"]):
Nabin Hait2bd37772013-07-08 19:00:29 +0530307 ref_doc.setdefault(key, d.fields[val["ref_dn_field"]])
308
309 if val.get("is_child_table"):
310 self.compare_values(ref_doc, val["compare_fields"], d)
311 else:
312 self.compare_values(ref_doc, val["compare_fields"])
313
314 def compare_values(self, ref_doc, fields, doc=None):
315 for ref_doctype, ref_docname in ref_doc.items():
316 prevdoc_values = webnotes.conn.get_value(ref_doctype, ref_docname,
317 [d[0] for d in fields], as_dict=1)
318
319 for field, condition in fields:
320 self.validate_value(field, condition, prevdoc_values[field], doc)
Anand Doshi99100a42013-07-04 17:13:53 +0530321
322def get_default_address_and_contact(party_field, party_name, fetch_shipping_address=False):
323 out = {}
324
325 # get addresses
326 billing_address = get_address_dict(party_field, party_name)
327 if billing_address:
328 out[party_field + "_address"] = billing_address["name"]
329 out["address_display"] = get_address_display(billing_address)
330 else:
331 out[party_field + "_address"] = out["address_display"] = None
332
333 if fetch_shipping_address:
334 shipping_address = get_address_dict(party_field, party_name, is_shipping_address=True)
335 if shipping_address:
336 out["shipping_address_name"] = shipping_address["name"]
337 out["shipping_address"] = get_address_display(shipping_address)
338 else:
339 out["shipping_address_name"] = out["shipping_address"] = None
340
341 # get contact
342 if party_field == "lead":
343 out["customer_address"] = out.get("lead_address")
344 out.update(map_lead_fields(party_name))
345 else:
346 out.update(map_contact_fields(party_field, party_name))
347
348 return out
349
350def get_address_dict(party_field, party_name, is_shipping_address=None):
351 order_by = "is_shipping_address desc, is_primary_address desc, name asc" if \
352 is_shipping_address else "is_primary_address desc, name asc"
353
354 address = webnotes.conn.sql("""select * from `tabAddress` where `%s`=%s order by %s
355 limit 1""" % (party_field, "%s", order_by), party_name, as_dict=True,
356 update={"doctype": "Address"})
357
358 return address[0] if address else None
Anand Doshiedbf3e12013-07-02 11:40:16 +0530359
360def get_address_display(address_dict):
Anand Doshi99100a42013-07-04 17:13:53 +0530361 def _prepare_for_display(a_dict, sequence):
362 display = ""
363 for separator, fieldname in sequence:
364 if a_dict.get(fieldname):
365 display += separator + a_dict.get(fieldname)
366
367 return display.strip()
368
Anand Doshiedbf3e12013-07-02 11:40:16 +0530369 meta = webnotes.get_doctype("Address")
370 address_sequence = (("", "address_line1"), ("\n", "address_line2"), ("\n", "city"),
371 ("\n", "state"), ("\n" + meta.get_label("pincode") + ": ", "pincode"), ("\n", "country"),
372 ("\n" + meta.get_label("phone") + ": ", "phone"), ("\n" + meta.get_label("fax") + ": ", "fax"))
373
Anand Doshi99100a42013-07-04 17:13:53 +0530374 return _prepare_for_display(address_dict, address_sequence)
375
376def map_lead_fields(party_name):
377 out = {}
378 for fieldname in ["contact_display", "contact_email", "contact_mobile", "contact_phone"]:
379 out[fieldname] = None
380
381 lead = webnotes.conn.sql("""select * from `tabLead` where name=%s""", party_name, as_dict=True)
382 if lead:
383 lead = lead[0]
384 out.update({
385 "contact_display": lead.get("lead_name"),
386 "contact_email": lead.get("email_id"),
387 "contact_mobile": lead.get("mobile_no"),
388 "contact_phone": lead.get("phone"),
389 })
390
391 return out
392
393def map_contact_fields(party_field, party_name):
394 out = {}
395 for fieldname in ["contact_person", "contact_display", "contact_email",
396 "contact_mobile", "contact_phone", "contact_designation", "contact_department"]:
397 out[fieldname] = None
398
399 contact = webnotes.conn.sql("""select * from `tabContact` where `%s`=%s
400 order by is_primary_contact desc, name asc limit 1""" % (party_field, "%s"),
401 (party_name,), as_dict=True)
402 if contact:
403 contact = contact[0]
404 out.update({
405 "contact_person": contact.get("name"),
406 "contact_display": " ".join(filter(None,
407 [contact.get("first_name"), contact.get("last_name")])),
408 "contact_email": contact.get("email_id"),
409 "contact_mobile": contact.get("mobile_no"),
410 "contact_phone": contact.get("phone"),
411 "contact_designation": contact.get("designation"),
412 "contact_department": contact.get("department")
413 })
414
415 return out
416
417def get_address_territory(address_doc):
418 territory = None
419 for fieldname in ("city", "state", "country"):
420 value = address_doc.fields.get(fieldname)
421 if value:
422 territory = webnotes.conn.get_value("Territory", value.strip())
423 if territory:
424 break
425
426 return territory
Anand Doshi1dde46a2013-05-15 21:15:57 +0530427
428def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
429 """common validation for currency and price list currency"""
430 if conversion_rate == 0:
431 msgprint(conversion_rate_label + _(' cannot be 0'), raise_exception=True)
432
433 company_currency = webnotes.conn.get_value("Company", company, "default_currency")
434
435 # parenthesis for 'OR' are necessary as we want it to evaluate as
436 # mandatory valid condition and (1st optional valid condition
437 # or 2nd optional valid condition)
438 valid_conversion_rate = (conversion_rate and
439 ((currency == company_currency and conversion_rate == 1.00)
440 or (currency != company_currency and conversion_rate != 1.00)))
441
442 if not valid_conversion_rate:
443 msgprint(_('Please enter valid ') + conversion_rate_label + (': ')
444 + ("1 %s = [?] %s" % (currency, company_currency)),
445 raise_exception=True)
446
447def validate_item_fetch(args, item):
448 from stock.utils import validate_end_of_life
449 validate_end_of_life(item.name, item.end_of_life)
450
451 # validate company
452 if not args.company:
453 msgprint(_("Please specify Company"), raise_exception=True)
454
Anand Doshif3096132013-05-21 19:35:06 +0530455def validate_currency(args, item, meta=None):
Anand Doshifc777182013-05-27 19:29:07 +0530456 from webnotes.model.meta import get_field_precision
Anand Doshif3096132013-05-21 19:35:06 +0530457 if not meta:
458 meta = webnotes.get_doctype(args.doctype)
Anand Doshifc777182013-05-27 19:29:07 +0530459
Anand Doshif3096132013-05-21 19:35:06 +0530460 # validate conversion rate
Anand Doshi1dde46a2013-05-15 21:15:57 +0530461 if meta.get_field("currency"):
Anand Doshi1dde46a2013-05-15 21:15:57 +0530462 validate_conversion_rate(args.currency, args.conversion_rate,
463 meta.get_label("conversion_rate"), args.company)
Anand Doshifc777182013-05-27 19:29:07 +0530464
465 # round it
466 args.conversion_rate = flt(args.conversion_rate,
Anand Doshie961af42013-05-31 14:30:46 +0530467 get_field_precision(meta.get_field("conversion_rate"),
468 webnotes._dict({"fields": args})))
Anand Doshi1dde46a2013-05-15 21:15:57 +0530469
Anand Doshif3096132013-05-21 19:35:06 +0530470 # validate price list conversion rate
471 if meta.get_field("price_list_currency") and args.price_list_name and \
472 args.price_list_currency:
473 validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
Anand Doshifc777182013-05-27 19:29:07 +0530474 meta.get_label("plc_conversion_rate"), args.company)
475
476 # round it
477 args.plc_conversion_rate = flt(args.plc_conversion_rate,
Anand Doshie961af42013-05-31 14:30:46 +0530478 get_field_precision(meta.get_field("plc_conversion_rate"),
479 webnotes._dict({"fields": args})))
Anand Doshi097ac352013-06-10 15:38:31 +0530480
Anand Doshi11d31132013-06-17 12:51:36 +0530481def delete_events(ref_type, ref_name):
482 webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
Anand Doshib5fd7882013-06-17 12:55:05 +0530483 where ref_type=%s and ref_name=%s""", (ref_type, ref_name)), for_reload=True)