From c36fc4a43512dda18b3f748de2ddbe6a0d3085f6 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 27 Aug 2018 10:58:40 +0200 Subject: [FIX] doc: API of create --- doc/reference/orm.rst | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'doc/reference') diff --git a/doc/reference/orm.rst b/doc/reference/orm.rst index 1a0dba9edf1..a7febdc7c7b 100644 --- a/doc/reference/orm.rst +++ b/doc/reference/orm.rst @@ -278,12 +278,18 @@ Common ORM methods .. tip:: to just check if any record matches a domain, or count the number of records which do, use :meth:`~odoo.models.Model.search_count` + :meth:`~odoo.models.Model.create` - Takes a number of field values, and returns a recordset containing the - record created:: + Takes a dictionary of field values, or a list of such dictionaries, and + returns a recordset containing the records created:: - >>> self.create({'name': "New Name"}) + >>> self.create({'name': "Joe"}) res.partner(78) + >>> self.create([{'name': "Jack"}, {'name': "William"}, {'name': "Averell"}]) + res.partner(79, 80, 81) + + See :ref:`how to define method `create` with one API or the other + `. :meth:`~odoo.models.Model.write` Takes a number of field values, writes them to all the records in its @@ -569,6 +575,19 @@ Two decorators can expose a new-style method to the old API: # can be called as old_style_model.some_method(cr, uid, [id1, id2], a_value, context=context) +Note that a method `create` decorated with :func:`~odoo.api.model` will always +be called with a single dictionary. A method `create` decorated with the variant +:func:`~odoo.api.model_create_multi` will always be called with a list of dicts. +The decorators take care of converting the argument to one form or the other:: + + @api.model + def create(self, vals): + ... + + @api.model_create_multi + def create(self, vals_list): + ... + Because new-style APIs tend to return recordsets and old-style APIs tend to return lists of ids, there is also a decorator managing this: -- cgit v1.2.3 From 0e307f8280eda4343a63c7faa2d52e33d46c9c0c Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 27 Aug 2018 12:55:21 +0200 Subject: [FIX] doc building and warnings doc: * fix incorrect doc comments (documenting params which don't exist) * correctly quote non-refs * fix role label syntax (backticks must be escaped) * add newline to fix warning JS doc parser: * fix handling of already-resolved objects * fix handling of non-string properties (e.g. foo[0] at module toplevel) * don't blow up if subject of .include call can't be resolved (just ignore) Others: * add translator support for ``problematic`` node (apparently used for some refs by recent Sphinx) --- doc/reference/orm.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/reference') diff --git a/doc/reference/orm.rst b/doc/reference/orm.rst index a7febdc7c7b..14dfdb4c058 100644 --- a/doc/reference/orm.rst +++ b/doc/reference/orm.rst @@ -288,7 +288,7 @@ Common ORM methods >>> self.create([{'name': "Jack"}, {'name': "William"}, {'name': "Averell"}]) res.partner(79, 80, 81) - See :ref:`how to define method `create` with one API or the other + See :ref:`how to define method \`create\` with one API or the other `. :meth:`~odoo.models.Model.write` -- cgit v1.2.3