fix typos for documentation (Model chapter)
This commit is contained in:
+26
-28
@@ -4,16 +4,16 @@
|
||||
Model
|
||||
#####
|
||||
|
||||
Model is python classes that usually represents business logical or
|
||||
concepts. Such classes consist essentially of keywords, fields,
|
||||
A model is a python class that usually represent a business logic or a
|
||||
concept. Such classes consist essentially of keywords, fields,
|
||||
constraints and helper functions.
|
||||
There is different kind of Model for different purpose:
|
||||
There are different kinds of Models for different purposes:
|
||||
|
||||
* ``ModelView``: Define Model with views.
|
||||
|
||||
* ``ModelStorage``: Define Model with storage capability.
|
||||
|
||||
* ``ModelSQL``: Define ModelStorage with SQL database for storage backend.
|
||||
* ``ModelSQL``: Define ModelStorage with SQL database as storage backend.
|
||||
|
||||
* ``ModelWorkflow``: Define Model with workflow.
|
||||
|
||||
@@ -61,13 +61,13 @@ The following snippet gives a first idea of what can be done:
|
||||
'party', 'category', 'Categories')
|
||||
Party()
|
||||
|
||||
Instantiating the class register the Model class in the framework.
|
||||
Later they will be instanciate once per database and stored in the Pool.
|
||||
Instantiating the class registers the Model class in the framework.
|
||||
Later the class will be instantiated once per database and stored in the Pool.
|
||||
Model instances are essentially accessors to records.
|
||||
|
||||
Model properties defines meta-informations about the model, they are
|
||||
class attributes starting with and underscore.
|
||||
Some Model Properties are instance attributes which allow to update
|
||||
Model properties define meta-information of the model, they are
|
||||
class attributes starting with an underscore.
|
||||
Some Model Properties are instance attributes allowing to update
|
||||
them at other places in the framework.
|
||||
|
||||
.. _model:
|
||||
@@ -100,7 +100,7 @@ Model
|
||||
Search clauses
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
Simple clause are a list of condition, with an implicit ``AND``
|
||||
A simple clause is a list of conditions, with an implicit ``AND``
|
||||
operator:
|
||||
|
||||
.. highlight:: python
|
||||
@@ -110,7 +110,7 @@ operator:
|
||||
[('name', '=', 'Bob'),('age','>=', 20)]
|
||||
|
||||
|
||||
More complex clause can be made this way:
|
||||
More complex clauses can be made this way:
|
||||
|
||||
.. highlight:: python
|
||||
|
||||
@@ -122,13 +122,13 @@ More complex clause can be made this way:
|
||||
|
||||
|
||||
Where ``country`` is a ``Many2One`` field on the current field. The
|
||||
number *dots* in the left hand side of a condition is not limited, but
|
||||
number of *dots* in the left hand side of a condition is not limited, but
|
||||
the underlying relation must be a ``Many2One``.
|
||||
|
||||
Which if used in a search call on the Address model will result in
|
||||
something similar to the following sql code (the actual sql query will
|
||||
If used in a search call on the Address model this will result in
|
||||
something similar to the following sql code (the actual sql query will
|
||||
be more complex since it has to take care of the access rights of the
|
||||
user.):
|
||||
user):
|
||||
|
||||
.. highlight:: sql
|
||||
|
||||
@@ -187,8 +187,8 @@ with the same ``_name`` attribute:
|
||||
|
||||
This example shows how to define and relate a new model to an existing model.
|
||||
The example also demonstrates how to define a reflecting ``Many2One``: It's not
|
||||
possible to create the two models without using inheritance because
|
||||
each of the foreign key (``first_owner`` and ``current_car``) need the
|
||||
possible to create the two models without using inheritance, because
|
||||
each of the foreign keys (``first_owner`` and ``current_car``) needs the
|
||||
other model table.
|
||||
|
||||
|
||||
@@ -221,14 +221,14 @@ and then calling `self._reset_columns`.
|
||||
|
||||
In this example the extended model wants on_change_employee(...) to be called so it adds 'employee'
|
||||
to the on_change attribute of the employee field. Notice that only if the the field is
|
||||
modified then `self._reset_columns` is called. Also notice that a developer should try
|
||||
modified `self._reset_columns` is called. Also notice that a developer should try
|
||||
to make no assumptions about the field so that additional modules could also
|
||||
extend the same field.
|
||||
|
||||
Fields
|
||||
******
|
||||
|
||||
Fields are class attributes which a name that can not start with an underscore.
|
||||
Fields are class attributes with a name that can not start with an underscore.
|
||||
|
||||
.. _trytond.model.fields.Boolean:
|
||||
.. autoclass:: trytond.model.fields.Boolean
|
||||
@@ -331,7 +331,7 @@ Fields are class attributes which a name that can not start with an underscore.
|
||||
How to use Function fields
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Let's say that the following field is defined on the invoice model:
|
||||
Assuming the following field is defined on the invoice model:
|
||||
|
||||
.. highlight:: python
|
||||
|
||||
@@ -365,7 +365,7 @@ each id in ``ids``.
|
||||
One method to rule them all
|
||||
+++++++++++++++++++++++++++
|
||||
|
||||
The first variant of this we'll look at is defining a unique function for
|
||||
The first variant we'll look at is defining a unique function for
|
||||
several fields. Let's consider this new field which returns the total for
|
||||
the invoice lines of kind *service*:
|
||||
|
||||
@@ -421,7 +421,7 @@ Or even better:
|
||||
return res
|
||||
|
||||
|
||||
The framework is able to check if ``names`` (instead of ``name``) is
|
||||
The framework is able to check, if ``names`` (instead of ``name``) is
|
||||
used in the method definition, hence adapting the way the method is
|
||||
called.
|
||||
|
||||
@@ -449,11 +449,10 @@ to the function call:
|
||||
Search on Function fields
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
Another improvement would be to provide a search function.
|
||||
Another possible improvement can be to provide a search function.
|
||||
Indeed without it the user will not be able to search across
|
||||
invoices for a certain amount. If we forget about the
|
||||
``total_service`` field, solution could be something like the
|
||||
following:
|
||||
``total_service`` field, a solution could look like the following:
|
||||
|
||||
.. highlight:: python
|
||||
|
||||
@@ -493,13 +492,12 @@ following:
|
||||
return res
|
||||
|
||||
|
||||
One should note that such an implementation would be very slow for a large
|
||||
number of invoices.
|
||||
Note: Such an implementation would be very slow for a large number of invoices.
|
||||
|
||||
|
||||
Write on Function fields
|
||||
++++++++++++++++++++++++
|
||||
It's also possible to allow the user to write on a function field:
|
||||
It is also possible to allow the user to write on a function field:
|
||||
|
||||
.. highlight:: python
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Binary(Field):
|
||||
'''
|
||||
Define a binary field (``str``)
|
||||
Define a binary field (``str``).
|
||||
'''
|
||||
_type = 'binary'
|
||||
|
||||
@@ -19,7 +19,7 @@ class Binary(Field):
|
||||
:param ids: a list of ids
|
||||
:param model: a string with the name of the model
|
||||
:param name: a string with the name of the field
|
||||
:param values: a dictionary with the readed values
|
||||
:param values: a dictionary with the read values
|
||||
:param context: the context
|
||||
:return: a dictionary with ids as key and values as value
|
||||
'''
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Char(Field):
|
||||
'''
|
||||
Define a char field (``unicode``)
|
||||
Define a char field (``unicode``).
|
||||
'''
|
||||
_type = 'char'
|
||||
|
||||
|
||||
@@ -6,20 +6,20 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Date(Field):
|
||||
'''
|
||||
Define a date field (``date``)
|
||||
Define a date field (``date``).
|
||||
'''
|
||||
_type = 'date'
|
||||
|
||||
|
||||
class DateTime(Field):
|
||||
'''
|
||||
Define a datetime field (``datetime``)
|
||||
Define a datetime field (``datetime``).
|
||||
'''
|
||||
_type = 'datetime'
|
||||
|
||||
|
||||
class Time(Field):
|
||||
'''
|
||||
Define a time field (``time``)
|
||||
Define a time field (``time``).
|
||||
'''
|
||||
_type = 'time'
|
||||
|
||||
@@ -18,15 +18,15 @@ class Field(object):
|
||||
:param domain: A list that defines a domain constraint. See domain on
|
||||
ModelStorage.search.
|
||||
:param states: A dictionary. Possible keys are ``required``,
|
||||
``readonly`` and ``invisible``. Values are string of python
|
||||
statement that can be evaluate with record values. This allows to
|
||||
``readonly`` and ``invisible``. Values are strings of python
|
||||
statements that can be evaluated with record values. This allows to
|
||||
change dynamically the attributes of the field.
|
||||
:param priority: Give the order in which set methods are called.
|
||||
:param change_default: A boolean if ``True`` the field can be used as
|
||||
condition for custom default value.
|
||||
:param translate: A boolean if ``True`` the field is translatable.
|
||||
:param change_default: A boolean. If ``True`` the field can be used as
|
||||
condition for a custom default value.
|
||||
:param translate: A boolean. If ``True`` the field is translatable.
|
||||
:param select: An integer. When equal to ``1``, the field appears in the
|
||||
search box in list view and search will be optimized. When equal to
|
||||
search box in list view and the search will be optimized. When equal to
|
||||
``2`` the field appears in the *Advanced Search* in the search box.
|
||||
:param on_change: A list of values. If set, the client will call the
|
||||
method ``on_change_<field_name>`` when the user changes the field
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Float(Field):
|
||||
'''
|
||||
Define a float field (``float``)
|
||||
Define a float field (``float``).
|
||||
'''
|
||||
_type = 'float'
|
||||
|
||||
@@ -15,8 +15,8 @@ class Float(Field):
|
||||
change_default=False, translate=False, select=0, on_change=None,
|
||||
on_change_with=None, depends=None, order_field=None, context=None):
|
||||
'''
|
||||
:param digits: a list of two intergers which define the total
|
||||
of digit and the number of decimal for the float.
|
||||
:param digits: a list of two integers defining the total
|
||||
of digits and the number of decimals of the float.
|
||||
'''
|
||||
super(Float, self).__init__(string=string, help=help, required=required,
|
||||
readonly=readonly, domain=domain, states=states,
|
||||
|
||||
@@ -7,7 +7,7 @@ import inspect
|
||||
|
||||
class Function(Field):
|
||||
'''
|
||||
Define function field (any)
|
||||
Define function field (any).
|
||||
'''
|
||||
_type = 'float'
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Integer(Field):
|
||||
'''
|
||||
Define an integer field (``int``)
|
||||
Define an integer field (``int``).
|
||||
'''
|
||||
_type = 'integer'
|
||||
|
||||
|
||||
class BigInteger(Field):
|
||||
'''
|
||||
Define an integer field (``long``)
|
||||
Define an integer field (``long``).
|
||||
'''
|
||||
_type = 'biginteger'
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Many2Many(Field):
|
||||
'''
|
||||
Define many2many field (``list``)
|
||||
Define many2many field (``list``).
|
||||
'''
|
||||
_type = 'many2many'
|
||||
|
||||
@@ -20,9 +20,9 @@ class Many2Many(Field):
|
||||
or the name of the target model for ModelView only.
|
||||
:param origin: The name of the field to store origin ids.
|
||||
:param target: The name of the field to store target ids.
|
||||
:param order: a list of tuple that are constructed like this:
|
||||
:param order: a list of tuples that are constructed like this:
|
||||
``('field name', 'DESC|ASC')``
|
||||
it allow to specify the order of result
|
||||
allowing to specify the order of result
|
||||
'''
|
||||
super(Many2Many, self).__init__(string=string, help=help,
|
||||
required=required, readonly=readonly, domain=domain,
|
||||
@@ -45,7 +45,7 @@ class Many2Many(Field):
|
||||
:param ids: a list of ids
|
||||
:param model: a string with the name of the model
|
||||
:param name: a string with the name of the field
|
||||
:param values: a dictionary with the readed values
|
||||
:param values: a dictionary with the read values
|
||||
:param context: the context
|
||||
:return: a dictionary with ids as key and values as value
|
||||
'''
|
||||
@@ -81,7 +81,7 @@ class Many2Many(Field):
|
||||
:param record_id: The record id
|
||||
:param model: A string with the name of the model
|
||||
:param name: A string with the name of the field
|
||||
:param values: A list of tuple:
|
||||
:param values: A list of tuples:
|
||||
(``create``, ``{<field name>: value}``),
|
||||
(``write``, ``<ids>``, ``{<field name>: value}``),
|
||||
(``delete``, ``<ids>``),
|
||||
@@ -170,7 +170,7 @@ class Many2Many(Field):
|
||||
|
||||
def get_target(self, pool):
|
||||
'''
|
||||
Return the target model
|
||||
Return the target model.
|
||||
|
||||
:param pool: The pool
|
||||
:return: A Model
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Many2One(Field):
|
||||
'''
|
||||
Define many2one field (``int``)
|
||||
Define many2one field (``int``).
|
||||
'''
|
||||
_type = 'many2one'
|
||||
|
||||
@@ -16,11 +16,11 @@ class Many2One(Field):
|
||||
change_default=False, translate=False, select=0, on_change=None,
|
||||
on_change_with=None, depends=None, order_field=None, context=None):
|
||||
'''
|
||||
:param model_name: The name of the targeted model
|
||||
:param model_name: The name of the targeted model.
|
||||
:param left: The name of the field to store the left value for
|
||||
Modified Preorder Tree Traversal.
|
||||
See http://en.wikipedia.org/wiki/Tree_traversal
|
||||
:param right: The name ofthe field to store the right value. See left
|
||||
:param right: The name of the field to store the right value. See left
|
||||
:param ondelete: Define the behavior of the record when the target
|
||||
record is deleted. (``CASCADE``, ``RESTRICT``, ``SET NULL``)
|
||||
:param datetime_field: The name of the field that contains the datetime
|
||||
|
||||
@@ -6,6 +6,6 @@ from trytond.model.fields.float import Float
|
||||
|
||||
class Numeric(Float):
|
||||
'''
|
||||
Define a numeric field (``decimal``)
|
||||
Define a numeric field (``decimal``).
|
||||
'''
|
||||
_type = 'numeric'
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class One2Many(Field):
|
||||
'''
|
||||
Define one2many field (``list``)
|
||||
Define one2many field (``list``).
|
||||
'''
|
||||
_type = 'one2many'
|
||||
|
||||
@@ -18,11 +18,11 @@ class One2Many(Field):
|
||||
'''
|
||||
:param model_name: The name of the targeted model.
|
||||
:param field: The name of the field that handle the reverse many2one.
|
||||
:param add_remove: A list that defines a domain for the add/remove.
|
||||
:param add_remove: A list that defines a domain on add/remove.
|
||||
See domain on ModelStorage.search.
|
||||
:param order: a list of tuple that are constructed like this:
|
||||
:param order: a list of tuples that are constructed like this:
|
||||
``('field name', 'DESC|ASC')``
|
||||
it allow to specify the order of result
|
||||
allowing to specify the order of result.
|
||||
'''
|
||||
super(One2Many, self).__init__(string=string, help=help,
|
||||
required=required, readonly=readonly, domain=domain,
|
||||
@@ -45,7 +45,7 @@ class One2Many(Field):
|
||||
:param ids: a list of ids
|
||||
:param model: a string with the name of the model
|
||||
:param name: a string with the name of the field
|
||||
:param values: a dictionary with the readed values
|
||||
:param values: a dictionary with the read values
|
||||
:param context: the context
|
||||
:return: a dictionary with ids as key and values as value
|
||||
'''
|
||||
@@ -90,7 +90,7 @@ class One2Many(Field):
|
||||
:param record_id: The record id
|
||||
:param model: A string with the name of the model
|
||||
:param name: A string with the name of the field
|
||||
:param values: A list of tuple:
|
||||
:param values: A list of tuples:
|
||||
(``create``, ``{<field name>: value}``),
|
||||
(``write``, ``<ids>``, ``{<field name>: value}``),
|
||||
(``delete``, ``<ids>``),
|
||||
|
||||
@@ -8,7 +8,7 @@ from trytond import backend
|
||||
|
||||
class Property(Function):
|
||||
'''
|
||||
Define property field that is stored in ir.property (any)
|
||||
Define a property field that is stored in ir.property (any).
|
||||
'''
|
||||
|
||||
def __init__(self, type='float', model_name=None, selection=None,
|
||||
@@ -17,8 +17,8 @@ class Property(Function):
|
||||
change_default=False, translate=False, select=0, on_change=None,
|
||||
on_change_with=None, depends=None, order_field=None, context=None):
|
||||
'''
|
||||
:param type: The type of field.
|
||||
:param fnct_search: The name of the function to search.
|
||||
:param type: The type of the field.
|
||||
:param fnct_search: The name of the search function.
|
||||
:param model_name: See Many2One.
|
||||
:param selection: See Selection.
|
||||
:param digits: See Float.
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Reference(Field):
|
||||
'''
|
||||
Define a reference field (``str``)
|
||||
Define a reference field (``str``).
|
||||
'''
|
||||
_type = 'reference'
|
||||
|
||||
@@ -16,7 +16,7 @@ class Reference(Field):
|
||||
on_change_with=None, depends=None, order_field=None, context=None):
|
||||
'''
|
||||
:param selection: A list or a function name that returns a list.
|
||||
The list must be a list of tuple. First member is a internal name
|
||||
The list must be a list of tuples. First member is an internal name
|
||||
of model and the second is the user name of model.
|
||||
'''
|
||||
super(Reference, self).__init__(string=string, help=help,
|
||||
@@ -30,14 +30,14 @@ class Reference(Field):
|
||||
|
||||
def get(self, cursor, user, ids, model, name, values=None, context=None):
|
||||
'''
|
||||
Replace removed reference id by False
|
||||
Replace removed reference id by False.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param ids: a list of ids
|
||||
:param model: a string with the name of the model
|
||||
:param name: a string with the name of the field
|
||||
:param values: a dictionary with the readed values
|
||||
:param values: a dictionary with the read values
|
||||
:param context: the context
|
||||
:return: a dictionary with ids as key and values as value
|
||||
'''
|
||||
|
||||
@@ -6,7 +6,7 @@ from trytond.model.fields.field import Field
|
||||
|
||||
class Selection(Field):
|
||||
'''
|
||||
Define a selection field (``str``)
|
||||
Define a selection field (``str``).
|
||||
'''
|
||||
_type = 'selection'
|
||||
|
||||
@@ -16,7 +16,7 @@ class Selection(Field):
|
||||
on_change_with=None, depends=None, order_field=None, context=None):
|
||||
'''
|
||||
:param selection: A list or a function name that returns a list.
|
||||
The list must be a list of tuple. First member is the value
|
||||
The list must be a list of tuples. First member is the value
|
||||
to store and the second is the value to display.
|
||||
:param sort: A boolean to sort or not the selections.
|
||||
'''
|
||||
|
||||
@@ -6,6 +6,6 @@ from trytond.model.fields.char import Char
|
||||
|
||||
class Text(Char):
|
||||
'''
|
||||
Define a text field (``unicode``)
|
||||
Define a text field (``unicode``).
|
||||
'''
|
||||
_type = 'text'
|
||||
|
||||
+12
-12
@@ -10,10 +10,10 @@ class Model(object):
|
||||
"""
|
||||
Define a model in Tryton.
|
||||
|
||||
:_name: a unique string to reference the model across all the platform.
|
||||
:_inherits:
|
||||
:_name: a unique string to reference the model throughout the platform.
|
||||
:_inherits: a model from which this one inherits.
|
||||
:_description: a non technical description string.
|
||||
:_rpc: a dictionary with method name allowed to be called remotely and
|
||||
:_rpc: a dictionary with a method name allowed to be called remotely and
|
||||
a boolean as value that defines if it must be called in a commited
|
||||
transaction.
|
||||
:_error_messages: a dictionary mapping keywords to an error message. Eg.:
|
||||
@@ -148,7 +148,7 @@ class Model(object):
|
||||
|
||||
def init(self, cursor, module_name):
|
||||
"""
|
||||
Add model in ir.model and ir.model.field
|
||||
Add model in ir.model and ir.model.field.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param module_name: the module name
|
||||
@@ -341,7 +341,7 @@ class Model(object):
|
||||
error_description='', error_description_args=None,
|
||||
raise_exception=True, context=None):
|
||||
'''
|
||||
Raise an exception that will be display as an error message
|
||||
Raise an exception that will be displayed as an error message
|
||||
in the client.
|
||||
|
||||
:param cursor: the database cursor
|
||||
@@ -419,8 +419,8 @@ class Model(object):
|
||||
warning_args=None, warning_description='',
|
||||
warning_description_args=None, context=None):
|
||||
'''
|
||||
Raise an exception that will be display as a warning message
|
||||
in the client if the user has not yet by-pass it.
|
||||
Raise an exception that will be displayed as a warning message
|
||||
in the client, if the user has not yet bypassed it.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -455,14 +455,14 @@ class Model(object):
|
||||
def default_get(self, cursor, user, fields_names, context=None,
|
||||
with_rec_name=True):
|
||||
'''
|
||||
Return a dict with the default values for each fields_names.
|
||||
Return a dict with the default values for each field in fields_names.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param fields_names: a list of fields names
|
||||
:param context: the context
|
||||
:param with_rec_name: a boolean to add rec_name value
|
||||
:return: a dictionnary with field name as key
|
||||
:return: a dictionary with field name as key
|
||||
and default value as value
|
||||
'''
|
||||
value = {}
|
||||
@@ -595,13 +595,13 @@ class Model(object):
|
||||
|
||||
def fields_get(self, cursor, user, fields_names=None, context=None):
|
||||
"""
|
||||
Returns the definition of each field in the object
|
||||
Return the definition of each field in the object.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param fields_names: a list of fields names or None for all fields
|
||||
:param fields_names: a list of field names or None for all fields
|
||||
:param context: the context
|
||||
:return: a dictionnary with field name as key and definition as value
|
||||
:return: a dictionary with field name as key and definition as value
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
@@ -15,7 +15,7 @@ _RE_CHECK = re.compile('CHECK\s*\((.*)\)', re.I)
|
||||
|
||||
class ModelSQL(ModelStorage):
|
||||
"""
|
||||
Define a model with storage in database in Tryton.
|
||||
Define a model with storage in database.
|
||||
|
||||
:_table: The name of the database table which is mapped to the class.
|
||||
If not set the value of ``_name`` is used with dots converted to
|
||||
@@ -25,7 +25,7 @@ class ModelSQL(ModelStorage):
|
||||
|
||||
``[('name', 'ASC'), 'age', 'DESC']``
|
||||
:_order_name: The name of the field (or an SQL statement) on which the records
|
||||
must be sorted when sorting on this model from an other one.
|
||||
must be sorted when sorting on this model from an other model.
|
||||
:_history: A boolean to historize record change.
|
||||
:_sql_constraints: A list of constraints that are added on the table. E.g.:
|
||||
|
||||
|
||||
@@ -75,11 +75,11 @@ class ModelStorage(Model):
|
||||
self._constraints = []
|
||||
|
||||
def default_create_uid(self, cursor, user, context=None):
|
||||
"Default value for uid field"
|
||||
"Default value for uid field."
|
||||
return int(user)
|
||||
|
||||
def default_create_date(self, cursor, user, context=None):
|
||||
"Default value for create_date field"
|
||||
"Default value for create_date field."
|
||||
return datetime.datetime.today()
|
||||
|
||||
def default_sequence(self, cursor, user, context=None):
|
||||
@@ -154,7 +154,7 @@ class ModelStorage(Model):
|
||||
|
||||
def write(self, cursor, user, ids, values, context=None):
|
||||
'''
|
||||
Write values on records
|
||||
Write values on records.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -223,12 +223,12 @@ class ModelStorage(Model):
|
||||
|
||||
def copy(self, cursor, user, ids, default=None, context=None):
|
||||
'''
|
||||
Duplicate the record in ids.
|
||||
Duplicate the record(s) in ids.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param ids: a list of ids or an id
|
||||
:param default: a dictionnary with field name as keys and
|
||||
:param default: a dictionary with field name as keys and
|
||||
new value for the field as value
|
||||
:param context: the context
|
||||
:return: a list of new ids or the new id
|
||||
@@ -333,28 +333,28 @@ class ModelStorage(Model):
|
||||
def search(self, cursor, user, domain, offset=0, limit=None, order=None,
|
||||
context=None, count=False):
|
||||
'''
|
||||
Return a list of id that match the clauses defined in args.
|
||||
Return a list of ids that match the clauses defined in args.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param domain: a list of tuples or lists
|
||||
lists are construct like this:
|
||||
lists are constructed like this:
|
||||
``['operator', args, args, ...]``
|
||||
operator can be 'AND' or 'OR', if it is missing the default
|
||||
value will be 'AND'
|
||||
tuples are construct like this:
|
||||
tuples are constructed like this:
|
||||
``('field name', 'operator', value)``
|
||||
field name: is a field name from the model or a relational field
|
||||
by using '.' as separator.
|
||||
operator must be in OPERATORS
|
||||
:param offset: an integer to specify the offset for the result
|
||||
:param offset: an integer to specify the offset of the result
|
||||
:param limit: an integer to specify the number of result
|
||||
:param order: a list of tuple that are constructed like this:
|
||||
:param order: a list of tuples that are constructed like this:
|
||||
``('field name', 'DESC|ASC')``
|
||||
it allow to specify the order of result
|
||||
allowing to specify the order of result
|
||||
:param context: the context
|
||||
:param count: a boolean to return only the len of the result
|
||||
:return: a list of ids or an interger
|
||||
:param count: a boolean to return only the length of the result
|
||||
:return: a list of ids or an integer
|
||||
'''
|
||||
if count:
|
||||
return 0
|
||||
@@ -362,7 +362,7 @@ class ModelStorage(Model):
|
||||
|
||||
def search_count(self, cursor, user, domain, context=None):
|
||||
'''
|
||||
Return the number of record that match the domain. (See search)
|
||||
Return the number of records that match the domain. (See search)
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -378,22 +378,22 @@ class ModelStorage(Model):
|
||||
def search_read(self, cursor, user, domain, offset=0, limit=None, order=None,
|
||||
context=None, fields_names=None):
|
||||
'''
|
||||
Call search function and read in once.
|
||||
Usefull for the client to reduce the number of calls.
|
||||
Call search and read functions at once.
|
||||
Useful for the client to reduce the number of calls.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param domain: a domain like in search
|
||||
:param offset: an integer to specify the offset for the result
|
||||
:param limit: an integer to specify the number of result
|
||||
:param order: a list of tuple that are constructed like this:
|
||||
:param limit: an integer to specify the number of records
|
||||
:param order: a list of tuples that are constructed like this:
|
||||
('field name', 'DESC|ASC')
|
||||
it allow to specify the order of result
|
||||
allowing to to specify the order of result
|
||||
:param context: the context
|
||||
:param fields_names: fields names to read if None read all fields
|
||||
:return: a list of dictionnary or a dictionnary if limit is 1
|
||||
the dictionnaries will have fields names as key
|
||||
and fields value as value
|
||||
:return: a list of dictionaries or a dictionary if limit is 1
|
||||
the dictionaries will have field names as key
|
||||
and field values as value
|
||||
'''
|
||||
ids = self.search(cursor, user, domain, offset=offset, limit=limit,
|
||||
order=order, context=context)
|
||||
@@ -466,7 +466,7 @@ class ModelStorage(Model):
|
||||
def get_rec_name(self, cursor, user, ids, name, arg, context=None):
|
||||
'''
|
||||
Return a dictionary with id as key and rec_name as value.
|
||||
It is used by the Function field rec_name
|
||||
It is used by the Function field rec_name.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -489,7 +489,7 @@ class ModelStorage(Model):
|
||||
|
||||
def search_rec_name(self, cursor, user, name, args, context=None):
|
||||
'''
|
||||
Return a list of arguments for search on rec_name
|
||||
Return a list of arguments for search on rec_name.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -507,7 +507,7 @@ class ModelStorage(Model):
|
||||
|
||||
def browse(self, cursor, user, ids, context=None):
|
||||
'''
|
||||
Return a browse a BrowseRecordList for the ids
|
||||
Return a BrowseRecordList for the ids
|
||||
or BrowseRecord if ids is a integer.
|
||||
|
||||
:param cursor: the database cursor
|
||||
@@ -562,15 +562,15 @@ class ModelStorage(Model):
|
||||
|
||||
def export_data(self, cursor, user, ids, fields_names, context=None):
|
||||
'''
|
||||
Return list of list of values for each ids.
|
||||
The list of values follow the fields_names.
|
||||
Relational fields are defined with '/' at any deep.
|
||||
Return list of list of values for each id in ids.
|
||||
The list of values follows fields_names.
|
||||
Relational fields are defined with '/' at any depth.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param ids: a list of ids
|
||||
:param fields_names: a list of fields names
|
||||
:param fields_names: a list of field names
|
||||
:param context: the context
|
||||
:return: a list of list of values for each ids
|
||||
:return: a list of list of values for each id in ids
|
||||
'''
|
||||
fields_names = [x.split('/') for x in fields_names]
|
||||
datas = []
|
||||
@@ -580,13 +580,13 @@ class ModelStorage(Model):
|
||||
|
||||
def import_data(self, cursor, user, fields_names, datas, context=None):
|
||||
'''
|
||||
Create record for each values in datas.
|
||||
The fields name of values must be defined in fields_names.
|
||||
Create records for all values in datas.
|
||||
The field names of values must be defined in fields_names.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param fields_names: a list of fields names
|
||||
:param datas: the datas to import
|
||||
:param datas: the data to import
|
||||
:param context: the context
|
||||
:return: a tuple with
|
||||
- the number of records imported
|
||||
@@ -782,15 +782,15 @@ class ModelStorage(Model):
|
||||
originating from xml data. This is used by write and delete
|
||||
functions: if the return value is True the records can be
|
||||
written/deleted, False otherwise. The default behaviour is to
|
||||
forbid all modification on records/fields originating from
|
||||
forbid any modification on records/fields originating from
|
||||
xml. Values is the dictionary of written values. If values is
|
||||
equal to None, no field by field check is performed, False is
|
||||
return has soon has one of the record comes from the xml.
|
||||
returned as soon as one of the record comes from the xml.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
:param ids: a list of ids or an id
|
||||
:param values: a dictionary with fields names as key and
|
||||
:param values: a dictionary with field names as key and
|
||||
written values as value
|
||||
:param context: the context
|
||||
:return: True or False
|
||||
@@ -824,7 +824,7 @@ class ModelStorage(Model):
|
||||
|
||||
def check_recursion(self, cursor, user, ids, parent='parent'):
|
||||
'''
|
||||
Function that check if there is no recursion in the tree
|
||||
Function that checks if there is no recursion in the tree
|
||||
composed with parent as parent field name.
|
||||
|
||||
:param cursor: the database cursor
|
||||
@@ -1064,7 +1064,7 @@ class ModelStorage(Model):
|
||||
|
||||
def workflow_trigger_trigger(self, cursor, user, ids, context=None):
|
||||
'''
|
||||
Trigger trigger event
|
||||
Trigger a trigger event.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
|
||||
@@ -93,7 +93,7 @@ class ModelView(Model):
|
||||
def fields_view_get(self, cursor, user, view_id=None, view_type='form',
|
||||
context=None, toolbar=False, hexmd5=None):
|
||||
'''
|
||||
Return a view definition
|
||||
Return a view definition.
|
||||
|
||||
:param cursor: the database cursor
|
||||
:param user: the user id
|
||||
@@ -102,14 +102,14 @@ class ModelView(Model):
|
||||
:param context: the context
|
||||
:param toolbar: if True the result will contain a toolbar key with
|
||||
keyword action definitions for the view
|
||||
:param hexmd5: if fill, the function will return True if the result
|
||||
have the same md5
|
||||
:return: a dictionnary with keys:
|
||||
:param hexmd5: if filled, the function will return True if the result
|
||||
has the same md5
|
||||
:return: a dictionary with keys:
|
||||
- model: the model name
|
||||
- arch: the xml description of the view
|
||||
- fields: a dictionnary with the definition of each fields in the view
|
||||
- toolbar: a dictionnary with the keyword action definitions
|
||||
- md5: the check sum of the dictionnary without this checksum
|
||||
- fields: a dictionary with the definition of each field in the view
|
||||
- toolbar: a dictionary with the keyword action definitions
|
||||
- md5: the check sum of the dictionary without this checksum
|
||||
'''
|
||||
|
||||
if context is None:
|
||||
@@ -252,7 +252,7 @@ class ModelView(Model):
|
||||
def view_header_get(self, cursor, user, value, view_type='form',
|
||||
context=None):
|
||||
"""
|
||||
Overload this method if you need a window title
|
||||
Overload this method if you need a window title.
|
||||
which depends on the context
|
||||
|
||||
:param cursor: the database cursor
|
||||
|
||||
Reference in New Issue
Block a user