diff options
| author | Raphael Collet <rco@openerp.com> | 2014-07-06 16:44:26 +0200 |
|---|---|---|
| committer | Antony Lesuisse <al@openerp.com> | 2014-07-06 17:05:41 +0200 |
| commit | cbe2dbb672a6c55d86f2e515f9d1cdfee426ef80 (patch) | |
| tree | d6ff62b719fce32392397783c961b734b1e4c50e /doc | |
| parent | d78192c489d3be66cd6487b39f5ce7ba4733a187 (diff) | |
[MERGE] new v8 api by rco
A squashed merge is required as the conversion of the apiculture branch from
bzr to git was not correctly done. The git history contains irrelevant blobs
and commits. This branch brings a lot of changes and fixes, too many to list
exhaustively.
- New orm api, objects are now used instead of ids
- Environements to encapsulates cr uid context while maintaining backward compatibility
- Field compute attribute is a new object oriented way to define function fields
- Shared browse record cache
- New onchange protocol
- Optional copy flag on fields
- Documentation update
- Dead code cleanup
- Lots of fixes
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/03_module_dev_02.rst | 1 | ||||
| -rw-r--r-- | doc/03_module_dev_03.rst | 17 | ||||
| -rw-r--r-- | doc/api_models.rst | 18 | ||||
| -rw-r--r-- | doc/howto/howto_website.rst | 30 | ||||
| -rw-r--r-- | doc/howto/howto_website/basic-page | 4 | ||||
| -rw-r--r-- | doc/howto/howto_website/field-label | 22 | ||||
| -rw-r--r-- | doc/howto/howto_website/lectures-model-add | 40 | ||||
| -rw-r--r-- | doc/howto/howto_website/manifest | 11 | ||||
| -rw-r--r-- | doc/howto/howto_website/move-to-openerp-objects | 70 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-controller | 6 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-data | 2 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-html-biography | 17 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-model | 34 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-t-field | 11 | ||||
| -rw-r--r-- | doc/howto/howto_website/ta-view-fix | 15 | ||||
| -rw-r--r-- | doc/howto/howto_website/templates-basic | 29 | ||||
| -rw-r--r-- | doc/howto/howto_website/website-dependency | 26 | ||||
| -rw-r--r-- | doc/howto/howto_website/website-layoutify | 14 | ||||
| -rw-r--r-- | doc/index.rst | 7 | ||||
| -rw-r--r-- | doc/new_api.rst | 138 |
20 files changed, 334 insertions, 178 deletions
diff --git a/doc/03_module_dev_02.rst b/doc/03_module_dev_02.rst index 223c82d3f1c..ec7fa57d0dc 100644 --- a/doc/03_module_dev_02.rst +++ b/doc/03_module_dev_02.rst @@ -615,6 +615,7 @@ Relational Types reference. :guilabel:`relation` is the table to look up that reference in. +.. _fields-functional: Functional Fields +++++++++++++++++ diff --git a/doc/03_module_dev_03.rst b/doc/03_module_dev_03.rst index e5e309fe00e..74fb4772f84 100644 --- a/doc/03_module_dev_03.rst +++ b/doc/03_module_dev_03.rst @@ -70,15 +70,21 @@ As we can see below in the purple zone of the screen, there is also a way to dis On Change +++++++++ -The on_change attribute defines a method that is called when the content of a view field has changed. +The on_change attribute defines a method that is called when the +content of a view field has changed. -This method takes at least arguments: cr, uid, ids, which are the three classical arguments and also the context dictionary. You can add parameters to the method. They must correspond to other fields defined in the view, and must also be defined in the XML with fields defined this way:: +This method takes at least arguments: cr, uid, ids, which are the +three classical arguments and also the context dictionary. You can add +parameters to the method. They must correspond to other fields defined +in the view, and must also be defined in the XML with fields defined +this way:: <field name="name_of_field" on_change="name_of_method(other_field'_1_', ..., other_field'_n_')"/> The example below is from the sale order view. -You can use the 'context' keyword to access data in the context that can be used as params of the function.:: +You can use the 'context' keyword to access data in the context that +can be used as params of the function.:: <field name="shop_id" on_change="onchange_shop_id(shop_id)"/> @@ -100,7 +106,10 @@ You can use the 'context' keyword to access data in the context that can be used return {'value':v} -When editing the shop_id form field, the onchange_shop_id method of the sale_order object is called and returns a dictionary where the 'value' key contains a dictionary of the new value to use in the 'project_id', 'pricelist_id' and 'payment_default_id' fields. +When editing the shop_id form field, the onchange_shop_id method of +the sale_order object is called and returns a dictionary where the +'value' key contains a dictionary of the new value to use in the +'project_id', 'pricelist_id' and 'payment_default_id' fields. Note that it is possible to change more than just the values of fields. For example, it is possible to change the value of some fields diff --git a/doc/api_models.rst b/doc/api_models.rst index 143147c0f48..82f45ed5c9c 100644 --- a/doc/api_models.rst +++ b/doc/api_models.rst @@ -1,7 +1,21 @@ -ORM and models --------------- +ORM and Models +============== .. automodule:: openerp.osv.orm :members: :undoc-members: + +Scope Management +================ + +.. automodule:: openerp.osv.scope + :members: + :undoc-members: + +API Decorators +============== + +.. automodule:: openerp.osv.api + :members: + :undoc-members: diff --git a/doc/howto/howto_website.rst b/doc/howto/howto_website.rst index e4ef9b4748b..722891519da 100644 --- a/doc/howto/howto_website.rst +++ b/doc/howto/howto_website.rst @@ -65,7 +65,7 @@ module in it: .. code-block:: console $ createdb academy - $ ./openerp-server --addons-path=../web/addons,../addons,../my-modules \ + $ ./openerp-server --addons-path=addons,../my-modules \ -d academy -i academy --db-filter=academy * ``--addons-path`` tells OpenERP where it can find its modules. By default it @@ -159,6 +159,10 @@ Let's move our 2 pseudo-templates from inline strings to actual templates: This simplifies the controller code by moving data formatting out of it, and generally makes it simpler for designers to edit the markup. +.. note:: + + You'll need to update the module to install the new templates + .. todo:: link to section about reusing/altering existing stuff, template overriding @@ -175,7 +179,7 @@ First, we'll install the ``website`` module: restart your server with .. code-block:: console - $ ./openerp-server --addons-path=../web/addons,../addons,../my-modules \ + $ ./openerp-server --addons-path=addons,../my-modules \ -d academy -i website --db-filter=academy If you navigate to `your openerp`_, your basic page may have been replaced by @@ -202,7 +206,7 @@ ensures ``academy``'s index page overwrites ``website``'s. .. code-block:: console - $ ./openerp-server --addons-path=../web/addons,../addons,../my-modules \ + $ ./openerp-server --addons-path=addons,../my-modules \ -d academy -u academy --db-filter=academy instead of the previous command (note: ``-i`` was replaced by ``-u``) @@ -460,14 +464,14 @@ of all records in the object) and the "form" view (view an manipulation of a single record). The :guilabel:`Create` button above the list lets you create new record, you can select records to delete them. -There's one big issue to fix right now, the labeling of the column in the list -and the fields in the form view, which are all currently :guilabel:`unknown`. -We can fix that by adding a ``string`` attribute to the model field: +The names of the fields in the search and list view are automatically inferred +from the logical field names, but it's probably a good idea to specify them +anyway, by adding a ``string`` to the model field: .. patch:: -The second problem is that the list view only displays the ``name`` field. To -fix this, we have to create an explicit list view for lectures: +An issue is that the list view only displays the ``name`` field. To fix this, +we have to create an explicit list view for lectures: .. patch:: @@ -491,7 +495,7 @@ the server as: .. code-block:: console - $ ./openerp-server --addons-path=../web/addons,../addons,../my-modules \ + $ ./openerp-server --addons-path=addons,../my-modules \ -d academy -i website_event --db-filter=academy We'll also add it as a dependency to our module: @@ -517,7 +521,7 @@ Restart the server with .. code-block:: console - $ ./openerp-server --addons-path=../web/addons,../addons,../my-modules \ + $ ./openerp-server --addons-path=addons,../my-modules \ -d academy -i academy --db-filter=academy and the menu item has been renamed to Lectures. @@ -573,6 +577,12 @@ The gist of the operation is fairly simple, but there are lots of changes: purged if we do not need it (e.g. existing non-lectures events and event types can be removed before adding our own) +.. note:: + + because we're reusing the old XIDs on completely different models, we need + to either remove the old reference or (simpler) just drop and re-create + the database + .. patch:: Our data is back in the fontend (site), and in the backend we get diff --git a/doc/howto/howto_website/basic-page b/doc/howto/howto_website/basic-page index d3179145542..ccb47652f39 100644 --- a/doc/howto/howto_website/basic-page +++ b/doc/howto/howto_website/basic-page @@ -1,5 +1,5 @@ # HG changeset patch -# Parent b96cd22d25cfa9a67f451d091f5c4896997d350d +# Parent 11a30af5c0c80b15a2bbad562ef3a580ee99fb3b diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py @@ -10,7 +10,7 @@ diff --git a/controllers/academy.py b/controllers/academy.py def index(self): - return "Hello, world!" + return """<!doctype html> -+<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> ++<link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> +<body class="container"> + Hello, world! +</body> diff --git a/doc/howto/howto_website/field-label b/doc/howto/howto_website/field-label index 2589e8f872a..090344dc719 100644 --- a/doc/howto/howto_website/field-label +++ b/doc/howto/howto_website/field-label @@ -1,14 +1,14 @@ # HG changeset patch -# Parent fe4edbcd9e98db81ec6321c58e8ac508a686f45b -diff -r fe4edbcd9e98 -r 72a099819e5b models/academy.py ---- a/models/academy.py Mon Apr 14 16:38:10 2014 +0200 -+++ b/models/academy.py Mon Apr 14 16:59:01 2014 +0200 -@@ -14,6 +14,6 @@ class Lectures(orm.Model): +# Parent 4b38aba926d27af5f81be1a3b5a482c26522bf38 + +diff --git a/models/academy.py b/models/academy.py +--- a/models/academy.py ++++ b/models/academy.py +@@ -12,5 +12,5 @@ class Lectures(Model): + _name = 'academy.lectures' _order = 'date ASC' - _columns = { -- 'name': fields.char(required=True), -- 'date': fields.date(required=True), -+ 'name': fields.char(required=True, string="Name"), -+ 'date': fields.date(required=True, string="Date"), - } +- name = Char(required=True) +- date = Date(required=True) ++ name = Char(required=True, string="Name") ++ date = Date(required=True, string="Date") diff --git a/doc/howto/howto_website/lectures-model-add b/doc/howto/howto_website/lectures-model-add index e622ec6656f..3211995ab72 100644 --- a/doc/howto/howto_website/lectures-model-add +++ b/doc/howto/howto_website/lectures-model-add @@ -1,5 +1,5 @@ # HG changeset patch -# Parent cd98e5752eedca2780da80387ac01c8cd166940f +# Parent 13c65b2eed8f84b951ff5a98051f64fe35ddcf0a diff --git a/__openerp__.py b/__openerp__.py --- a/__openerp__.py @@ -15,22 +15,17 @@ diff --git a/__openerp__.py b/__openerp__.py diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py +++ b/controllers/academy.py -@@ -6,10 +6,15 @@ from openerp.addons.web.controllers impo +@@ -6,8 +6,10 @@ from openerp.addons.web.controllers impo class academy(main.Home): @http.route('/', auth='public', website=True) def index(self): -+ cr, uid, context = http.request.cr, http.request.uid, http.request.context -+ Lectures = http.request.registry['academy.lectures'] - tas = http.request.registry['academy.tas'].search_read( - http.request.cr, http.request.uid, context=http.request.context) -+ lectures = Lectures.browse( -+ cr, uid, Lectures.search(cr, uid, [], context=context), context=context) - return http.request.website.render('academy.index', { - 'tas': tas, ++ lectures = http.request.env['academy.lectures'].search([]) + tas = http.request.env['academy.tas'].search([]) + return http.request.render('academy.index', { + 'lectures': lectures, + 'tas': tas, }) - @http.route('/tas/<model("academy.tas"):ta>/', auth='public', website=True) diff --git a/data/lectures.xml b/data/lectures.xml new file mode 100644 --- /dev/null @@ -63,19 +58,24 @@ new file mode 100644 diff --git a/models/academy.py b/models/academy.py --- a/models/academy.py +++ b/models/academy.py -@@ -8,3 +8,12 @@ class TeachingAssistants(orm.Model): - 'name': fields.char(), - 'biography': fields.html(), - } +@@ -1,9 +1,16 @@ + # -*- coding: utf-8 -*- + from openerp.models import Model +-from openerp.fields import Char, Html ++from openerp.fields import Char, Html, Date + + class TeachingAssistants(Model): + _name = "academy.tas" + + name = Char() + biography = Html() + -+class Lectures(orm.Model): ++class Lectures(Model): + _name = 'academy.lectures' + _order = 'date ASC' + -+ _columns = { -+ 'name': fields.char(required=True), -+ 'date': fields.date(required=True), -+ } ++ name = Char(required=True) ++ date = Date(required=True) diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv diff --git a/doc/howto/howto_website/manifest b/doc/howto/howto_website/manifest index 601c18c5106..c0c7ee29547 100644 --- a/doc/howto/howto_website/manifest +++ b/doc/howto/howto_website/manifest @@ -71,16 +71,15 @@ diff --git a/models/academy.py b/models/academy.py new file mode 100644 --- /dev/null +++ b/models/academy.py -@@ -0,0 +1,9 @@ +@@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- -+from openerp.osv import orm, fields ++from openerp.models import Model ++from openerp.fields import Char + -+class academy(orm.Model): ++class academy(Model): + _name = "academy.academy" + -+ _columns = { -+ 'name': fields.char(), -+ } ++ name = Char() diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv new file mode 100644 --- /dev/null diff --git a/doc/howto/howto_website/move-to-openerp-objects b/doc/howto/howto_website/move-to-openerp-objects index 8623d8a90e5..0efebb39846 100644 --- a/doc/howto/howto_website/move-to-openerp-objects +++ b/doc/howto/howto_website/move-to-openerp-objects @@ -1,5 +1,5 @@ # HG changeset patch -# Parent ade038cd6dfd855f1d423cffb3d4e242404c28f0 +# Parent bc8914ae6b552520bdc3856e81d3624dc5a77a99 diff --git a/__init__.py b/__init__.py --- a/__init__.py @@ -26,40 +26,31 @@ diff --git a/__openerp__.py b/__openerp__.py diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py +++ b/controllers/academy.py -@@ -6,18 +6,29 @@ from openerp.addons.web.controllers impo +@@ -6,14 +6,22 @@ from openerp.addons.web.controllers impo class academy(main.Home): @http.route('/', auth='public', website=True) def index(self): -+ registry = http.request.registry - cr, uid, context = http.request.cr, http.request.uid, http.request.context -- Lectures = http.request.registry['academy.lectures'] -- tas = http.request.registry['academy.tas'].search_read( -- http.request.cr, http.request.uid, context=http.request.context) +- lectures = http.request.env['academy.lectures'].search([]) +- tas = http.request.env['academy.tas'].search([]) ++ ta_group = http.request.env.ref('academy.tas') ++ tas = http.request.env['res.users'].search( ++ [('groups_id', '=', [ta_group.id])] ++ ) + -+ Data = registry['ir.model.data'] -+ _, ta_group_id = Data.get_object_reference(cr, uid, 'academy', 'tas') -+ tas = registry['res.users'].search_read( -+ http.request.cr, http.request.uid, -+ [('groups_id', '=', [ta_group_id])], -+ context=http.request.context) ++ lecture_type = http.request.env.ref('academy.lecture_type') ++ lectures = http.request.env['event.event'].search( ++ [('type', '=', lecture_type.id)] ++ ) + -+ Lectures = registry['event.event'] -+ _, lecture_type_id = Data.get_object_reference(cr, uid, 'academy', 'lecture_type') - lectures = Lectures.browse( -- cr, uid, Lectures.search(cr, uid, [], context=context), context=context) -+ cr, uid, -+ Lectures.search(cr, uid, [('type', '=', lecture_type_id),], context=context), -+ context=context) -+ - return http.request.website.render('academy.index', { - 'tas': tas, + return http.request.render('academy.index', { 'lectures': lectures, + 'tas': tas, }) - @http.route('/tas/<model("academy.tas"):ta>/', auth='public', website=True) + @http.route('/tas/<model("res.users"):ta>/', auth='public', website=True) def ta(self, ta): - return http.request.website.render('academy.ta', { + return http.request.render('academy.ta', { 'ta': ta, diff --git a/data/views.xml b/data/views.xml deleted file mode 100644 @@ -227,39 +218,36 @@ diff --git a/models/academy.py b/models/academy.py deleted file mode 100644 --- a/models/academy.py +++ /dev/null -@@ -1,19 +0,0 @@ +@@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- --from openerp.osv import orm, fields +-from openerp.models import Model +-from openerp.fields import Char, Html, Date - --class TeachingAssistants(orm.Model): +-class TeachingAssistants(Model): - _name = "academy.tas" - -- _columns = { -- 'name': fields.char(), -- 'biography': fields.html(), -- } +- name = Char() +- biography = Html() - --class Lectures(orm.Model): +-class Lectures(Model): - _name = 'academy.lectures' - _order = 'date ASC' - -- _columns = { -- 'name': fields.char(required=True, string="Name"), -- 'date': fields.date(required=True, string="Date"), -- } +- name = Char(required=True, string="Name") +- date = Date(required=True, string="Date") diff --git a/models/res_partner.py b/models/res_partner.py new file mode 100644 --- /dev/null +++ b/models/res_partner.py @@ -0,0 +1,8 @@ -+from openerp.osv import orm, fields ++from openerp.models import Model ++from openerp.fields import Html + -+class Partner(orm.Model): ++class Partner(Model): + _inherit = 'res.partner' + -+ _columns = { -+ 'biography': fields.html(), -+ } ++ biography = Html() ++ diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv deleted file mode 100644 --- a/security/ir.model.access.csv diff --git a/doc/howto/howto_website/ta-controller b/doc/howto/howto_website/ta-controller index 64de1dae17b..da4ee7606c9 100644 --- a/doc/howto/howto_website/ta-controller +++ b/doc/howto/howto_website/ta-controller @@ -1,5 +1,5 @@ # HG changeset patch -# Parent a110c540b0769ee849a404324cf8594d116cc982 +# Parent a813df5b9cbdf5db9b0c3f6bac47b1821ddbb086 diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py @@ -25,7 +25,7 @@ diff --git a/controllers/academy.py b/controllers/academy.py + ] + return """<!doctype html> - <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> + <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> <body class="container"> - Hello, world! + <h1>Introduction to something</h1> @@ -45,7 +45,7 @@ diff --git a/controllers/academy.py b/controllers/academy.py +<html> + <head> + <title>AcademyAcademy TA %(name)s</title> -+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> ++ <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> + </head> + <body class="container"> + <h1>%(name)s</h1> diff --git a/doc/howto/howto_website/ta-data b/doc/howto/howto_website/ta-data index 395b5a2b430..2c001de47ac 100644 --- a/doc/howto/howto_website/ta-data +++ b/doc/howto/howto_website/ta-data @@ -1,5 +1,5 @@ # HG changeset patch -# Parent a35b5f4903087b1b31a4ecf33bfe655dc3ad5663 +# Parent 650d20edf05a23b977c3b9fa476a39986eee4722 diff --git a/__openerp__.py b/__openerp__.py --- a/__openerp__.py diff --git a/doc/howto/howto_website/ta-html-biography b/doc/howto/howto_website/ta-html-biography index a8460c3090a..c0fae24aa41 100644 --- a/doc/howto/howto_website/ta-html-biography +++ b/doc/howto/howto_website/ta-html-biography @@ -1,12 +1,17 @@ # HG changeset patch -# Parent 313d7c760558b24461a544063de061d00fdf7059 +# Parent d57af6d92026e45b336308b143a5c227d44de9f7 diff --git a/models/academy.py b/models/academy.py --- a/models/academy.py +++ b/models/academy.py -@@ -6,4 +6,5 @@ class TeachingAssistants(orm.Model): +@@ -1,8 +1,9 @@ + # -*- coding: utf-8 -*- + from openerp.models import Model +-from openerp.fields import Char ++from openerp.fields import Char, Html - _columns = { - 'name': fields.char(), -+ 'biography': fields.html(), - } + class TeachingAssistants(Model): + _name = "academy.tas" + + name = Char() ++ biography = Html() diff --git a/doc/howto/howto_website/ta-model b/doc/howto/howto_website/ta-model index d3b79299e9c..277ceea3cf9 100644 --- a/doc/howto/howto_website/ta-model +++ b/doc/howto/howto_website/ta-model @@ -1,10 +1,10 @@ # HG changeset patch -# Parent e8b98f4c8f9070f7d5b91936381324cd1fe12e17 +# Parent 3fbc9c92bcee395900c441aeb80e68036004a7a0 diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py +++ b/controllers/academy.py -@@ -3,19 +3,13 @@ +@@ -3,19 +3,12 @@ from openerp import http from openerp.addons.web.controllers import main @@ -19,9 +19,8 @@ diff --git a/controllers/academy.py b/controllers/academy.py class academy(main.Home): @http.route('/', auth='public', website=True) def index(self): -+ tas = http.request.registry['academy.tas'].search_read( -+ http.request.cr, http.request.uid, context=http.request.context) - return http.request.website.render('academy.index', { ++ tas = http.request.env['academy.tas'].search([]) + return http.request.render('academy.index', { - 'tas': teaching_assistants, + 'tas': tas, }) @@ -30,17 +29,16 @@ diff --git a/controllers/academy.py b/controllers/academy.py diff --git a/models/academy.py b/models/academy.py --- a/models/academy.py +++ b/models/academy.py -@@ -1,8 +1,8 @@ - # -*- coding: utf-8 -*- - from openerp.osv import orm, fields +@@ -2,7 +2,7 @@ + from openerp.models import Model + from openerp.fields import Char --class academy(orm.Model): +-class academy(Model): - _name = "academy.academy" -+class TeachingAssistants(orm.Model): ++class TeachingAssistants(Model): + _name = "academy.tas" - _columns = { - 'name': fields.char(), + name = Char() diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -48,3 +46,15 @@ diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_academy_academy,access_academy_academy,model_academy_academy,,1,0,0,0 +access_academy_tas,access_academy_tas,model_academy_tas,,1,0,0,0 +diff --git a/views/templates.xml b/views/templates.xml +--- a/views/templates.xml ++++ b/views/templates.xml +@@ -17,7 +17,7 @@ + <h2>Teaching Assistants</h2> + <ul> + <li t-foreach="tas" t-as="ta"> +- <a t-att-href="url_for('/tas/%d/' % ta_index)"> ++ <a t-att-href="url_for('/tas/%d/' % ta['id'])"> + <t t-esc="ta['name']"/> + </a> + </li> diff --git a/doc/howto/howto_website/ta-t-field b/doc/howto/howto_website/ta-t-field index a61bec85a6b..8d6ffe06d90 100644 --- a/doc/howto/howto_website/ta-t-field +++ b/doc/howto/howto_website/ta-t-field @@ -1,9 +1,18 @@ # HG changeset patch -# Parent 9d054be011cf2d3019e3b4d1be7cc95375044a05 +# Parent a1788b0db87f7fdb5640b17bbda6e9a0c6093c37 diff --git a/views/templates.xml b/views/templates.xml --- a/views/templates.xml +++ b/views/templates.xml +@@ -18,7 +18,7 @@ + <ul> + <li t-foreach="tas" t-as="ta"> + <a t-att-href="url_for('/tas/%d/' % ta['id'])"> +- <t t-esc="ta['name']"/> ++ <span t-field="ta.name"/> + </a> + </li> + </ul> @@ -35,7 +35,7 @@ <div class="oe_structure"/> <div class="oe_structure"> diff --git a/doc/howto/howto_website/ta-view-fix b/doc/howto/howto_website/ta-view-fix index 5e3f494cf3d..c04c5dc1349 100644 --- a/doc/howto/howto_website/ta-view-fix +++ b/doc/howto/howto_website/ta-view-fix @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 466d19929560c2a60c347990ea44730ae40ec36d +# Parent 0d88c003a54e6501eee5f43b90db20d9b78c07c8 diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py @@ -10,24 +10,15 @@ diff --git a/controllers/academy.py b/controllers/academy.py - @http.route('/tas/<int:id>/', auth='public', website=True) - def ta(self, id): -- return http.request.website.render('academy.ta', teaching_assistants[id]) +- return http.request.render('academy.ta', teaching_assistants[id]) + @http.route('/tas/<model("academy.tas"):ta>/', auth='public', website=True) + def ta(self, ta): -+ return http.request.website.render('academy.ta', { ++ return http.request.render('academy.ta', { + 'ta': ta, + }) diff --git a/views/templates.xml b/views/templates.xml --- a/views/templates.xml +++ b/views/templates.xml -@@ -17,7 +17,7 @@ - <h2>Teaching Assistants</h2> - <ul> - <li t-foreach="tas" t-as="ta"> -- <a t-att-href="url_for('/tas/%d/' % ta_index)"> -+ <a t-att-href="url_for('/tas/%s/' % ta['id'])"> - <t t-esc="ta['name']"/> - </a> - </li> @@ -35,7 +35,7 @@ <div class="oe_structure"/> <div class="oe_structure"> diff --git a/doc/howto/howto_website/templates-basic b/doc/howto/howto_website/templates-basic index a5b14a3fbc1..95d7614b496 100644 --- a/doc/howto/howto_website/templates-basic +++ b/doc/howto/howto_website/templates-basic @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 2edbac8244a982055a6786c14ee41719ea5410e8 +# Parent 9979cfa9319edcd15e6c243862eeeb03b851a82a diff --git a/__openerp__.py b/__openerp__.py --- a/__openerp__.py @@ -19,18 +19,13 @@ diff --git a/__openerp__.py b/__openerp__.py diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py +++ b/controllers/academy.py -@@ -14,34 +14,17 @@ teaching_assistants = [ - class academy(main.Home): - @http.route('/', auth='none') - def index(self): -+ cr, uid, context = http.request.cr, http.request.uid, http.request.context - tas = [ +@@ -18,30 +18,10 @@ class academy(main.Home): '<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name']) for i, ta in enumerate(teaching_assistants) ] - +- - return """<!doctype html> --<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> +-<link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> -<body class="container"> - <h1>Introduction to something</h1> - <h2>Teaching Assistants</h2> @@ -41,26 +36,24 @@ diff --git a/controllers/academy.py b/controllers/academy.py -""" % { - 'tas': '\n'.join(tas) - } -- -+ return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', { ++ return http.request.render('academy.index', { + 'tas': '\n'.join(tas) -+ }, context=context) ++ }) + @http.route('/tas/<int:id>/', auth='none') def ta(self, id): - return """<!doctype html> -<html> - <head> - <title>AcademyAcademy TA %(name)s</title> -- <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> +- <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"> - </head> - <body class="container"> - <h1>%(name)s</h1> - </body> -</html> -""" % teaching_assistants[id] -+ cr, uid, context = http.request.cr, http.request.uid, http.request.context -+ return http.request.registry['ir.ui.view'].render( -+ cr, uid, 'academy.ta', teaching_assistants[id], context=context) ++ return http.request.render('academy.ta', teaching_assistants[id]) diff --git a/views/templates.xml b/views/templates.xml new file mode 100644 --- /dev/null @@ -72,7 +65,7 @@ new file mode 100644 + <html> + <head> + <title>AcademyAcademy</title> -+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/> ++ <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"/> + </head> + <body class="container"> + <h1>Introduction to a thing</h1> @@ -95,7 +88,7 @@ new file mode 100644 + <html> + <head> + <title>AcademyAcademy TA <t t-esc="name"/></title> -+ <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/> ++ <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"/> + </head> + <body class="container"> + <h1><t t-esc="name"/></h1> diff --git a/doc/howto/howto_website/website-dependency b/doc/howto/howto_website/website-dependency index 37c14e8f2c2..e1a038233ca 100644 --- a/doc/howto/howto_website/website-dependency +++ b/doc/howto/howto_website/website-dependency @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 0fdf3e29ce5bb1dd39479f157eeac5bdfd3cffb0 +# Parent 9d2ca56532b5bbb5d6c9de995088d895fbefff2e diff --git a/__openerp__.py b/__openerp__.py --- a/__openerp__.py @@ -16,32 +16,20 @@ diff --git a/__openerp__.py b/__openerp__.py diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py +++ b/controllers/academy.py -@@ -12,19 +12,12 @@ teaching_assistants = [ - ] - +@@ -14,12 +14,8 @@ teaching_assistants = [ class academy(main.Home): -- @http.route('/', auth='none') -+ @http.route('/', auth='none', website=True) + @http.route('/', auth='none') def index(self): -- cr, uid, context = http.request.cr, http.request.uid, http.request.context - tas = [ - '<li><a href="/tas/%d/">%s</a></li>' % (i, ta['name']) - for i, ta in enumerate(teaching_assistants) - ] -+ return http.request.website.render('academy.index', { + return http.request.render('academy.index', { +- 'tas': '\n'.join(tas) + 'tas': teaching_assistants, -+ }) + }) -- return http.request.registry['ir.ui.view'].render(cr, uid, 'academy.index', { -- 'tas': '\n'.join(tas) -- }, context=context) -- @http.route('/tas/<int:id>/', auth='none') -+ @http.route('/tas/<int:id>/', auth='none', website=True) - def ta(self, id): -- cr, uid, context = http.request.cr, http.request.uid, http.request.context -- return http.request.registry['ir.ui.view'].render( -- cr, uid, 'academy.ta', teaching_assistants[id], context=context) -+ return http.request.website.render('academy.ta', teaching_assistants[id]) + @http.route('/tas/<int:id>/', auth='none') diff --git a/views/templates.xml b/views/templates.xml --- a/views/templates.xml +++ b/views/templates.xml diff --git a/doc/howto/howto_website/website-layoutify b/doc/howto/howto_website/website-layoutify index d4ed9647dd5..a2ae505673c 100644 --- a/doc/howto/howto_website/website-layoutify +++ b/doc/howto/howto_website/website-layoutify @@ -1,5 +1,5 @@ # HG changeset patch -# Parent 69c500d7634c0e5287508cfaffa14174cc47d800 +# Parent 22cbd107041dde59f904e94ea8c740fca5965fc0 diff --git a/controllers/academy.py b/controllers/academy.py --- a/controllers/academy.py @@ -8,17 +8,17 @@ diff --git a/controllers/academy.py b/controllers/academy.py ] class academy(main.Home): -- @http.route('/', auth='none', website=True) +- @http.route('/', auth='none') + @http.route('/', auth='public', website=True) def index(self): - return http.request.website.render('academy.index', { + return http.request.render('academy.index', { 'tas': teaching_assistants, }) -- @http.route('/tas/<int:id>/', auth='none', website=True) +- @http.route('/tas/<int:id>/', auth='none') + @http.route('/tas/<int:id>/', auth='public', website=True) def ta(self, id): - return http.request.website.render('academy.ta', teaching_assistants[id]) + return http.request.render('academy.ta', teaching_assistants[id]) diff --git a/views/templates.xml b/views/templates.xml --- a/views/templates.xml +++ b/views/templates.xml @@ -29,7 +29,7 @@ diff --git a/views/templates.xml b/views/templates.xml - <html> - <head> - <title>AcademyAcademy</title> -- <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/> +- <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"/> - </head> - <body class="container"> - <h1>Introduction to a thing</h1> @@ -83,7 +83,7 @@ diff --git a/views/templates.xml b/views/templates.xml - <html> - <head> - <title>AcademyAcademy TA <t t-esc="name"/></title> -- <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/> +- <link href="/web/static/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet"/> - </head> - <body class="container"> - <h1><t t-esc="name"/></h1> diff --git a/doc/index.rst b/doc/index.rst index ad42e41a10f..f7cd7c399f1 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -36,9 +36,10 @@ OpenERP Server API .. toctree:: :maxdepth: 1 - orm-methods.rst - api_models.rst - routing.rst + new_api + orm-methods + api_models + routing Changelog ''''''''' diff --git a/doc/new_api.rst b/doc/new_api.rst new file mode 100644 index 00000000000..e99d5b7eef4 --- /dev/null +++ b/doc/new_api.rst @@ -0,0 +1,138 @@ +================== +High-level ORM API +================== + +.. _compute: + +Computed fields: defaults and function fields +============================================= + +The high-level API attempts to unify concepts of programmatic value generation +for function fields (stored or not) and default values through the use of +computed fields. + +Fields are marked as computed by setting their ``compute`` attribute to the +name of the method used to compute then:: + + has_sibling = fields.Integer(compute='compute_has_sibling') + +by default computation methods behave as simple defaults in case no +corresponding value is found in the database:: + + def default_number_of_employees(self): + self.number_of_employees = 1 + +.. todo:: + + literal defaults:: + + has_sibling = fields.Integer(compute=fields.default(1)) + +but they can also be used for computed fields by specifying fields used for +the computation. The dependencies can be dotted for "cascading" through +related models:: + + @api.depends('parent_id.children_count') + def compute_has_sibling(self): + self.has_sibling = self.parent_id.children_count >= 2 + +.. todo:: + + function-based:: + + has_sibling = fields.Integer() + @has_sibling.computer + @api.depends('parent_id.children_count') + def compute_has_sibling(self): + self.has_sibling = self.parent_id.children_count >= 2 + +note that computation methods (defaults or others) do not *return* a value, +they *set* values the current object. This means the high-level API does not +need :ref:`an explicit multi <fields-functional>`: a ``multi`` method is +simply one which computes several values at once:: + + @api.depends('company_id') + def compute_relations(self): + self.computed_company = self.company_id + self.computed_companies = self.company_id.to_recordset() + +Automatic onchange +================== + +Using to the improved and expanded :ref:`computed fields <compute>`, the +high-level ORM API is able to infer the effect of fields on +one another, and thus automatically provide a basic form of onchange without +having to implement it by hand, or implement dozens of onchange functions to +get everything right. + + + + +.. todo:: + + deferred records:: + + partner = Partner.record(42, defer=True) + partner.name = "foo" + partner.user_id = juan + partner.save() # only saved to db here + + with scope.defer(): + # all records in this scope or children scopes are deferred + # until corresponding scope poped or until *this* scope poped? + partner = Partner.record(42) + partner.name = "foo" + partner.user_id = juan + # saved here, also for recordset &al, ~transaction + + # temp deferment, maybe simpler? Or for bulk operations?: + with Partner.record(42) as partner: + partner.name = "foo" + partner.user_id = juan + + ``id = False`` => always defered? null v draft? + +.. todo:: keyword arguments passed positionally (common for context, completely breaks everything) + +.. todo:: optional arguments (report_aged_receivable) + +.. todo:: non-id ids? (mail thread_id) + +.. todo:: partial signatures on overrides (e.g. message_post) + +.. todo:: + + :: + + field = fields.Char() + + @field.computer + def foo(self): + "compute foo here" + + ~ + + :: + + field = fields.Char(compute='foo') + + def foo(self): + "compute foo here" + +.. todo:: doc + +.. todo:: incorrect dependency spec? + +.. todo:: dynamic dependencies? + + :: + + @api.depends(???) + def foo(self) + self.a = self[self.b] + +.. todo:: recursive onchange + + Country & state. Change country -> remove state; set state -> set country + +.. todo:: onchange list affected? |
