Metadata-Version: 2.5
Name: trytond_etude_bind
Version: 8.0.0.1
Summary: Etude Form Server — Bindings to Internal Models
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: binding,domain,form,survey,tryton
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Requires-Python: >=3.10
Requires-Dist: trytond-etude<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Description-Content-Type: text/x-rst

Etude Bind Module
=================

The ``etude_bind`` module binds the questions of a form to the records of an
internal model: a question can be *pre-filled* from a record, offer the records
as its *choices*, or have its answer *validated* against a record that exists.
It is a companion of the core module of the etude group - it depends on
``etude`` and extends its definition - and it is what turns a form into a
Tryton data-capture front end.

An answer that is read rather than typed
----------------------------------------

A form asks questions and a deployment usually already holds the answers: the
record of the participant, the party it speaks for, the asset an intake form
describes.  A binding attaches a question to a model and a field of it, and the
question is answered from a record rather than typed.

A binding names one model and the fields of it: the *target field* it reads,
the *key field* a record is matched by, and the *create/update policy* of the
mode that writes a record.  The modes this module carries are the three that
read:

- ``read`` pre-fills the question from a record, so a participant reads the
  name, the address or the reference of the record instead of retyping it;
- ``options`` populates the choices of the question from the records, so a
  question of a single choice offers what the deployment holds rather than a
  list frozen in the definition;
- ``validate`` checks that the answer names a record that exists, so a
  reference is stored only when it points at something.

What selects the record
-----------------------

A binding holds ``etude.binding.rule`` rows: a *domain*, an *order* and a
*limit*, read against the target model.  The rules of a binding are read in
their order and the first one that selects a record is the rule of the
binding, so a designer writes the case of the current user first and the case
of the party it names after it, and the binding reads the first case that
holds.

A text of a domain that names a question of the response by its code, written
``$reference``, is replaced by the answer of that question.  That is what makes
``validate`` check an answer against the record it itself names and what makes
``read`` pre-fill a question from the record an earlier answer already chose.

The target of a binding is a capability
---------------------------------------

A binding names the model and the field of another module, so it is refused
where it is written rather than trusted where it runs:

- the (model, field) pair a binding names must be whitelisted for one of the
  groups of the running user (``etude.binding.whitelist``); a pair outside the
  whitelist, and a field of another model than the target, are refused with the
  message that names what to correct;
- the running user must hold on the target the access the mode of the binding
  needs, so a user who may not reach a record can not name it as a target even
  when the pair is whitelisted;
- every access goes through the ORM (``Pool().get(...)``, no raw SQL), so
  ``ir.model.access``, the field accesses and the record rules of the
  deployment apply to a binding exactly as they apply to any other read.

The whitelist is readable by everybody, because a form is served to users who
hold no right on the configuration of the deployment, and it is written by the
administrators of the module and of the deployment alone: an entry grants a
capability to every user of a group.

Several bindings onto one record
--------------------------------

A record of a form is usually written from several answers at once - the
headings of a document and the lines it holds - so the bindings that write it
are gathered by an ``etude.binding.map``: the maps of a form that carry the
same *record* name describe the same record, the maps of the role *header*
write its fields and the maps of the role *line* write the lines it holds.

What a version freezes
----------------------

Editing a binding, a rule or a mapping is an edit of the definition of a form:
a published form opens the draft version the next publish completes, exactly
like editing a question or an option.  The bindings of a question and the
mappings of a form are part of the definition payload a version freezes, so a
response that pins a version is read against the targets that version named,
and restoring a version writes the bindings and the mappings back with the
pages of the form.

A target is named in the payload by the technical name of its model and the
name of its field rather than by their identifiers, because a restore recreates
the rows of a definition; a target this deployment does not hold is refused
rather than written as no target.

See ``doc/index.rst`` for the module documentation and ``ETUDE.md`` in
``modules-cch/`` for the architecture of the whole group.
