您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

100 行
3.2 KiB

  1. Server Side Cookbook
  2. ====================
  3. Standard Patterns for server side scripts
  4. Create a name by using a prefix selected by the user
  5. ----------------------------------------------------
  6. You can create a field "naming_series" of type Select and give Options. Then you can write the autoname function
  7. as follows::
  8. # Autoname
  9. def autoname(self):
  10. self.doc.name = make_autoname(self.doc.naming_series+'.#####')
  11. Stop duplicate entries in a child table based on a key
  12. ------------------------------------------------------
  13. For example, your key is item_code. Call this method from the validate method::
  14. # Does not allow same item code to be entered twice
  15. def validate_for_items(self):
  16. check_list=[]
  17. for d in getlist(self.doclist,'quotation_details'):
  18. if d.item_code in check_list:
  19. msgprint("Oops! Item %s has been entered twice." % d.item_code)
  20. raise Exception
  21. else:
  22. check_list.append(cstr(d.item_code))
  23. Add an event to the calendar
  24. ----------------------------
  25. Add an event to the calendar on saving::
  26. # Add to Calendar
  27. def add_calendar_event(self):
  28. ev = Document('Event')
  29. ev.description = self.doc.description
  30. ev.event_date = self.doc.contact_date
  31. ev.event_hour = '10:00'
  32. ev.event_type = 'Private'
  33. ev.ref_type = 'Enquiry'
  34. ev.ref_name = self.doc.name
  35. ev.save(1)
  36. # invite users (Sales People) to the event
  37. user_lst.append(self.doc.owner)
  38. 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)
  39. if chk:
  40. user_lst.append(chk[0][0])
  41. for d in user_lst:
  42. ch = addchild(ev, 'event_individuals', 'Event User', 0)
  43. ch.person = d
  44. ch.save(1)
  45. # on_udpate method
  46. def on_update(self):
  47. # Add to calendar
  48. if self.doc.contact_date and self.doc.contact_date_ref != self.doc.contact_date:
  49. if self.doc.contact_by:
  50. self.add_calendar_event()
  51. set(self.doc, 'contact_date_ref',self.doc.contact_date)
  52. Send HTML Email based on certain condition
  53. ------------------------------------------
  54. Email can be sent using the sendmail method. In this message, we send an email when the
  55. quantity of a certain item falls below the minimum inventory level::
  56. def check_min_inventory_level(self):
  57. if self.doc.minimum_inventory_level:
  58. total_qty = sql("select sum(projected_qty) from tabBin where item_code = %s",self.doc.name)
  59. if flt(total_qty) < flt(self.doc.minimum_inventory_level):
  60. msgprint("Minimum inventory level for item %s is reached", self.doc.name)
  61. send_to = []
  62. send = sql("select t1.email from `tabProfile` t1,`tabUserRole` t2 where t2.role IN ('Material Master Manager','Purchase Manager') and t2.parent = t1.name")
  63. for d in send:
  64. send_to.append(d[0])
  65. msg = '''Minimum Inventory Level Reached
  66. Item Code: %s
  67. Item Name: %s
  68. Minimum Inventory Level: %s
  69. Total Available Qty: %s
  70. ''' % (self.doc.item_code, self.doc.item_name, self.doc.minimum_inventory_level, total_qty)
  71. sendmail(send_to, sender='automail@webnotestech.com', subject='Minimum Inventory Level Reached', parts=[['text/plain', msg]])