openerp-connector-community team mailing list archive
-
openerp-connector-community team
-
Mailing list archive
-
Message #00217
Re: override field selection, best pratice
+1 for solution 2 over the 2 others in OCA
and +1k for some better inheritance mechanism for function and selection
fields.
Can we put the store triggers in the weird inheritance things to improve as
well ?
Regards,
On Mon, Feb 24, 2014 at 2:47 PM, Lionel Sausin <ls@xxxxxxxxxxxxxxxx> wrote:
> First, please excuse me if what I'm writing here is not 100% accurate, I
> haven't had time to keep up with recent server-side improvements.
>
> 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
>>
>>
>
> --
> 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
>
--
Yannick Vaucher
Business Solutions Software Developer
Camptocamp SA
PSE A, CH-1015 Lausanne
Phone: +41 21 619 10 30
Office: +41 21 619 10 10
http://www.camptocamp.com/
References