From 652c0167a3254bad4a04a801b2998fe4752b37e2 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 14 Oct 2020 08:21:13 +0200 Subject: [PATCH] [IMP] base_jsonify: Allow to export many2one and referene field as simple field Before this change, the result of the export of a relational field was always a dict or a list of dict. ex: publication_language_id/name publication_language_id/name:lang will output: { ... "publication_language_id" : { "lang": "French" } ... } After this change it's now possible to define simple exporter for relational fields where the value into the result will be the display_name or a list of display_name of the related records. ex: publication_language_id publication_language_id:lang will output: { "lang": "French" } Please enter the commit message for your changes. Lines starting --- base_jsonify/models/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/base_jsonify/models/models.py b/base_jsonify/models/models.py index b75461100..5e11a568f 100644 --- a/base_jsonify/models/models.py +++ b/base_jsonify/models/models.py @@ -87,6 +87,13 @@ class Base(models.AbstractModel): # object value = fields.Datetime.context_timestamp(self, value) value = value.isoformat() + elif field_type in ("many2one", "reference"): + if not value: + value = None + else: + value = value.display_name + elif field_type in ("one2many", "many2many"): + value = [v.display_name for v in value] return value def _jsonify_value_subparser(self, field_name, subparser):