The Document class represents the basic Object-Relational Mapper (ORM). The object type is defined by DocType and the object ID is represented by name:
Please note the anamoly in the Web Notes Framework that `ID` is always called as `name`
If both doctype and name are specified in the constructor, then the object is loaded from the database. If only doctype is given, then the object is not loaded If fielddata is specfied, then the object is created from the given dictionary.
Note 1:
The getter and setter of the object are overloaded to map to the fields of the object that are loaded when it is instantiated.
For example: doc.name will be the name field and doc.owner will be the owner field
Note 2 - Standard Fields:
- name: ID / primary key
- owner: creator of the record
- creation: datetime of creation
- modified: datetime of last modification
- modified_by : last updating user
- docstatus : Status 0 - Saved, 1 - Submitted, 2- Cancelled
- parent : if child (table) record, this represents the parent record
- parenttype : type of parent record (if any)
- parentfield : table fieldname of parent record (if any)
- idx : Index (sequence) of the child record
Saves the current record in the database. If new = 1, creates a new instance of the record. Also clears temperory fields starting with __
Returns a child record of the give childtype.
Create a child record to the parent doc.
Example:
c = Document('Contact','ABC')
d = addchild(c, 'contact_updates', 'Contact Update', local = 1)
d.last_updated = 'Phone call'
d.save(1)
Creates an autoname from the given key:
Autoname rules:
The key is separated by ‘.’
- ‘####’ represents a series. The string before this part becomes the prefix:
Example: ABC.#### creates a series ABC0001, ABC0002 etc
‘MM’ represents the current month
‘YY’ and ‘YYYY’ represent the current year
Example:
- DE/./.YY./.MM./.##### will create a series like DE/09/01/0001 where 09 is the year, 01 is the month and 0001 is the series
Open an existing Contact:
c = Document('Contact', 'ABC')
c.phone_number = '233-3432'
c.save()
Create a new Contact:
c = Document('Contact')
c.name = 'XYZ'
c.phone_number = '342-3423'
c.email_id = 'xyz@foo.com'
c.save(new = 1)