4

I need to read a field in an object, which is purchase.order , from another object product.product This field is a selection type field, so if this field has si is selected then do _get_product_available_func(('done')) which is a function already declared in product.product

This is the selection field in purchase.order

'sel_cert' : fields.selection([('si', 'Si'),('no','No')], 'Origen Certificado'),

And this the function which should "retrieve" that field from product.product

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val

The function which has _get_product_available_func(('done))

def _get_product_available_func(states, what):
    def _product_available(self, cr, uid, ids, name, arg, context=None):
        return {}.fromkeys(ids, 0.0)
    return _product_available

_product_qty_available = _get_product_available_func(('done',), ('in', 'out'))
_product_certificado_qty = _get_product_available_func(('done',), ('in', 'out'))
_product_virtual_available = _get_product_available_func(('confirmed','waiting','assigned','done'), ('in', 'out'))
_product_outgoing_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('out',))
_product_incoming_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('in',))

So, i need to "execute" _get_product_available_func(('done')) in product.product when field sel_cert in purchase.order has the value si , but is giving me an error, here's the traceback in openerp server:

Server Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\openerp\addons\web\session.py", line 89, in send
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 197, in execute
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\orm.py", line 3604, in read
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\orm.py", line 3724, in _read_flat
File "C:\Program Files\OpenERP 7.0-20130726-231403\Server\server\.\openerp\osv\fields.py", line 1139, in get
AttributeError: 'NoneType' object has no attribute 'get'

Perhaps i should call _product_qty_available instead in _get_product_available_func?

Anybody could clarify this?

Thanks in advance!

6
  • The error message basically says that you used the get method on something that you expected to have that method (probably a dict) but that turned out to be just None. You should add some guards to your code that check whether your variables really are what you believe them to be... Commented Jul 28, 2013 at 19:08
  • Mmm i see, i'm going to try your answer now, seems like a didn't declared things the way they should be Commented Jul 28, 2013 at 19:53
  • The first code show 'undefined' on products menu, can't even access them, because of the 'pool' getting override in the current object (maybe), then i tried 2nd code and still get the attribute error, you say that maybe it's the 'dict' from the select type field? Maybe returning not what i expect? Commented Jul 28, 2013 at 20:10
  • New idea: desc_cert(...) will only return something if pids == 'si'. Try to return an alternative if pids != 'si'. Commented Jul 28, 2013 at 23:26
  • Also, you might want to check out this site: help.openerp.com/questions Commented Jul 29, 2013 at 0:13

2 Answers 2

2

More ideas:

Try this for once:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val
    return 10

If we get an AttributeError: 'int' object has no attribute 'get', we know that the fault is indeed in the output of this function.

Another idea:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids.lower() == 'si':
            return val

Now pids may be "si" or "Si".

Sign up to request clarification or add additional context in comments.

4 Comments

It is indeed in the output of the function, gonna try the other idea
With ´if pids.lower() == 'si':´ it gives me 'AttributeError: 'list' object has no attribute 'lower'' maybe, i think it's the _defaults thing i was commenting you, gonna try it tomorrow and see what happens, thank you very very much!
Well, at least we know now that pids is a list.
Yeah, thank you! :) if it gets very hard i'll try another solution, and that's all, thank you again!
2

Try this:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    if pids == 'si':
        val = self._get_product_available_func(('done'))
        return val

Or this:

def desc_cert(self, cr, uid, ids, field_name, field_args, context=None):
    if self.pool:
        obj = self.pool.get('purchase.order')
    pids = obj.search(cr, uid, [('sel_cert', '=', 'si')])
    val = self._get_product_available_func(('done'))
    if pids == 'si':
            return val

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.