| Thread Previous • Date Previous • Date Next • Thread Next |
Now, at least in v6.0 there is also the possibility to make the selection a simple list attribute of the model, and .append() to it in the inherited model.
in the main model:
_TYPE_LIST = [
#...
]
_columns = {
'type': fields.selection(
_TYPE_LIST,
'Type',),
in inherited models:
def __init__(self, pool, cr):
"""Add a type state value"""
super(MyModel, self)._TYPE_LIST.append(('myvalue', My Value'), )
return super(MyModel, self).__init__(pool, cr)
But basically all three solutions solutions suck don't they?
Your solution 2 sucks a bit less, but no-op wrappers make me raise
eybrows when I read the code. You'll need to comment it every time.
Solution 1 is really bad because it makes it impossible for several
modules to add values to the same selection field.
By the way, I think the same goes for function fields - we have to re-write the field definition every time don't we?
Please Anthony Lesuisse, Olivier Dony: can't changes be made in the server to make the "value list" functions obey the usual inherit mechanism?
Lionel Sausin. Le 24/02/2014 11:10, David Beal a écrit :
Hello devs,
I have a question towards OpenERP experts
We cant' inherit directly method defined for field selection.
Two Solutions
1.a/ Either you do this on main class model
def _get_type_selection(self, cr, uid, context=None):
""" To inherit to add type """
return []
_columns = {
'type': fields.selection(
_get_type_selection,
'Type',),
1.b/ and defined again field on each inherit class
def _get_type_selection(self, cr, uid, context=None):
res = super(MyClass, self)._get_type_selection(cr, uid, context=context)
res.append(('myvalue', My Value'),)
return res
_columns = {
'type': fields.selection(
_get_type_selection,
'Type',),
2.a/ Either you do that in the main model
def _get_type_selection(self, cr, uid, context=None):
""" To inherit to add type """
return []
def __get_type_selection(self, cr, uid, context=None):
return self._get_type_selection(cr, uid, context=context)
_columns = {
'type': fields.selection(
__get_type_selection,
'Type',),
2.b/ only this on each inherit class:
def _get_type_selection(self, cr, uid, context=None):
res = super(MyClass, self)._get_type_selection(cr, uid, context=context)
res.append(('myvalue', My Value'),)
return res
First solution is used for example here
in http://bazaar.launchpad.net/~stock-logistic-core-editors/carriers-deliveries/7.0/files/9/delivery_carrier_label_postlogistics.
Mainly at Akretion we think second solution is better,
Thanks for your feed back
David BEAL
Akretion
OpenERP Development - Integration
+33 (0)6 67 22 86 89
+33 (0)4 82 53 84 60
| Thread Previous • Date Previous • Date Next • Thread Next |