trytond-3.8.3/0000755000175000017500000000000012655425164012552 5ustar cedced00000000000000trytond-3.8.3/bin/0000755000175000017500000000000012655425163013321 5ustar cedced00000000000000trytond-3.8.3/bin/trytond0000755000175000017500000000555412651525744014765 0ustar cedced00000000000000#!/usr/bin/env python #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. import sys import os import argparse DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, '..', '..', 'trytond'))) if os.path.isdir(DIR): sys.path.insert(0, os.path.dirname(DIR)) from trytond import __version__ from trytond import server def parse_commandline(): options = {} parser = argparse.ArgumentParser(prog='trytond') parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) parser.add_argument("-c", "--config", dest="configfile", metavar='FILE', default=os.environ.get('TRYTOND_CONFIG'), help="specify config file") parser.add_argument('--dev', dest='dev', action='store_true', help='enable development mode') parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", help="enable verbose mode") parser.add_argument("-d", "--database", dest="database_names", nargs='+', default=[], metavar='DATABASE', help="specify the database name") parser.add_argument("-u", "--update", dest="update", nargs='+', default=[], metavar='MODULE', help="update a module") parser.add_argument("--all", dest="update", action="append_const", const="ir", help="update all installed modules") parser.add_argument("--pidfile", dest="pidfile", metavar='FILE', help="file where the server pid will be stored") parser.add_argument("--logconf", dest="logconf", metavar='FILE', help="logging configuration file (ConfigParser format)") parser.add_argument("--cron", dest="cron", action="store_true", help="enable cron") parser.epilog = ('The first time a database is initialized admin ' 'password is read from file defined by TRYTONPASSFILE ' 'environment variable or interactively ask user.\n' 'The config file can be specified in the TRYTOND_CONFIG ' 'environment variable.\n' 'The database URI can be specified in the TRYTOND_DATABASE_URI ' 'environment variable.') options = parser.parse_args() if not options.database_names and options.update: parser.error('Missing database option') return options if '--profile' in sys.argv: import profile import pstats import tempfile sys.argv.remove('--profile') options = parse_commandline() statfile = tempfile.mkstemp(".stat", "trytond-")[1] profile.run('server.TrytonServer(options).run()', statfile) s = pstats.Stats(statfile) s.sort_stats('cumulative').print_stats() s.sort_stats('call').print_stats() s.sort_stats('time').print_stats() s.sort_stats('time') s.print_callers() s.print_callees() os.remove(statfile) else: options = parse_commandline() server.TrytonServer(options).run() trytond-3.8.3/doc/0000755000175000017500000000000012655425163013316 5ustar cedced00000000000000trytond-3.8.3/doc/ref/0000755000175000017500000000000012655425163014072 5ustar cedced00000000000000trytond-3.8.3/doc/ref/models/0000755000175000017500000000000012655425163015355 5ustar cedced00000000000000trytond-3.8.3/doc/ref/models/fields.rst0000644000175000017500000005047112651525744017366 0ustar cedced00000000000000.. _ref-models-fields: .. module:: trytond.model.fields ====== Fields ====== Fields define the behavior of the data on model's record. Field options ============= The following arguments are available to all field types. All are optional except :attr:`Field.string`. ``string`` ---------- .. attribute:: Field.string A string for the label of the field. ``help`` -------- .. attribute:: Field.help A multi-line help string for the field. ``required`` ------------ .. attribute:: Field.required If ``True``, the field is not allowed to be empty. Default is ``False``. ``readonly`` ------------ .. attribute:: Field.readonly If ``True``, the field is not editable in the client. Default is ``False``. ``domain`` ---------- .. attribute:: Field.domain A :ref:`domain ` constraint that will be applied on the field value. ``states`` ---------- .. attribute:: Field.states A dictionary that defines dynamic states of the field and overrides the static one. Possible keys are ``required``, ``readonly`` and ``invisible``. The values are :class:`~trytond.pyson.PYSON` statements that will be evaluated with the values of the record. ``select`` ---------- .. attribute:: Field.select If true, the content of the field will be indexed. .. _ref-models-fields-on_change: ``on_change`` ------------- .. attribute:: Field.on_change A set of field names. If this attribute is set, the client will call the method ``on_change_`` of the model when the user changes the current field value and will give the values of each fields in this list. The method signature is:: on_change_() This method must change the value of the fields to be updated. .. note:: The on_change_ methods are running in a rollbacked transaction. .. The set of field names could be filled by using the decorator :meth:`depends`. .. _ref-models-fields-on_change_with: ``on_change_with`` ------------------ .. attribute:: Field.on_change_with A set of field names. Same like :attr:`on_change`, but defined the other way around. If this attribute is set, the client will call the method ``on_change_with_`` of the model when the user changes one of the fields defined in the list and will give the values of each fields in this list. The method signature is:: on_change_with_() This method must return the new value of the field. .. note:: The on_change_with_ methods are running in a rollbacked transaction. .. The set of field names could be filled by using the decorator :meth:`depends`. ``depends`` ----------- .. attribute:: Field.depends A list of field names on which the current one depends. This means that the client will also read these fields even if they are not defined on the view. :attr:`Field.depends` is used per example to ensure that :class:`~trytond.pyson.PYSON` statement could be evaluated. ``context`` ----------- .. attribute:: Field.context A dictionary which will update the current context for *relation field*. .. warning:: The context could only depend on direct field of the record and without context. .. ``loading`` ----------- .. attribute:: Field.loading Define how the field must be loaded: ``lazy`` or ``eager``. ``name`` -------- .. attribute:: Field.name The name of the field. Instance methods: .. method:: Field.convert_domain(domain, tables, Model) Convert the simple :ref:`domain ` clause into a SQL expression or a new domain. :ref:`tables ` could be updated to add new joins. .. method:: Field.sql_format(value) Convert the value to use as parameter of SQL queries. .. method:: Field.sql_type() Return the namedtuple('SQLType', 'base type') which defines the SQL type to use for creation and casting. .. method:: Field.sql_column(table) Return the Column instance based on table. Default value ============= See :ref:`default value ` Searching ========= A class method could be defined for each field which must return a SQL expression for the given domain instead of the default one. The method signature is:: domain_(domain, tables) Where ``domain`` is the simple :ref:`domain ` clause and ``tables`` is a nested dictionary, see :meth:`~Field.convert_domain`. Ordering ======== A class method could be defined for each field which must return a list of SQL expression on which to order instead of the field. The method signature is:: order_(tables) Where ``tables`` is a nested dictionary, see :meth:`~Field.convert_domain`. Depends ======= .. method:: depends([\*fields[, methods]]) A decorator to define the field names on which the decorated method depends. The `methods` argument can be used to duplicate the field names from other fields. This is usefull if the decorated method calls another method. Field types =========== Boolean ------- .. class:: Boolean(string[, \**options]) A true/false field. Integer ------- .. class:: Integer(string[, \**options]) An integer field. BigInteger ---------- .. class:: BigInteger(string[, \**options]) A long integer field. Char ---- .. class:: Char(string[, size[, translate[, \**options]]]) A single line string field. :class:`Char` has two extra optional arguments: .. attribute:: Char.size The maximum length (in characters) of the field. The size is enforced at the storage level and in the client input. .. attribute:: Char.translate If true, the value of the field is translatable. The value readed and stored will depend on the ``language`` defined in the context. .. attribute:: Char.autocomplete A set of field names. If this attribute is set, the client will call the method ``autocomplete_`` of the model when the user changes one of those field value. The method signature is:: autocomplete_() This method must return a list of string that will populate the ComboboxEntry in the client. The set of field names could be filled by using the decorator :meth:`depends`. Text ---- .. class:: Text(string[, size[, translatable[, \**options]]]) A multi line string field. :class:`Text` has two extra optional arguments: .. attribute:: Text.size Same as :attr:`Char.size` .. attribute:: Text.translate Same as :attr:`Char.translate` Float ----- .. class:: Float(string[, digits[, \**options]]) A floating-point number field. It will be represented in Python by a ``float`` instance. :class:`Float` has one extra optional arguments: .. attribute:: Float.digits A tuple of two integers. The first integer defines the total of numbers in the integer part. The second integer defines the total of numbers in the decimal part. Integers can be replaced by a :class:`~trytond.pyson.PYSON` statement. Numeric ------- .. class:: Numeric(string[, digits[, \**options]]) A fixed-point number field. It will be represented in Python by a ``decimal.Decimal`` instance. :class:`Numeric` has one extra optional arguments: .. attribute:: Numeric.digits Same as :attr:`Float.digits` Date ---- .. class:: Date(string[, \**options]) A date, represented in Python by a ``datetime.date`` instance. DateTime -------- .. class:: DateTime(string[, format, \**options]) A date and time, represented in Python by a ``datetime.datetime`` instance. It is stored in `UTC`_ while displayed in the user timezone. .. _`UTC`: https://en.wikipedia.org/wiki/Coordinated_Universal_Time .. attribute:: DateTime.format A string format as used by strftime. This format will be used to display the time part of the field. The default value is `%H:%M:%S`. The value can be replaced by a :class:`~trytond.pyson.PYSON` statement. Timestamp --------- .. class:: Timestamp(string[, \**options]) A timestamp, represented in Python by a ``datetime.datetime`` instance. Time ---- .. class:: Time(string[, format, \**options]) A time, represented in Python by a ``datetime.time`` instance. .. attribute:: Time.format Same as :attr:`DateTime.format` TimeDelta --------- .. class:: TimeDelta(string[, converter[, \**options]]) An interval, represented in Python by a ``datetime.timedelta`` instance. .. attribute:: TimeDelta.converter The name of the context key containing the time converter. A time converter is a dictionary with the keys: ``s`` (second), ``m`` (minute), ``h`` (hour), ``d`` (day), ``w`` (week), ``M`` (month), ``Y`` (year) and the value in second. Binary ------ .. class:: Binary(string[, \**options]) A binary field. It will be represented in Python by a ``bytes`` instance. :class:`Binary` has one extra optional argument: .. attribute:: Binary.filename Name of the field that holds the data's filename. Default value is an empty string, which means the data has no filename (in this case, the filename is hidden, and the "Open" button is hidden when the widget is set to "image"). Selection --------- .. class:: Selection(selection, string[, sort[, selection_change_with[, translate[, \**options]]]) A string field with limited values to choice. :class:`Selection` has one extra required argument: .. attribute:: Selection.selection A list of 2-tuples that looks like this:: [ ('M', 'Male'), ('F', 'Female'), ] The first element in each tuple is the actual value stored. The second element is the human-readable name. It can also be the name of a class method on the model, that will return an appropriate list. The signature of the method is:: selection() .. note:: The method is automaticly added to :attr:`trytond.model.Model._rpc` if not manually set. .. :class:`Selection` has two extra optional arguments: .. attribute:: Selection.sort If true, the choices will be sorted by human-readable value. Default value is ``True``. .. attribute:: Selection.selection_change_with A set of field names. If this attribute is set, the client will call the ``selection`` method of the model when the user changes on of the fields defined in the list and will give the values of each fields in the list. The ``selection`` method should be an instance method. The set of field names could be filled by using the decorator :meth:`depends`. .. attribute:: Selection.translate_selection If true, the human-readable values will be translated. Default value is ``True``. Instance methods: .. method:: Selection.translated([name]) Returns a descriptor for the translated value of the field. The descriptor must be used on the same class as the field. Reference --------- .. class:: Reference(string[, selection[, selection_change_with[, \**options]]) A field that refers to a record of a model. It will be represented in Python by a ``str`` instance like this:: ',' But a ``tuple`` can be used to search or set value. :class:`Reference` has one extra optional argument: .. attribute:: Reference.selection Same as :attr:`Selection.selection` but only for model name. .. attribute:: Reference.selection_change_with Same like :attr:`Selection.selection_change_with`. Many2One -------- .. class:: Many2One(model_name, string[, left[, right[, ondelete[, datetime_field[, target_search[, \**options]]]]]) A many-to-one relation field. :class:`Many2One` has one extra required argument: .. attribute:: Many2One.model_name The name of the target model. :class:`Many2One` has some extra optional arguments: .. attribute:: Many2One.left The name of the field that stores the left value for the `Modified Preorder Tree Traversal`_. It only works if the :attr:`model_name` is the same then the model. .. _`Modified Preorder Tree Traversal`: http://en.wikipedia.org/wiki/Tree_traversal .. attribute:: Many2One.right The name of the field that stores the right value. See :attr:`left`. .. attribute:: Many2One.ondelete Define the behavior of the record when the target record is deleted. Allowed values are: - ``CASCADE``: it will try to delete the record. - ``RESTRICT``: it will prevent the deletion of the target record. - ``SET NULL``: it will empty the relation field. ``SET NULL`` is the default setting. .. note:: ``SET NULL`` will be override into ``RESTRICT`` if :attr:`~Field.required` is true. .. .. attribute:: Many2One.datetime_field If set, the target record will be read at the date defined by the datetime field name of the record. It is usually used in combination with :attr:`trytond.model.ModelSQL._history` to request a value for a given date and time on a historicized model. .. attribute:: Many2One.target_search Define the kind of SQL query to use when searching on related target. Allowed values are: - ``subquery``: it will use a subquery based on the ids. - ``join``: it will add a join on the main query. ``join`` is the default value. .. note:: ``join`` could improve the performance if the target has a huge amount of records. .. One2Many -------- .. class:: One2Many(model_name, field, string[, add_remove[, order[, datetime_field[, size[, \**options]]]]]) A one-to-many relation field. It requires to have the opposite :class:`Many2One` field or a :class:`Reference` field defined on the target model. This field accepts as written value a list of tuples like this: - ``('create', [{: value, ...}, ...])``: it will create new target records and link them to this one. - ``('write'[[, ids, ...], {: value, ...}, ...])``: it will write values to target ids. - ``('delete'[, ids, ...])``: it will delete the target ids. - ``('add'[, ids, ...])``: it will link the target ids to this record. - ``('remove'[, ids, ...])``: it will unlink the target ids from this record. - ``('copy', ids[, {: value, ...}])``: it will copy the target ids to this record. Optional field names and values may be added to override some of the fields of the copied records. :class:`One2Many` has some extra required arguments: .. attribute:: One2Many.model_name The name of the target model. .. attribute:: One2Many.field The name of the field that handles the opposite :class:`Many2One` or :class:`Reference`. :class:`One2Many` has some extra optional arguments: .. attribute:: One2Many.add_remove A :ref:`domain ` to select records to add. If set, the client will allow to add/remove existing records instead of only create/delete. .. attribute:: One2Many.order A list of tuple defining the default order of the records like for :attr:`trytond.model.ModelSQL._order`. .. attribute:: One2Many.datetime_field Same as :attr:`Many2One.datetime_field` .. attribute:: One2Many.size An integer or a PYSON expression denoting the maximum number of records allowed in the relation. Many2Many --------- .. class:: Many2Many(relation_name, origin, target, string[, order[, datetime_field[, size[, \**options]]]]) A many-to-many relation field. It requires to have the opposite origin :class:`Many2One` field or a:class:`Reference` field defined on the relation model and a :class:`Many2One` field pointing to the target. This field accepts as written value a list of tuples like the :class:`One2Many`. :class:`Many2Many` has some extra required arguments: .. attribute:: Many2Many.relation_name The name of the relation model. .. attribute:: Many2Many.origin The name of the field that has the :class:`Many2One` or :class:`Reference` to the record. .. attribute:: Many2Many.target The name of the field that has the :class:`Many2One` to the target record. .. note:: A :class:`Many2Many` field can be used on a simple :class:`~trytond.model.ModelView`, like in a :class:`~trytond.wizard.Wizard`. For this, :attr:`~Many2Many.relation_name` is set to the target model and :attr:`~Many2Many.origin` and :attr:`~Many2Many.target` are set to `None`. .. :class:`Many2Many` has some extra optional arguments: .. attribute:: Many2Many.order Same as :attr:`One2Many.order` .. attribute:: Many2Many.datetime_field Same as :attr:`Many2One.datetime_field` .. attribute:: Many2Many.size An integer or a PYSON expression denoting the maximum number of records allowed in the relation. .. attribute:: Many2Many.add_remove An alias to the :attr:`domain` for compatibility with the :class:`One2Many`. Instance methods: .. method:: Many2Many.get_target() Return the target :class:`~trytond.model.Model`. One2One ------- .. class:: One2One(relation_name, origin, target, string[, datetime_field[, \**options]]) A one-to-one relation field. .. warning:: It is on the relation_name :class:`~trytond.model.Model` that the unicity of the couple (origin, target) must be checked. .. .. attribute:: One2One.datetime_field Same as :attr:`Many2One.datetime_field` Instance methods: .. method:: One2One.get_target() Return the target :class:`~trytond.model.Model`. Function -------- .. class:: Function(field, getter[, setter[, searcher]]) A function field can emulate any other given `field`. :class:`Function` has a required argument: .. attribute:: Function.getter The name of the classmethod or instance of the :class:`~trytond.model.Model` for getting values. The signature of the classmethod is:: getter(instances, name) where `name` is the name of the field, and it must return a dictionary with a value for each instance. Or the signature of the classmethod is:: getter(instances, names) where `names` is a list of name fields, and it must return a dictionary containing for each names a dictionary with a value for each instance. The signature of the instancemethod is:: getter(name) where `name` is the name of the field, and it must return the value. :class:`Function` has some extra optional arguments: .. attribute:: Function.setter The name of the classmethod of the :class:`~trytond.model.Model` to set the value. The signature of the method id:: setter(ids, name, value) where `name` is the name of the field and `value` the value to set. .. attribute:: Function.searcher The name of the classmethod of the :class:`~trytond.model.Model` to search on the field. The signature of the method is:: searcher(name, clause) where `name` is the name of the field and `clause` is a :ref:`domain clause `. It must return a list of :ref:`domain ` clauses but the ``operand`` can be a SQL query. Instance methods: .. method:: Function.get(ids, model, name[, values]) Call the :attr:`~Function.getter` classmethod where `model` is the :class:`~trytond.model.Model` instance of the field, `name` is the name of the field. .. method:: Function.set(ids, model, name, value) Call the :attr:`~Function.setter` classmethod where `model` is the :class:`~trytond.model.Model` instance of the field, `name` is the name of the field, `value` is the value to set. .. method:: Function.search(model, name, clause) Call the :attr:`~Function.searcher` classmethod where `model` is the :class:`~trytond.model.Model` instance of the field, `name` is the name of the field, `clause` is a clause of :ref:`domain `. Property -------- .. class:: Property(field) A property field that is like a :class:`Function` field but with predifined :attr:`~Function.getter`, :attr:`~Function.setter` and :attr:`~Function.searcher` that use the :class:`~trytond.model.ModelSQL` `ir.property` to store values. Instance methods: .. method:: Property.get(ids, model, name[, values]) Same as :meth:`Function.get`. .. method:: Property.set(ids, model, name, value) Same as :meth:`Function.set`. .. method:: Property.search(model, name, clause) Same as :meth:`Function.search`. Dict ---- .. class:: Dict(schema_model[, \**options]) A dictionary field with predefined keys. :class:`Dict` has one extra required argument: .. attribute:: Dict.schema_model The name of the :class:`DictSchemaMixin` model that stores the definition of keys. Instance methods: .. method:: Dict.translated([name[, type_]]) Returns a descriptor for the translated `values` or `keys` of the field following `type_`. The descriptor must be used on the same class as the field. Default `type_` is `values`. trytond-3.8.3/doc/ref/models/index.rst0000644000175000017500000000017012615705746017220 0ustar cedced00000000000000.. _ref-models-index: ====== Models ====== Model API reference. .. toctree:: :maxdepth: 1 models fields trytond-3.8.3/doc/ref/models/models.rst0000644000175000017500000004706412651525744017407 0ustar cedced00000000000000.. _ref-models: .. module:: trytond.model ===== Model ===== .. class:: Model([id[, \**kwargs]]) This is the base class that every kind of :ref:`model ` inherits. It defines common attributes of all models. Class attributes are: .. attribute:: Model.__name__ It contains the a unique name to reference the model throughout the platform. .. attribute:: Model.__rpc__ It contains a dictionary with method name as key and an instance of :class:`trytond.rpc.RPC` as value. .. attribute:: Model._error_messages 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!' } .. attribute:: Model._rec_name It contains the name of the field used as name of records. The default value is 'name'. .. attribute:: Model.id The definition of the field ``id`` of records. Class methods: .. classmethod:: Model.__setup__() Setup the class before adding into the :class:`trytond.pool.Pool`. .. classmethod:: Model.__post_setup__() Setup the class after added into the :class:`trytond.pool.Pool`. .. classmethod:: Model.__register__(module_name) Registers the model in ``ir.model`` and ``ir.model.field``. .. classmethod:: Model.raise_user_error(error[, error_args[, error_description[, error_description_args[, raise_exception]]]]) 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. .. classmethod:: Model.raise_user_warning(warning_name, warning[, warning_args[, warning_description[, warning_description_args]]]) 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 :meth:`Model.raise_user_error`. .. warning:: It requires that the cursor will be commited as it stores state of the warning states by users. .. .. classmethod:: Model.default_get(fields_names[, with_rec_name]) 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. .. classmethod:: Model.fields_get([fields_names]) Return the definition of each field on the model. Instance methods: .. method:: Model.on_change(fieldnames) Returns the list of changes by calling `on_change` method of each field. .. method:: Model.on_change_with(fieldnames) Returns the new values of all fields by calling `on_change_with` method of each field. .. method:: Model.pre_validate() This method is called by the client to validate the instance. ========= ModelView ========= .. class:: ModelView It adds requirements to display a view of the model in the client. Class attributes: .. attribute:: ModelView._buttons 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: .. staticmethod:: ModelView.button Decorate button method to check group access. .. staticmethod:: ModelView.button_action(action) Same as :meth:`ModelView.button` but return the action id of the XML `id` action. .. staticmethod:: ModelView.button_change([\*fields]) Same as :meth:`ModelView.button` but for button that change values of the fields on client side (similar to :ref:`on_change `). .. warning:: Only on instance methods. Class methods: .. classmethod:: ModelView.fields_view_get([view_id[, view_type[, toolbar]]]) 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, } .. classmethod:: ModelView.view_toolbar_get() Returns the model specific actions in a dictionary with keys: - `print`: a list of available reports - `action`: a list of available actions - `relate`: a list of available relations .. classmethod:: ModelView.view_header_get(value[, view_type]) Returns the window title used by the client for the specific view type. .. classmethod:: ModelView.view_attributes() Returns a list of XPath, attribute and value. Each element from the XPath will get the attribute set with the JSON encoded value. ============ ModelStorage ============ .. class:: ModelStorage It adds storage capability. Class attributes are: .. attribute:: ModelStorage.create_uid The definition of the :class:`trytond.model.fields.Many2One` field :attr:`create_uid` of records. It contains the :attr:`id` of the user who creates the record. .. attribute:: ModelStorage.create_date The definition of the :class:`trytond.model.fields.DateTime` field :attr:`create_date` of records. It contains the datetime of the creation of the record. .. attribute:: ModelStorage.write_uid The definition of the :class:`trytond.model.fields.Many2One` field :attr:`write_uid` of the records. It contains the :attr:`id` of the last user who writes on the record. .. attribute:: ModelStorage.write_date The definition of the :class:`trytond.model.fields.DateTime` field :attr:`write_date` of the records. It contains the datetime of the last write on the record. .. attribute:: ModelStorage.rec_name The definition of the :class:`trytond.model.fields.Function` field :attr:`rec_name`. It is used in the client to display the records with a single string. .. attribute:: ModelStorage._constraints .. warning:: Deprecated, use :class:`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 :attr:`Model._error_messages`. Static methods: .. staticmethod:: ModelStorage.default_create_uid() Return the default value for :attr:`create_uid`. .. staticmethod:: ModelStorage.default_create_date() Return the default value for :attr:`create_date`. Class methods: .. classmethod:: ModelStorage.create(vlist) Create records. ``vlist`` is list of dictionaries with fields names as key and created values as value and return the list of new instances. .. classmethod:: ModelStorage.trigger_create(records) Trigger create actions. It will call actions defined in ``ir.trigger`` if ``on_create`` is set and ``condition`` is true. .. classmethod:: ModelStorage.read(ids[, fields_names]) 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. .. classmethod:: ModelStorage.write(records, values, [[records, values], ...]) Write ``values`` on the list of records. ``values`` is a dictionary with fields names as key and writen values as value. .. classmethod:: ModelStorage.trigger_write_get_eligibles(records) Return eligible records for write actions by triggers. This dictionary is to pass to :meth:`~ModelStorage.trigger_write`. .. classmethod:: ModelStorage.trigger_write(eligibles) Trigger write actions. It will call actions defined in ``ir.trigger`` if ``on_write`` is set and ``condition`` was false before :meth:`~ModelStorage.write` and true after. .. classmethod:: ModelStorage.delete(records) Delete records. .. classmethod:: ModelStorage.trigger_delete(records) Trigger delete actions. It will call actions defined in ``ir.trigger`` if ``on_delete`` is set and ``condition`` is true. .. classmethod:: ModelStorage.copy(records[, default]) Duplicate the records. ``default`` is a dictionary of default value for the created records. .. classmethod:: ModelStorage.search(domain[, offset[, limit[, order[, count]]]]) Return a list of records that match the :ref:`domain `. .. classmethod:: ModelStorage.search_count(domain) Return the number of records that match the :ref:`domain `. .. classmethod:: ModelStorage.search_read(domain[, offset[, limit[, order[, fields_names]]]]) Call :meth:`search` and :meth:`read` at once. Useful for the client to reduce the number of calls. .. classmethod:: ModelStorage.search_rec_name(name, clause) Searcher for the :class:`trytond.model.fields.Function` field :attr:`rec_name`. .. classmethod:: ModelStorage.search_global(cls, text) Yield tuples (record, name, icon) for records matching text. It is used for the global search. .. classmethod:: ModelStorage.browse(ids) Return a list of record instance for the ``ids``. .. classmethod:: ModelStorage.export_data(records, fields_names) 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. .. classmethod:: ModelStorage.import_data(fields_names, data) 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. .. classmethod:: ModelStorage.check_xml_record(records, values) 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. .. classmethod:: ModelStorage.check_recursion(records[, parent]) Helper method that checks if there is no recursion in the tree composed with ``parent`` as parent field name. .. classmethod:: ModelStorage.validate(records) 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: .. classmethod:: ModelStorage.save(records) Save the modification made on the records. Instance methods: .. method:: ModelStorage.get_rec_name(name) Getter for the :class:`trytond.model.fields.Function` field :attr:`rec_name`. ======== ModelSQL ======== .. class:: ModelSQL It implements :class:`ModelStorage` for an SQL database. Class attributes are: .. attribute:: ModelSQL._table The name of the database table which is mapped to the class. If not set, the value of :attr:`Model._name` is used with dots converted to underscores. .. attribute:: ModelSQL._order 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 :class:`fields.Many2One`, it is also possible to use the dotted notation to sort on a specific field from the target record. .. attribute:: ModelSQL._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 model. If not set, :attr:`ModelStorage._rec_name` will be used. .. attribute:: ModelSQL._history If true, all changes on records will be stored in a history table. .. attribute:: ModelSQL._sql_constraints A list of SQL constraints that are added on the table: [ ('constraint name', constraint, 'error message key'), ... ] - `constraint name` is the name of the SQL constraint in the database - constraint is an instance of :class:`Constraint` - `error message key` is the key of :attr:`_sql_error_messages` .. attribute:: ModelSQL._sql_error_messages Like :attr:`Model._error_messages` but for :attr:`_sql_constraints` Class methods: .. classmethod:: ModelSQL.__table__() Return a SQL Table instance for the Model. .. classmethod:: ModelSQL.table_query() Could be overrided to use a custom SQL query instead of a table of the database. It should return a SQL FromItem. .. warning:: By default all CRUD operation will raise an error on models implementing this method so the create, write and delete methods may also been overriden if needed. .. .. classmethod:: ModelSQL.history_revisions(ids) Return a sorted list of all revisions for ids. The list is composed of the date, id and username of the revision. .. classmethod:: ModelSQL.restore_history(ids, datetime) 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. .. .. classmethod:: ModelSQL.restore_history_before(ids, datetime) 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. .. .. classmethod:: ModelStorage.search(domain[, offset[, limit[, order[, count[, query]]]]]) Return a list of records that match the :ref:`domain ` or the sql query if query is True. .. classmethod:: ModelSQL.search_domain(domain[, active_test[, tables]]) Convert a :ref:`domain ` into a SQL expression by returning the updated tables dictionary and a SQL expression. .. _ref-tables: Where ``tables`` is a nested dictionary containing the existing joins:: { None: (, None), 'party': { None: (
, ), 'addresses': { None: (
, ), }, }, } Constraint ========== .. class:: Constraint(table) It represents a SQL constraint on a table of the database and it follows the API of the python-sql expression. Instance attributes: .. attribute:: Constraint.table The SQL Table on which the constraint is defined. Check ----- .. class:: Check(table, expression) It represents a check :class:`Constraint` which enforce the validity of the expression. Instance attributes: .. attribute:: Check.expression The SQL expression to check. Unique ------ .. class:: Unique(table, \*columns) It represents a unique :class:`Constraint` which enforce the uniqeness of the group of columns with respect to all the rows in the table. Instance attributes: .. attribute:: Unique.columns The tuple of SQL Column instances. ======== Workflow ======== .. class:: Workflow A Mix-in class to handle transition check. Class attribute: .. attribute:: Workflow._transition_state The name of the field that will be used to check state transition. .. attribute:: Workflow._transitions A set containing tuples of from and to state. Static methods: .. staticmethod:: Workflow.transition(state) Decorate method to filter ids for which the transition is valid and finally to update the state of the filtered ids. ============== ModelSingleton ============== .. class:: ModelSingleton Modify :class:`ModelStorage` into a singleton_. This means that there will be only one record of this model. It is commonly used to store configuration value. .. _singleton: http://en.wikipedia.org/wiki/Singleton_pattern Class methods: .. classmethod:: ModelSingleton.get_singleton() Return the instance of the unique record if there is one. =============== DictSchemaMixin =============== .. class:: DictSchemaMixin A mixin_ for the schema of :class:`trytond.model.fields.Dict` field. Class attributes are: .. attribute:: DictSchemaMixin.name The definition of the :class:`trytond.model.fields.Char` field for the name of the key. .. attribute:: DictSchemaMixin.string The definition of the :class:`trytond.model.fields.Char` field for the string of the key. .. attribute:: DictSchemaMixin.type\_ The definition of the :class:`trytond.model.fields.Selection` field for the type of the key. The available types are: * boolean * integer * char * float * numeric * date * datetime * selection .. attribute:: DictSchemaMixin.digits The definition of the :class:`trytond.model.fields.Integer` field for the digits number when the type is `float` or `numeric`. .. attribute:: DictSchemaMixin.selection The definition of the :class:`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. .. attribute:: DictSchemaMixin.selection_sorted If the :attr:`selection` must be sorted on label by the client. .. attribute:: DictSchemaMixin.selection_json The definition of the :class:`trytond.model.fields.Function` field to return the JSON_ version of the :attr:`selection`. Static methods: .. staticmethod:: DictSchemaMixin.default_digits() Return the default value for :attr:`digits`. Class methods: .. classmethod:: DictSchemaMixin.get_keys(records) Return the definition of the keys for the records. Instance methods: .. method:: DictSchemaMixin.get_selection_json(name) Getter for the :attr:`selection_json`. ========== MatchMixin ========== .. class:: MatchMixin A mixin_ to add to a :class:`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: .. method:: MatchMixin.match(pattern) Return if the instance match the pattern ========== UnionMixin ========== .. class:: UnionMixin A mixin_ to create a :class:`ModelSQL` which is the UNION_ of some :class:`ModelSQL`'s. The ids of each models are sharded to be unique. Static methods: .. staticmethod:: UnionMixin.union_models() Return the list of :class:`ModelSQL`'s names Class methods: .. classmethod:: UnionMixin.union_shard(column, model) Return a SQL expression that shards the column containing record id of model name. .. classmethod:: UnionMixin.union_unshard(record_id) Return the original instance of the record for the sharded id. .. classmethod:: UnionMixin.union_column(name, field, table, Model) Return the SQL column that corresponds to the field on the union model. .. classmethod:: UnionMixin.union_columns(model) Return the SQL table and columns to use for the UNION for the model name. .. _mixin: http://en.wikipedia.org/wiki/Mixin .. _JSON: http://en.wikipedia.org/wiki/Json .. _UNION: http://en.wikipedia.org/wiki/Union_(SQL)#UNION_operator trytond-3.8.3/doc/ref/tools/0000755000175000017500000000000012655425163015232 5ustar cedced00000000000000trytond-3.8.3/doc/ref/tools/singleton.rst0000644000175000017500000000036312615705746017774 0ustar cedced00000000000000.. _ref-tools-singleton: .. module:: trytond.tools.singleton ========= Singleton ========= .. class:: Singleton A class to use as metaclass to create a `singleton`_ object. .. _`singleton`: http://en.wikipedia.org/wiki/Singleton_pattern trytond-3.8.3/doc/ref/index.rst0000644000175000017500000000026512615705746015742 0ustar cedced00000000000000.. _ref-index: ============= API Reference ============= .. toctree:: :maxdepth: 1 models/index wizard pyson transaction tools/singleton pool rpc trytond-3.8.3/doc/ref/pool.rst0000644000175000017500000000214612651525744015602 0ustar cedced00000000000000.. _ref-pool: .. module:: trytond.pool ==== Pool ==== .. class:: Pool([database_name]) The Pool store the instances of models, wizards and reports per database. Static methods: .. staticmethod:: Pool.register(klass[, type]) Register a class of type (default: `model`). Class methods: .. classmethod:: Pool.start() Start the pool by registering all Tryton modules found. .. classmethod:: Pool.stop(database_name) Stop the pool by removing instances for the database. .. classmethod:: Pool.database_list() List all started database. Instance methods: .. method:: Pool.get(name[, type]) Return the named instance of type from the pool. .. method:: Pool.iterobject([type]) Return an interator over instances names. .. method:: Pool.setup(module) Setup classes for module and return a list of classes for each type in a dictionary. ======== PoolMeta ======== .. class:: PoolMeta The PoolMeta is a metaclass helper to setup __name__ on class to be registered in the Pool. ======== PoolBase ======== .. class:: PoolBase The base class of registered class that will be setup. trytond-3.8.3/doc/ref/pyson.rst0000644000175000017500000002013412651525744015776 0ustar cedced00000000000000.. _ref-pyson: .. module:: trytond.pyson ===== PYSON ===== PYSON is the PYthon Statement and Object Notation. There is also a more :ref:`practical introduction into PYSON statements `. .. class:: PYSON Base class of any PYSON statement. It is never used directly. Instance methods: .. method:: PYSON.pyson() Method that returns the internal dictionary representation of the statement. .. method:: PYSON.types() Method that returns a set of all possible types which the statement can become when evaluated. .. classmethod:: PYSON.eval(dct, context) Method which returns the evaluation of the statement given in ``dct`` within the ``context``. ``dct`` contains a dictionary which is the internal representation of a PYSON statement. ``context`` contains a dictionary with contextual values. Encoder and Decoder =================== .. class:: PYSONEncoder() Encoder for PYSON statements into string representations. Instance method: .. method:: PYSONEncoder.encode(object) Returns a string representation of a given PYSON statement. ``object`` contains a PYSON statement. .. class:: PYSONDecoder([context[, noeval]]) Decoder for string into the evaluated or not PYSON statement. Instance method: .. method:: PYSONDecoder.decode(object) Returns a PYSON statement evaluated or not of a given string. ``object`` contains a string. Statements ========== The following statements can be used in :class:`PYSON`. .. class:: Eval(value[, default]) An :class:`Eval()` object represents the PYSON ``Eval()`` statement for evaluations. When evaluated, it returns the value of the statement named by ``value``, if defined in the evaluation context, otherwise the ``default`` value (empty string by default). Returns an instance of itself. .. note:: The default value determines the type of the statement. .. .. class:: Not(value) A :class:`Not` object represents the PYSON ``Not()`` statement for logical negations. When evaluated, returns the boolean negation of the value of the statement named by ``value``, if defined in the evaluation context. Returns an instance of itself. .. class:: Bool(value) A :class:`Bool` object represents the PYSON ``Bool()`` statement for boolean evaluations. Returns the boolean representation of the value of the statement named by ``value``. .. class:: And(\*statements) An :class:`And` object represents the PYSON ``And()`` statement for logical *and* operations. Returns the result of the logical conjunction of two or more values named by the statements in the ``statements`` tuple. .. class:: Or(\*statements) An :class:`Or` object represents the PYSON ``Or()`` statement for logical *or* operations. Returns the result of the logical disjunction of two or more values named by the statements in the ``statements`` tuple. .. class:: Equal(statement1, statement2) An :class:`Equal` object represents the PYSON ``Equal()`` statement for equation comparisons. Returns true when a value of a statement named by ``statement1`` and the value of a statement named by ``statement2`` are equal, otherwise returns false. .. class:: Greater(statement1, statement2[, equal]) A :class:`Greater` object represents the PYSON ``Greater()`` statement for *greater-than* comparisons. Returns true when the value of the statement named by ``statement1`` is strictly greater than the value of the statement named by ``statement2``, otherwise returns false. Is the value of the variable named by ``equal`` is true, then returns also true when both values of statements named by ``statement1`` and ``statement2`` are equal. In this case :class:`Greater` works as a *greater-than or equal* operator. .. class:: Less(statement1, statement2[, equal]) A :class:`Less` object represents the PYSON ``Less()`` statement for *less-than* comparisons. Returns true when the value of the statement named by ``statement1`` is strictly less than the value of the statement named by ``statement2``, otherwise returns false. Is the value of the variable named ``equal`` is true, then returns also true when both values of the statements named by ``statement1`` and ``statement2`` are equal. In this case :class:`Less` works as a *less-than or equal* operator. .. class:: If(condition, then_statement, else_statement) An :class:`If` object represents the PYSON ``If()`` statement for conditional flow control operations. Returns the value of the statement named by ``then_statement`` when the value of the statement named by ``condition`` evaluates true. Otherwise returns the value of the statement named by ``else_statement``. .. class:: Get(obj, key[, default]) A :class:`Get` object represents the PYSON ``Get()`` statement for dictionary look-up operations and evaluation. Look up and returns the value of a key named by ``key`` in an object named by ``obj`` if defined. Otherwise returns the value of the variable named by ``default``. .. class:: In(key, obj) An :class:`In` object represents the PYSON ``In()`` statement for look-up dictionary or integer objects. Returns true when a list (or dictionary) object named by ``obj`` contains the value of the variable (or key) named by ``key``. Otherwise returns false. .. class:: Date([year[, month[, day[, delta_years[, delta_month[, delta_days]]]]]]) A :class:`Date` object represents the PYSON ``Date()`` statement for date related conversions and basic calculations. Returns a date object which represents the values of arguments named by the *variables* explained below. Missing values of arguments named by ``year`` or ``month`` or ``day`` take their defaults from the actual date. When values of arguments named by ``delta_*`` are given, they are added to the values of the appropriate arguments in a date and time preserving manner. Arguments: ``year`` Contains a PYSON statement of type int or long. ``month`` Contains a PYSON statement of type int or long. ``day`` Contains a PYSON statement of type int or long. ``delta_years`` Contains a PYSON statement of type int or long. ``delta_month`` Contains a PYSON statement of type int or long. ``delta_days`` Contains a PYSON statement of type int or long. .. class:: DateTime([year[, month[, day[, hour[, minute[, second[, microsecond[, delta_years[, delta_months[, delta_days[, delta_hours[, delta_minutes[, delta_seconds[, delta_microseconds]]]]]]]]]]]]]]) A :class:`DateTime` object represents the PYSON ``Date()`` statement for date and time related conversions and calculations. Returns a date time object which represents the values of variables named by the *arguments* explained below. Missing values of arguments named by ``year``, ``month``, ``day``, ``hour``, ``minute``, ``second``, ``microseconds`` take their defaults from the actual date and time. When values of arguments named by ``delta_*`` are given, these are added to the appropriate attributes in a date and time preserving manner. Arguments: ``year`` Contains a PYSON statement of type int or long. ``month`` Contains a PYSON statement of type int or long. ``day`` Contains a PYSON statement of type int or long. ``hour`` Contains a PYSON statement of type int or long. ``minute`` Contains a PYSON statement of type int or long. ``second`` Contains a PYSON statement of type int or long. ``microsecond`` Contains a PYSON statement of type int or long. ``delta_years`` Contains a PYSON statement of type int or long. ``delta_month`` Contains a PYSON statement of type int or long. ``delta_days`` Contains a PYSON statement of type int or long. ``delta_hours`` Contains a PYSON statement of type int or long. ``delta_minutes`` Contains a PYSON statement of type int or long. ``delta_seconds`` Contains a PYSON statement of type int or long. ``delta_microseconds`` Contains a PYSON statement of type int or long. .. class:: Len(value) A :class:`Len` object represents the PYSON ``Len()`` statement for length of a dictionary, list or string. Returns the number of items in ``value``. .. class:: Id(module, fs_id) An :class:`Id` object represents the PYSON ``Id()`` statement for filesystem id evaluations. When converted into the internal dictionary, it returns the database id stored in `ir.model.data`. trytond-3.8.3/doc/ref/rpc.rst0000644000175000017500000000110212651525744015404 0ustar cedced00000000000000.. _ref-rpc: .. module:: trytond.rpc === RPC === .. class:: RPC([readonly[, instantiate[, result[, check_access]]]]) RPC is an object to define the behavior of Remote Procedur Call. Instance attributes are: .. attribute:: RPC.readonly The transaction mode .. attribute:: RPC.instantiate The position or the slice of the argument to be instanciated .. attribute:: RPC.result The function to transform the result .. attribute:: RPC.check_access Set `_check_access` in the context to activate the access right on model and field. Default is `True`. trytond-3.8.3/doc/ref/transaction.rst0000644000175000017500000000425612651525744017162 0ustar cedced00000000000000.. _ref-transaction: .. module:: trytond.transaction =========== Transaction =========== .. class:: Transaction This class is a `singleton`_ that contains thread-local parameters of the database transaction. .. _`singleton`: http://en.wikipedia.org/wiki/Singleton_pattern .. attribute:: Transaction.cursor The database cursor. .. attribute:: Transaction.database The database. .. attribute:: Transaction.user The id of the user. .. attribute:: Transaction.context .. attribute:: Transaction.create_records .. attribute:: Transaction.delete_records .. attribute:: Transaction.delete .. attribute:: Transaction.timestamp .. attribute:: Transaction.language The language code defines in the context. .. attribute:: Transaction.counter Count the number of modification made in this transaction. .. method:: Transaction.start(database_name, user[, readonly[, context[, close[, autocommit]]]]) Start a new transaction and return a `context manager`_. .. method:: Transaction.stop() Stop a started transaction. This method should not be called directly as it will be by the context manager when exiting the `with` statement. .. method:: Transaction.set_context(context, \**kwargs) Update the transaction context and return a `context manager`_. The context will be restored when exiting the `with` statement. .. method:: Transaction.set_user(user[, set_context]) Modify the user of the transaction and return a `context manager`_. `set_context` will put the previous user id in the context to simulate the record rules. The user will be restored when exiting the `with` statement. .. method:: Transaction.set_cursor(cursor) Modify the cursor of the transaction and return a `context manager`_. The previous cursor will be restored when exiting the `with` statement. .. method:: Transaction.new_cursor([autocommit[, readonly]]) Change the cursor of the transaction with a new one on the same database and return a `context manager`_. The previous cursor will be restored when exiting the `with` statement and the new one will be closed. .. _`context manager`: http://docs.python.org/reference/datamodel.html#context-managers trytond-3.8.3/doc/ref/wizard.rst0000644000175000017500000001200512651525744016124 0ustar cedced00000000000000.. _ref-wizard: .. module:: trytond.wizard ====== Wizard ====== A wizard is a `finite state machine`_. There is also a more :ref:`practical introduction into wizards `. .. _`finite state machine`: http://en.wikipedia.org/wiki/Finite-state_machine .. class:: Wizard(session_id) This is the base for any wizard. It contains the engine for the finite state machine. A wizard must have some :class:`State` instance attributes that the engine will use. Class attributes are: .. attribute:: Wizard.__name__ It contains the unique name to reference the wizard throughout the platform. .. attribute:: Wizard.start_state It contains the name of the starting state. .. attribute:: Wizard.end_state It contains the name of the ending state. If an instance method with this name exists on the wizard, it will be called on deletion of the wizard and it may return one of the :ref:`client side action keywords `. .. attribute:: Wizard.__rpc__ Same as :attr:`trytond.model.Model.__rpc__`. .. attribute:: Wizard.states It contains a dictionary with state name as key and :class:`State` as value. Class methods are: .. classmethod:: Wizard.__setup__() Setup the class before adding into the :class:`trytond.pool.Pool`. .. classmethod:: Wizard.__post_setup__() Setup the class after added into the :class:`trytond.pool.Pool`. .. classmethod:: Wizard.__register__(module_name) Register the wizard. .. classmethod:: Wizard.create() Create a session for the wizard and returns a tuple containing the session id, the starting and ending state. .. classmethod:: Wizard.delete(session_id) Delete the session. .. classmethod:: Wizard.execute(session_id, data, state_name) Execute the wizard for the state. `session_id` is a session id. `data` is a dictionary with the session data to update. `active_id`, `active_ids`, `active_model` and `action_id` must be set in the context according to the records on which the wizard is run. ===== State ===== .. class:: State() This is the base for any wizard state. Instance attributes are: .. attribute:: State.name The name of the state. ========= StateView ========= .. class:: StateView(model_name, view, buttons) A :class:`StateView` is a state that will display a form in the client. The form is defined by the :class:`~trytond.model.ModelView` with the name `model_name`, the `XML` id in `view` and the `buttons`. The default value of the view can be set with a method on wizard having the same name as the state but starting with `default_`. Instance attributes are: .. attribute:: StateView.model_name The name of the :class:`~trytond.model.ModelView`. .. attribute:: StateView.view The `XML` id of the form view. .. attribute:: StateView.buttons The list of :class:`Button` instances to display on the form. Instance methods are: .. method:: StateView.get_view(wizard, state_name) Returns the view definition like :meth:`~trytond.model.ModelView.fields_view_get`. * wizard is a :class:`Wizard` instance * state_name is the name of the :class:`StateView` instance .. method:: StateView.get_defaults(wizard, state_name, fields) Return default values for the fields. * wizard is a :class:`Wizard` instance * state_name is the name of the :class:`State` * fields is the list of field names .. method:: StateView.get_buttons(wizard, state_name) Returns button definitions of the wizard. * wizard is a :class:`Wizard` instance * state_name is the name of the :class:`StateView` instance =============== StateTransition =============== .. class:: StateTransition() A :class:`StateTransition` brings the wizard to the `state` returned by the method having the same name as the state but starting with `transition_`. =========== StateAction =========== .. class:: StateAction(action_id) A :class:`StateAction` is a :class:`StateTransition` which let the client launch an `ir.action`. This action definition can be customized with a method on wizard having the same name as the state but starting with `do_`. Instance attributes are: .. attribute:: StateAction.action_id The `XML` id of the `ir.action`. Instance methods are: .. method:: StateAction.get_action() Returns the `ir.action` definition. =========== StateReport =========== .. class:: StateReport(report_name) A :class:`StateReport` is a :class:`StateAction` which find the report action by name instead of `XML` id. ====== Button ====== .. class:: Button(string, state[, icon[, default]]) A :class:`Button` is a single object containing the definition of a wizard button. Instance attributes are: .. attribute:: Button.string The label display on the button. .. attribute:: Button.state The next state to reach if button is clicked. .. attribute:: Button.icon The name of the icon to display on the button. .. attribute:: Button.default A boolean to set it as default on the form. trytond-3.8.3/doc/topics/0000755000175000017500000000000012655425163014617 5ustar cedced00000000000000trytond-3.8.3/doc/topics/models/0000755000175000017500000000000012655425163016102 5ustar cedced00000000000000trytond-3.8.3/doc/topics/models/fields_default_value.rst0000644000175000017500000000141212615705746023004 0ustar cedced00000000000000.. _topics-fields_default_value: ======================= Default value of fields ======================= When a record is created, each field, which doesn't have a value specified, is set with the default value if exists. The following class method:: Model.default_() Return the default value for ``field name``. This example defines an ``Item`` model which has a default ``since``:: import datetime from trytond.model import ModelView, ModelSQL, fields class Item(ModelSQL, ModelView): "Item" __name__ = 'item' since = fields.Date('since') @classmethod def default_since(cls): return datetime.date.today() See also method ``Model.default_get``: :attr:`~trytond.model.Model.default_get` trytond-3.8.3/doc/topics/models/fields_on_change.rst0000644000175000017500000000217612651525744022113 0ustar cedced00000000000000.. _topcis-fields_on_change: =================== on_change of fields =================== Tryton allows developers to define methods that can be called once a field's value has changed by the user this is the :ref:`ref-models-fields-on_change` method. The method has the following name:: Model.on_change_ This is an instance method, an instance of ``Model`` will be created by using the values from the form's fields specified by the ``on_change`` list defined on the field. Any change made on the instance will be pushed back to the client-side record. There is also a way to define a method that must update a field whenever any field from a predefined list is modified. This list is defined by the :ref:`ref-models-fields-on_change_with` attribute of the field. The method that will be called has the following name:: Model.on_change_with_ Just like for the classic ``on_change``, an instance of ``Model`` will be created by using the values entered in the form's fields specified by the ``on_change_with`` attribute. The method must return the new value of the field to push back to the client-side record. trytond-3.8.3/doc/topics/models/index.rst0000644000175000017500000000253112651525744017746 0ustar cedced00000000000000.. _topics-models: ====== Models ====== A model represents a single business logic or concept. It contains fields and defines the behaviors of the record. Most of the time, each model stores records in a single database table. The basics: * Each model is a Python class that subclasses one of :class:`trytond.model.model.Model`. * :ref:`Fields ` are defined as model attributes. * Tryton generates the table definitions * Tryton provides an API following the `active record pattern`_ to access the records. .. _active record pattern: http://en.wikipedia.org/wiki/Active_record Example ======= This example defines a ``Party`` model which has a ``name`` and a ``code`` fields:: from trytond.model import ModelView, ModelSQL, fields from trytond.pool import Pool class Party(ModelSQL, ModelView): "Party" __name__ = "party.party" name = fields.Char('Name') code = fields.Char('Code') Pool.register(Party) The class must be registered in the :ref:`Pool `. Model classes are essentially data mappers to records and Model instances are records. Model attributes 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. trytond-3.8.3/doc/topics/modules/0000755000175000017500000000000012655425163016267 5ustar cedced00000000000000trytond-3.8.3/doc/topics/modules/index.rst0000644000175000017500000001227412651525744020140 0ustar cedced00000000000000.. _topics-modules: ======= Modules ======= The modules of Tryton extend the functionality of the platform. The server comes by default with only a basic functionality included in these modules: ``ir``, ``res``, ``webdav``. Module Structure ================ A module is a directory in trytond/modules which contains at least two files: * ``__init__.py``: a Tryton module must be a Python module. * ``tryton.cfg``: a Configuration file that describes the Tryton module. ``__init__.py`` file -------------------- It is the Python ``__init__.py`` to define a module. It must contains a method named `register()` that must register to the pool all the objects of the module. ``tryton.cfg`` file ------------------- It is a configuration file using the format of `ConfigParser`_ that must contain `tryton` section with this following name: * ``version``: The version number of the module. * ``depends``: A one per line list of modules on which this module depends. * ``extras_depend``: A one per line list of modules on which this module *may* depend. * ``xml``: The one per line list of the XML files of the module. They will be loaded in the given order at the installation or update of the module. Here is an example:: [tryton] version=0.0.1 depends: ir res country xml: party.xml category.xml address.xml contact_mechanism.xml Python Files ============ The Python files define the models for the modules. XML Files ========= The XML files define data that will be inserted into the database. There is an rnc for those files stored in ``trytond/tryton.rnc``. The following snippet gives a first idea of what an xml file looks: .. highlight:: xml :: Party Administration party.party tree ]]> Here is the list of the tags: * ``tryton``: The main tag of the xml * ``data``: Define a set of data inside the file. It can have the attributes: * ``noupdate`` to prevent the framework to update the records, * ``skiptest`` to prevent import of data when running tests, * ``depends`` to import data only if all modules in the comma separated module list value are installed, * ``grouped`` to create records at the end with a grouped call. * ``record``: Create a record of the model defined by the attribute ``model`` in the database. The ``id`` attribute can be used to refer to the record later in any xml file. * ``field``: Set the value of the field with the name defined by the attribute ``name``. Here is the list of attributes: * ``search``: Only for relation field. It contains a domain which is used to search for the value to use. The first value found will be used. * ``ref``: Only for relation field. It contains an xml id of the relation to use as value. It must be prefixed by the module name with an ending dot, if the record is defined in an other module. * ``eval``: Python code to evaluate and use result as value. * ``pyson``: convert the evaluated value into :ref:`PYSON ` string. .. note:: Field content is considered as a string. So for fields that require other types, it is required to use the ``eval`` attribute. .. * ``menuitem``: Shortcut to create ir.ui.menu records. Here is the list of attributes: * ``id``: The id of the menu. * ``name``: The name of the menu. * ``icon``: The icon of the menu. * ``sequence``: The sequence value used to order the menu entries. * ``parent``: The xml id of the parent menu. * ``action``: The xml id of the action linked to the menu. * ``groups``: A list of xml id of group, that have access to the menu, separated by commas. * ``active``: A boolean telling if the menu is active or not. .. _ConfigParser: http://docs.python.org/library/configparser.html trytond-3.8.3/doc/topics/reports/0000755000175000017500000000000012655425163016315 5ustar cedced00000000000000trytond-3.8.3/doc/topics/reports/index.rst0000644000175000017500000001647612651525744020176 0ustar cedced00000000000000.. _topics-reports: ======= Reports ======= Tryton can generate dynamic reports in many formats from templates. The reports are generated in one step as follows: a report template in a special file format, explained later, is interpolated with dynamic data and placed into a document of the same file format. Tryton's ability to generate documents in this way allows documents to be generated for any editor that supports the Open Document Format which can be converted to third party formats, such as PDF. Extra libraries are required for this, see INSTALL for more information. Report Templates ================ Report templates are files with a format supported by relatorio, that contain snippets of the Genshi templating language. Here is an example of the text that would be placed in an open document text document, ``*.odt``, that displays the full name and the address lines of the first address of each party. The genshi code is placed in the template using ``Functions->Placeholder->Text`` Fields. These are specific to ODT files. .. highlight:: genshi :: Report API ========== Python API ---------- .. TODO XML Description --------------- When defining an `ir.action.report` the following attributes are available: * ``name``: The name of the report. * ``report_name``: The name of the report model, for example my_module.my_report. This is the name you would use with `Pool().get` * ``model``: If this report is of an existing model this is its name. For example my_module.my_model. Custom reports that aren't of a specific model will need to leave this blank. * ``report``: The path to the template file starting with the module, for example my_module/my_report.odt. * ``template_extension``: The template format. Report Usage ============ Using genshi and open office reports ------------------------------------ Setting up an ODT file ^^^^^^^^^^^^^^^^^^^^^^ If you are creating a report from scratch you should perform the following steps: - Remove user data * "File > Properties..." * Uncheck "Apply user data" * Click on "Reset" - Select Style and Formatting * Press F11 or "Format > Style and Formatting" * Click on the drop down at the right top * Select "Load Styles" * Click on "From File..." * Select a existing report (``company/header_A4.odt``) - Set some parameters * Set the zoom to 100% (View>Zoom) * Set the document in read-only mode (``Tools>Options>OpenOffice.org>Security``) (Decreases the time it takes to open the document.) - Usage * Use Liberation fonts (Only necessary if being officially included in Tryton) * Try to use styles in report templates so that they can be extended. Using Genshi in an ODT file ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The genshi code is placed in the template using Functions->Placeholder->Text Fields. These are specific to ``*.odt`` files and can be found in the open office menu at Insert -> Fields -> Other and then Functions -> Placeholder -> Text. Type genshi code into the Placeholder field. There are alternatives for embedding genshi that are supported by relatorio but their use is not encouraged within Tryton. Also note that relatorio only supports a subset of genshi. The directives that are supported by relatorio can be found here: `Quick Example`_ . See genshi's documentation for more information: `Genshi XML Templates`_ Examples ^^^^^^^^ The modules company, account_invoice and stock all contain helpful examples. Also see relatorio's site for some examples: - `Quick Example`_ - `In Depth Introduction`_ - `Example Documents`_ Accessing models from within the report --------------------------------------- By default instances of the models the report is for are passed in to the report via a list of objects called `objects`. These objects behave just as they would within trytond itself. You can access any of the models relations as well. For example within the invoice report each object is an invoice and you can access the name of the party of the invoice via `invoice.party.name`. Additional objects can be passed to a report. This is discussed below in `Passing custom data to a report`. Within Tryton the underlying model the report can be found by following the Menu to ``Administration > UI > Actions > Report``. Furthermore in tryton the fields for that model can be found by following the menu to ``Administration > Model > Model``. Model relation fields can be accessed to any depth, for example, one could access `invoice.party.addresses` to get a list of addresses for the party of an invoice. Creating a simple report template for a model from client --------------------------------------------------------- TODO: Explain the steps necessary to do this. Creating a simple report template for a model in XML ---------------------------------------------------- Less work has to be done if you just want a simple report representation of a model. There are just 2 steps. First, create a report template file in a format supported by relatorio. Second, describe your report in XML making sure to define the correct ``report_name`` and ``model``. Replacing existing Tryton reports --------------------------------- To replace an existing report you must deactivate the old report and activate the new report. For example to deactivate the invoice report: .. highlight:: xml :: Then you must activate the new invoice report that exists in your new module: .. highlight:: xml :: Invoice account.invoice account.invoice my_module/invoice.odt odt Passing custom data to a report ------------------------------- TODO: Examples of overriding Report.execute. In this example `Report.get_context` is overridden and an employee object is set into context. Now the invoice report will be able to access the employee object. .. highlight:: python :: from trytond.report import Report from tryton.pool import Pool class InvoiceReport(Report): __name__ = 'account.invoice' @classmethod def get_context(cls, records, data): pool = Pool() Employee = pool.get('company.employee') context = super(InvoiceReport, cls).get_context(records, data) employee_id = Transaction().context.get('employee') employee = Employee(employee_id) if employee_id else None context['employee'] = employee return context Pool.register(InvoiceReport, type_='report') .. _Genshi XML Templates: http://genshi.edgewall.org/wiki/Documentation/0.5.x/xml-templates.html .. _Quick Example: http://code.google.com/p/python-relatorio/wiki/QuickExample .. _In Depth Introduction: http://code.google.com/p/python-relatorio/wiki/IndepthIntroduction .. _Example Documents: http://code.google.com/p/python-relatorio/source/browse/#hg%2Fexamples trytond-3.8.3/doc/topics/views/0000755000175000017500000000000012655425163015754 5ustar cedced00000000000000trytond-3.8.3/doc/topics/views/extension.rst0000644000175000017500000000234412615705746020531 0ustar cedced00000000000000.. _topics-extension: ============== Extending View ============== Extending a view means, that the original view will be modified by a set of rules which are defined with XML. For this purpose, the extension engine uses xpath expressions. The view is defined with the field ``inherit`` of the ir.ui.view. If the field ``domain`` (a Python string representation of a :ref:`domain `) is not set or evaluated to True, the inheritance will be proceeded. XML Description =============== data ---- Each view must start with this tag. xpath ----- * ``expr``: the xpath expression to find a node in the inherited view. * ``position``: Define the position in relation to the node found. It can be ``before``, ``after``, ``replace``, ``inside`` or ``replace_attributes`` which will change the attributes. Example ======= .. highlight:: xml :: trytond-3.8.3/doc/topics/views/index.rst0000644000175000017500000005016412651525744017625 0ustar cedced00000000000000.. _topics-views: ===== Views ===== The views are used to display records of an :class:`ModelView ` to the user. In Tryton, :class:`ModelView ` can have several views. An `action` opens a window and defines which view to show. The views are built from XML that is stored in the `view` directory of the module or in the databases thanks to the model ir.ui.view. So generally, they are defined in xml files with this kind of xml where name is the name of the XML file in the `view` directory: .. highlight:: xml :: model name type name view_name There is three types of views: * Form * Tree * Graph Form view ========= The RNG describing the xml of a form view is stored in trytond/ir/ui/form.rng. There is also a RNC in trytond/ir/ui/form.rnc. A form view is used to display one record of an object. Elements of the view are put on the screen following the rules: * Elements are placed on the screen from left to right, from top to bottom, according to the order of the xml. * The screen composed of a table with a fixed number of columns and enough rows to handle all elements. * Elements take one or more columns when they are put in the table. If there are not enough free columns on the current row, the elements are put at the begining of the next row. XML description --------------- List of attributes shared by many form elements: .. _common-attributes-id: * ``id``: A unique identifier for the tag if there is no name attribute. .. _common-attributes-yexpand: * ``yexpand``: A boolean to specify if the label should expand to take up any extra vertical space. .. _common-attributes-yfill: * ``yfill``: A boolean to specify if the label should fill the vertical space allocated to it in the table cell. .. _common-attributes-yalign: * ``yalign``: The vertical alignment, from 0.0 to 1.0. .. _common-attributes-xexpand: * ``xexpand``: The same as yexpand but for horizontal space. .. _common-attributes-xfill: * ``xfill``: The same as yfill but for horizontal space. .. _common-attributes-xalign: * ``xalign``: The horizontal alignment, from 0.0 to 1.0. .. _common-attributes-colspan: * ``colspan``: The number of columns the widget must take in the table. .. _common-attributes-states: * ``states``: A string of :ref:`PYSON statement ` that will be evaluated with the values of the current record. It must return a dictionary where keys can be: * ``invisible``: If true, the widget will be hidden. * ``required``: If true, the field will be required. * ``readonly``: If true, the field will be readonly. * ``icon``: Only for button, it must return the icon name to use or False. * ``pre_validate``: Only for button, it contains a domain to apply on the record before calling the button. .. _common-attributes-help: * ``help``: The string that will be displayed when the cursor hovers over the widget. .. _common-attributes-pre_validate: * ``pre_validate``: A boolean only for fields :class:`trytond.model.fields.One2Many` to specify if the client must pre-validate the records using :meth:`trytond.model.Model.pre_validate`. .. _common-attributes-completion: * ``completion``: A boolean only for fields :class:`trytond.model.fields.Many2One`, :class:`trytond.model.fields.Many2Many` and :class:`trytond.model.fields.One2Many` to specifiy if the client must auto-complete the field. The default value is True. .. _common-attributes-factor: * ``factor``: A factor to apply on fields :class:`trytond.model.fields.Integer`, :class:`trytond.model.fields.Float` and :class:`trytond.model.fields.Numeric` to display on the widget. The default value is 1. form ^^^^ Each form view must start with this tag. * ``string``: The text that will be used as default title for the tab or the window. .. _form-attributes-on_write: * ``on_write``: The name of a method on the Model of the view that will be called when a record is saved. The method must return a list of record ids that the client must reload if they are already loaded. The function must have this syntax: ``on_write(self, ids)`` .. note:: The method must be registered in :attr:`trytond.model.Model.__rpc__`. .. * ``col``: The number of columns for the view. * ``cursor``: The name of the field that must have the cursor by default. label ^^^^^ Display static string. * ``string``: The string that will be displayed in the label. * ``name``: The name of the field whose description will be used for string. Except if ``string`` is set, it will use this value and the value of the field if ``string`` is empty. * ``id``: see common-attributes-id_. * ``yexpand``: see in common-attributes-yexpand_. * ``yfill``: see in common-attributes-yfill_. * ``yalign``: see in common-attributes-yalign_. * ``xexpand``: see in common-attributes-xexpand_. * ``xfill``: see in common-attributes-xfill_. * ``xalign``: see in common-attributes-xalign_. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. * ``help``: see in common-attributes-help_. * Requires that either ``id`` or ``name`` is defined. field ^^^^^ Display a field of the object with the value of the current record. * ``name``: The name of the field. * ``string``: The string that will be displayed for the widget. * ``widget``: The widget that must be used instead of the default one. * ``help``: The string that will be displayed when the cursor stays over the widget. * ``width``: The minimum width the widget should request, or -1 to unset. * ``height``: The minimum height the widget should request, or -1 to unset. * ``readonly``: Boolean to set the field readonly. * ``required``: Boolean to set the field required. * ``mode``: Only for One2Many fields: it is a comma separated list, that specifies the order of the view used to display the relation. (Example: ``tree,form``) * ``view_ids``: A comma separated list that specifies the view ids used to display the relation. * ``product``: Only for One2Many fields, a comma separated list of target field name used to create records from the cartesian product. * ``completion``: Only for Many2One fields, it is a boolean to set the completion of the field. * ``invisible``: The field will not be displayed, but it will fill cells in the table. * ``filename_visible``: Only for Binary fields, boolean that enables the display of the filename. * ``yexpand``: see in common-attributes-yexpand_. * ``yfill``: see in common-attributes-yfill_. * ``xexpand``: see in common-attributes-xexpand_. * ``xfill``: see in common-attributes-xfill_. * ``colspan``: see in common-attributes-colspan_. * ``help``: see in common-attributes-help_. * ``pre_validate``: see in common-attributes-pre_validate_. * ``completion``: see in common-attributes-completion_. * ``factor``: see in common-attributes-factor_. image ^^^^^ Display an image. * ``name``: the name of the image. It must be the name with the extension of an image from ``tryton/share/pixmaps/``. * ``yexpand``: see in common-attributes-yexpand_. * ``yfill``: see in common-attributes-yfill_. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. * ``help``: see in common-attributes-help_. separator ^^^^^^^^^ Display a horizontal separator. * ``string``: The string that will be displayed above the separator. * ``name``: The name of the field from which the description will be used for string. * ``id``: see in common-attributes-id_. * ``yexpand``: see in common-attributes-yexpand_. * ``yfill``: see in common-attributes-yfill_. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. * ``help``: see in common-attributes-help_. * Requires that either ``id`` or ``name`` is defined. newline ^^^^^^^ Force to use a new row. .. _form-button: button ^^^^^^ Display a button. * ``string``: The string that will be displayed inside the button. * ``name``: The name of the function that will be called. The function must have this syntax: ``button(cls, records)`` The function may return an `ir.action` id or one of those client side action keywords: .. _topics-views-client-actions: * ``new``: to create a new record * ``delete``: to delete the selected records * ``remove``: to remove the record if it has a parent * ``copy``: to copy the selected records * ``next``: to go to the next record * ``previous``: to go to the previous record * ``close``: to close the current tab * ``switch ``: to switch the view to the defined type * ``reload``: to reload the current tab * ``reload context``: to reload user context * ``reload menu``: to reload menu * ``icon`` * ``confirm``: A text that will be displayed in a confirmation popup when the button is clicked. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. * ``help``: see in common-attributes-help_. notebook ^^^^^^^^ It adds a notebook widget which can contain page tags. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. page ^^^^ Define a new tab inside a notebook. * ``string``: The string that will be displayed in the tab. * ``angle``: The angle in degrees between the baseline of the label and the horizontal, measured counterclockwise. * ``col``: The number of columns for the page view. * ``id``: see in common-attributes-id_. * ``states``: see in common-attributes-states_. * Requires that either ``id`` or ``name`` is defined. group ^^^^^ Create a sub-table in a cell. * ``string``: If set a frame will be drawn around the field with a label containing the string. Otherwise, the frame will be invisible. * ``rowspan``: The number of rows the group spans in the table. * ``col``: The number of columns for the group contains. * ``homogeneous``: If True all the tables cells are the same size. * ``id``: see in common-attributes-id_. * ``yexpand``: see in common-attributes-yexpand_. * ``yfill``: see in common-attributes-yfill_. * ``colspan``: see in common-attributes-colspan_. * ``states``: see in common-attributes-states_. * Requires that either ``id`` or ``name`` is defined. hpaned, vpaned ^^^^^^^^^^^^^^ * ``position``: The pixel position of divider, a negative value means that the position is unset. * ``id``: see in common-attributes-id_. * ``colspan``: see in common-attributes-colspan_. The default for panes is 4 columns. child ^^^^^ Contains the childs of a hpaned or vpaned. .. _example_form_view: Example ------- .. highlight:: xml ::