Skip to content
Snippets Groups Projects
Commit cb35b42ea32d authored by Brendan Masson's avatar Brendan Masson
Browse files

Change type of analytic.structure field to Selection

parent 60e96f419da8
No related branches found
No related tags found
No related merge requests found
...@@ -60,5 +60,32 @@ ...@@ -60,5 +60,32 @@
u"structure is common to all companies." 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", u"Object",
...@@ -64,3 +91,2 @@ ...@@ -64,3 +91,2 @@
u"Object", u"Object",
size=128,
required=True, required=True,
...@@ -66,5 +92,4 @@ ...@@ -66,5 +92,4 @@
required=True, required=True,
select='1',
) )
nd_id = fields.Many2one( nd_id = fields.Many2one(
'analytic.dimension', 'analytic.dimension',
...@@ -92,6 +117,12 @@ ...@@ -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'): def format_field_name(self, ordering, prefix='a', suffix='id'):
"""Return an analytic field's name from its slot, prefix and suffix. """Return an analytic field's name from its slot, prefix and suffix.
""" """
......
...@@ -121,4 +121,8 @@ ...@@ -121,4 +121,8 @@
<field name="model">analytic.structure</field> <field name="model">analytic.structure</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Analytic Structure" version="7.0"> <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" /> <label for="model_name" class="oe_edit_only" string="Target Model Name" />
...@@ -124,8 +128,6 @@ ...@@ -124,8 +128,6 @@
<label for="model_name" class="oe_edit_only" string="Target Model Name" /> <label for="model_name" class="oe_edit_only" string="Target Model Name" />
<h1> <field name="model_name" class="oe_edit_only"
<field name="model_name" class="oe_inline" placeholder="Target Model Name" />
placeholder="Target Model Name" style="width: 6em" />
</h1>
<group colspan="4" col="4"> <group colspan="4" col="4">
<field name="nd_id" /> <field name="nd_id" />
<newline /> <newline />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment