[Openerp-community] how to access context in my own method/function?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Openerp-community] how to access context in my own method/function?

Martin Herweg

Hi!

I'm using fields.function in a tree view:

 _columns = {
 'qty2_test' : fields.function(_calc_price, arg=2 , type = 'float', method =
True, string = _get_qty(2) ),


in "_calc_price" it is no problem to access the context:

def _calc_price(self, cr, uid, ids, field, arg, context=None):
        form = context['form']


but how can I do it in "_get_qty"  ?

my goal ist to have different healines/labels for the colums depending on the
context.


thank you for any help & hints,

Martin



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] how to access context in my own method/function?

Niels Huylebroeck-2
Don't expect the string argument to be dynamically executed, because you provided the argument "2" the function is actually executed when the module is first loaded and thus the string is static (won't be executed more than once per database)

You should override the fields_view_get method on your object, see the documentation here : http://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html#osv.osv.osv.fields_view_get
There you have access to both the context and are allowed (even expected) to return the view definition to be used by the client.

Regards,
Niels

2011/12/19 Martin Herweg <[hidden email]>

Hi!

I'm using fields.function in a tree view:

 _columns = {
 'qty2_test' : fields.function(_calc_price, arg=2 , type = 'float', method =
True, string = _get_qty(2) ),


in "_calc_price" it is no problem to access the context:

def _calc_price(self, cr, uid, ids, field, arg, context=None):
       form = context['form']


but how can I do it in "_get_qty"  ?

my goal ist to have different healines/labels for the colums depending on the
context.


thank you for any help & hints,

Martin



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp



--
Niels Huylebroeck
Lead Architect   --   Agaplan
Tel. : +32 (0) 93 95 98 90


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] how to access context in my own method/function?

Martin Herweg

Thanks for your answer, Niels.
I now have my own  fields_view_get and it is beeing executed (I see the output
of my print on cosole) and the return-dict "res" looks o.k. but the tree view
did not change.

    def fields_view_get(self, cr, uid, view_id=None, view_type='tree',
context=None, toolbar=False, submenu=False):
        res = super(pricelist_screen,self).fields_view_get(cr, uid, view_id,
view_type, context, toolbar=toolbar, submenu=submenu)
       
        form = context['form']
        qty1 = form['qty1']
        res['fields']['qty1_test']['string']=`qty1`
        print 'hallo'
        print res
        return res

 _columns = {
      'qty1_test' : fields.function(_calc_price, arg=1 , type = 'float',
method = True, string = 'placeholder'),

   

_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp
Reply | Threaded
Open this post in threaded view
|

Re: [Openerp-community] how to access context in my own method/function?

Niels Huylebroeck-2
The res should also contain a key 'arch', you will need to alter that one.
I recon the easiest way is to "from lxml import etree" and parse the arch "myarch = etree.fromstring(res['arch'])" so it becomes an xml tree, then alter it and then "res['arch'] = etree.tostring(myarch)"

2011/12/20 Martin Herweg <[hidden email]>

Thanks for your answer, Niels.
I now have my own  fields_view_get and it is beeing executed (I see the output
of my print on cosole) and the return-dict "res" looks o.k. but the tree view
did not change.

   def fields_view_get(self, cr, uid, view_id=None, view_type='tree',
context=None, toolbar=False, submenu=False):
       res = super(pricelist_screen,self).fields_view_get(cr, uid, view_id,
view_type, context, toolbar=toolbar, submenu=submenu)

       form = context['form']
       qty1 = form['qty1']
       res['fields']['qty1_test']['string']=`qty1`
       print 'hallo'
       print res
       return res

 _columns = {
     'qty1_test' : fields.function(_calc_price, arg=1 , type = 'float',
method = True, string = 'placeholder'),



_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp



--
Niels Huylebroeck
Lead Architect   --   Agaplan
Tel. : +32 (0) 93 95 98 90


_______________________________________________
Mailing list: https://launchpad.net/~openerp-community
Post to     : [hidden email]
Unsubscribe : https://launchpad.net/~openerp-community
More help   : https://help.launchpad.net/ListHelp