Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

133 righe
4.3 KiB

  1. :mod:`doc` --- Document (ORM)
  2. =============================
  3. .. module:: doc
  4. :synopsis: Document (ORM) Module
  5. .. function:: get(dt, dn=''):
  6. Returns a doclist containing the main record and all child records
  7. Document object
  8. ---------------
  9. .. class:: Document(doctype = '', name = '', fielddata = {})
  10. The `Document` class represents the basic Object-Relational Mapper (ORM). The object type is defined by
  11. `DocType` and the object ID is represented by `name`::
  12. Please note the anamoly in the Web Notes Framework that `ID` is always called as `name`
  13. If both `doctype` and `name` are specified in the constructor, then the object is loaded from the database.
  14. If only `doctype` is given, then the object is not loaded
  15. If `fielddata` is specfied, then the object is created from the given dictionary.
  16. **Note 1:**
  17. The getter and setter of the object are overloaded to map to the fields of the object that
  18. are loaded when it is instantiated.
  19. For example: doc.name will be the `name` field and doc.owner will be the `owner` field
  20. **Note 2 - Standard Fields:**
  21. * `name`: ID / primary key
  22. * `owner`: creator of the record
  23. * `creation`: datetime of creation
  24. * `modified`: datetime of last modification
  25. * `modified_by` : last updating user
  26. * `docstatus` : Status 0 - Saved, 1 - Submitted, 2- Cancelled
  27. * `parent` : if child (table) record, this represents the parent record
  28. * `parenttype` : type of parent record (if any)
  29. * `parentfield` : table fieldname of parent record (if any)
  30. * `idx` : Index (sequence) of the child record
  31. .. attribute:: fields
  32. Dictionary containing the properties of the record. This dictionary is mapped to the getter and setter
  33. .. method:: save(new=0, check_links=1, ignore_fields=0)
  34. Saves the current record in the database. If new = 1, creates a new instance of the record.
  35. Also clears temperory fields starting with `__`
  36. * if check_links is set, it validates all `Link` fields
  37. * if ignore_fields is sets, it does not throw an exception for any field that does not exist in the
  38. database table
  39. .. method:: clear_table(doclist, tablefield, save=0)
  40. Clears the child records from the given `doclist` for a particular `tablefield`
  41. .. method:: addchild(self, fieldname, childtype = '', local=0, doclist=None)
  42. Returns a child record of the give `childtype`.
  43. * if local is set, it does not save the record
  44. * if doclist is passed, it append the record to the doclist
  45. Standard methods for API
  46. ------------------------
  47. .. function:: addchild(parent, fieldname, childtype = '', local=0, doclist=None):
  48. Create a child record to the parent doc.
  49. Example::
  50. c = Document('Contact','ABC')
  51. d = addchild(c, 'contact_updates', 'Contact Update', local = 1)
  52. d.last_updated = 'Phone call'
  53. d.save(1)
  54. .. function:: removechild(d, is_local = 0)
  55. Sets the docstatus of the object d to 2 (deleted) and appends an 'old_parent:' to the parent name
  56. Naming
  57. ------
  58. .. function:: make_autoname(key, doctype='')
  59. Creates an autoname from the given key:
  60. **Autoname rules:**
  61. * The key is separated by '.'
  62. * '####' represents a series. The string before this part becomes the prefix:
  63. Example: ABC.#### creates a series ABC0001, ABC0002 etc
  64. * 'MM' represents the current month
  65. * 'YY' and 'YYYY' represent the current year
  66. *Example:*
  67. * DE/./.YY./.MM./.##### will create a series like
  68. DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series
  69. Inheritance
  70. -----------
  71. .. class:: BaseDocType:
  72. The framework supports simple inheritance using the BaseDocType class.
  73. It creates the base object and saves it in the property `super`. The getter then tries to retrive the
  74. property from the `super` object if it exsits before retrieving it from the current record.
  75. Example
  76. -------
  77. Open an existing Contact::
  78. c = Document('Contact', 'ABC')
  79. c.phone_number = '233-3432'
  80. c.save()
  81. Create a new Contact::
  82. c = Document('Contact')
  83. c.name = 'XYZ'
  84. c.phone_number = '342-3423'
  85. c.email_id = 'xyz@foo.com'
  86. c.save(new = 1)