# HG changeset patch # User Brendan Masson <brendan.masson@xcg-consulting.fr> # Date 1457453832 -3600 # Tue Mar 08 17:17:12 2016 +0100 # Branch odoo8 # Node ID cb35b42ea32d7ef27c56a8f79841165bf1497173 # Parent 60e96f419da8b2f238a3e81731c1bbb319a508d1 Change type of analytic.structure field to Selection diff --git a/analytic_structure.py b/analytic_structure.py --- a/analytic_structure.py +++ b/analytic_structure.py @@ -60,11 +60,36 @@ u"structure is common to all companies." ) - model_name = fields.Char( + def _get_model_name(self): + """Looks up the list of model names""" + registry = self.env.registry + models = [ + model + for name, model in registry.items() + if getattr(model, '_analytic', False) + ] + model_names = set() + for model in models: + analytic = model._analytic + if analytic is True: + model_names.add(model._name.replace('.', '_')) + elif isinstance(analytic, basestring): + model_names.add(analytic) + else: + # Expecting analytic to be a dict + model_names.update(analytic.values()) + + res = [(model_name, model_name) for model_name in model_names] + + from pprint import pprint + pprint(res) + + return res + + model_name = fields.Selection( + _get_model_name, u"Object", - size=128, required=True, - select='1', ) nd_id = fields.Many2one( 'analytic.dimension', @@ -92,6 +117,12 @@ ), ] + def name_get(self): + names = [ + (record.id, record.model_name) for record in self + ] + return names + def format_field_name(self, ordering, prefix='a', suffix='id'): """Return an analytic field's name from its slot, prefix and suffix. """ diff --git a/analytic_views.xml b/analytic_views.xml --- a/analytic_views.xml +++ b/analytic_views.xml @@ -121,11 +121,13 @@ <field name="model">analytic.structure</field> <field name="arch" type="xml"> <form string="Analytic Structure" version="7.0"> + <h1> + <field name="display_name" class="oe_inline,oe_read_only" + style="width: 6em" /> + </h1> <label for="model_name" class="oe_edit_only" string="Target Model Name" /> - <h1> - <field name="model_name" class="oe_inline" - placeholder="Target Model Name" style="width: 6em" /> - </h1> + <field name="model_name" class="oe_edit_only" + placeholder="Target Model Name" /> <group colspan="4" col="4"> <field name="nd_id" /> <newline />