This is the base class that every kind of model inherits. It defines common attributes of all models.
Class attributes are:
It contains the a unique name to reference the model throughout the platform.
It contains a dictionary with method name as key and an instance of trytond.rpc.RPC as value.
It contains a dictionary mapping keywords to an error message. By way of example:
_error_messages = {
'recursive_categories': 'You can not create recursive categories!',
'wrong_name': 'You can not use " / " in name field!'
}
It contains the name of the field used as name of records. The default value is ‘name’.
The definition of the field id of records.
Class methods:
Setup the class before adding into the trytond.pool.Pool.
Setup the class after added into the trytond.pool.Pool.
Registers the model in ir.model and ir.model.field.
Raises an exception that will be displayed as an error message in the client. error is the key of the error message in _error_messages and error_args is the arguments for the “%”-based substitution of the error message. There is the same parameter for an additional description. The boolean raise_exception can be set to False to retrieve the error message strings.
Raises an exception that will be displayed as a warning message on the client, if the user has not yet bypassed it. warning_name is used to uniquely identify the warning. Others parameters are like in Model.raise_user_error().
Warning
It requires that the cursor will be commited as it stores state of the warning states by users.
Returns a dictionary with the default values for each field in fields_names. Default values are defined by the returned value of each instance method with the pattern default_`field_name`(). with_rec_name allow to add rec_name value for each many2one field.
Return the definition of each field on the model.
Instance methods:
Returns the list of changes by calling on_change method of each field.
Returns the new values of all fields by calling on_change_with method of each field.
This method is called by the client to validate the instance.
It adds requirements to display a view of the model in the client.
Class attributes:
It contains a dictionary with button name as key and the states dictionary for the button. This states dictionary will be used to generate the views containing the button.
Static methods:
Decorate button method to check group access.
Same as ModelView.button() but return the action id of the XML id action.
Same as ModelView.button() but for button that change values of the fields on client side (similar to on_change).
Warning
Only on instance methods.
Class methods:
Return a view definition used by the client. The definition is:
{
'model': model name,
'type': view type,
'view_id': view id,
'arch': XML description,
'fields': {
field name: {
...
},
},
'field_childs': field for tree,
}
Returns the window title used by the client for the specific view type.
Returns a list of XPath, attribute and value. Each element from the XPath will get the attribute set with the JSON encoded value.
It adds storage capability.
Class attributes are:
The definition of the trytond.model.fields.Many2One field create_uid of records. It contains the id of the user who creates the record.
The definition of the trytond.model.fields.DateTime field create_date of records. It contains the datetime of the creation of the record.
The definition of the trytond.model.fields.Many2One field write_uid of the records. It contains the id of the last user who writes on the record.
The definition of the trytond.model.fields.DateTime field write_date of the records. It contains the datetime of the last write on the record.
The definition of the trytond.model.fields.Function field rec_name. It is used in the client to display the records with a single string.
Warning
Deprecated, use trytond.model.ModelStorage.validate instead.
The list of constraints that each record must respect. The definition is:
[ (‘function name’, ‘error keyword’), ... ]
where function name is the name of an instance or a class method of the which must return a boolean (False when the constraint is violated) and error keyword is a key of Model._error_messages.
Static methods:
Return the default value for create_uid.
Return the default value for create_date.
Class methods:
Create records. vlist is list of dictionaries with fields names as key and created values as value and return the list of new instances.
Trigger create actions. It will call actions defined in ir.trigger if on_create is set and condition is true.
Return a list of values for the ids. If fields_names is set, there will be only values for these fields otherwise it will be for all fields.
Write values on the list of records. values is a dictionary with fields names as key and writen values as value.
Return eligible records for write actions by triggers. This dictionary is to pass to trigger_write().
Trigger write actions. It will call actions defined in ir.trigger if on_write is set and condition was false before write() and true after.
Delete records.
Trigger delete actions. It will call actions defined in ir.trigger if on_delete is set and condition is true.
Duplicate the records. default is a dictionary of default value for the created records.
Return a list of records that match the domain.
Call search() and read() at once. Useful for the client to reduce the number of calls.
Searcher for the trytond.model.fields.Function field rec_name.
Yield tuples (record, name, icon) for records matching text. It is used for the global search.
Return a list of record instance for the ids.
Return a list of list of values for each records. The list of values follows fields_names. Relational fields are defined with / at any depth. Descriptor on fields are available by appending . and the name of the method on the field that returns the descriptor.
Create records for all values in datas. The field names of values must be defined in fields_names. It returns a tuple containing: the number of records imported, the last values if failed, the exception if failed and the warning if failed.
Verify if the records are originating from XML data. It is used to prevent modification of data coming from XML files. This method must be overiden to change this behavior.
Helper method that checks if there is no recursion in the tree composed with parent as parent field name.
Validate the integrity of records after creation and modification. This method must be overridden to add validation and must raise an exception if validation fails.
Dual methods:
Save the modification made on the records.
Instance methods:
Getter for the trytond.model.fields.Function field rec_name.
It implements ModelStorage for an SQL database.
Class attributes are:
The name of the database table which is mapped to the class. If not set, the value of Model._name is used with dots converted to underscores.
A list of tuples defining the default order of the records:
[ (‘field name’, ‘ASC’), (‘other field name’, ‘DESC’), ... ]
where the first element of the tuple is a field name of the model and the second is the sort ordering as ASC for ascending or DESC for descending.
In case the field used for the first element is a fields.Many2One, it is also possible to use the dotted notation to sort on a specific field from the target record.
The name of the field (or an SQL statement) on which the records must be sorted when sorting on this model from an other model. If not set, ModelStorage._rec_name will be used.
If true, all changes on records will be stored in a history table.
A list of SQL constraints that are added on the table:
[ (‘constraint name’, ‘SQL constraint’, ‘error message key’), ... ]
Like Model._error_messages but for _sql_constraints
Class methods:
Return a SQL Table instance for the Model.
Could be overrided to use a custom SQL query instead of a table of the database. It should return a SQL FromItem.
Return a sorted list of all revisions for ids. The list is composed of the date, id and username of the revision.
Restore the record ids from history at the specified date time. Restoring a record will still generate an entry in the history table.
Warning
No access rights are verified and the records are not validated.
Restore the record ids from history before the specified date time. Restoring a record will still generate an entry in the history table.
Warning
No access rights are verified and the records are not validated.
Return a list of records that match the domain or the sql query if query is True.
A Mix-in class to handle transition check.
Class attribute:
The name of the field that will be used to check state transition.
A set containing tuples of from and to state.
Static methods:
Decorate method to filter ids for which the transition is valid and finally to update the state of the filtered ids.
Modify ModelStorage into a singleton. This means that there will be only one record of this model. It is commonly used to store configuration value.
Class methods:
Return the instance of the unique record if there is one.
A mixin for the schema of trytond.model.fields.Dict field.
Class attributes are:
The definition of the trytond.model.fields.Char field for the name of the key.
The definition of the trytond.model.fields.Char field for the string of the key.
The definition of the trytond.model.fields.Selection field for the type of the key. The available types are:
The definition of the trytond.model.fields.Integer field for the digits number when the type is float or numeric.
The definition of the trytond.model.fields.Text field to store the couple of key and label when the type is selection. The format is a key/label separated by ”:” per line.
The definition of the trytond.model.fields.Function field to return the JSON version of the selection.
Static methods:
Class methods:
Return the definition of the keys for the records.
Instance methods:
Getter for the selection_json.
A mixin to add to a Model a match method on pattern. The pattern is a dictionary with field name as key and the value to compare. The record matches the pattern if for all dictionary entries, the value of the record is equal or not defined.
Instance methods:
Return if the instance match the pattern
A mixin to create a ModelSQL which is the UNION of some ModelSQL‘s. The ids of each models are sharded to be unique.
Static methods:
Class methods:
Return a SQL expression that shards the column containing record id of model name.
Return the original instance of the record for the sharded id.
Return the SQL column that corresponds to the field on the union model.
Return the SQL table and columns to use for the UNION for the model name.