← Back to team overview

openerp-connector-community team mailing list archive

Re: override field selection, best pratice

 

I prefer second option, though not the ideal, because in the first one, you
are overwritting full field, avoiding possible future definition changes,
and having to retranslate label and help.

ORM should be improved to detect overwritten methods and call them, so any
trick has to be done, but I don't know if there is any technical issue that
prevents this.

Regards.


2014-02-24 11:10 GMT+01:00 David Beal <david.beal@xxxxxxxxxxxx>:

> 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
>
> --
> Mailing list: https://launchpad.net/~openerp-connector-community
> Post to     : openerp-connector-community@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openerp-connector-community
> More help   : https://help.launchpad.net/ListHelp
>

References