Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

ValueError: "local variable ' ' referenced before assignment" while evaluating u'action_ship_create()'

By
Susi
on 10/26/16, 6:21 AM 195 views

i have code like this

def _picking_assign(self,cr, uid, move_ids, procurement_group, location_from, location_to, context=None):
pick_obj = self.pool.get("stock.picking")
    move = self.browse(cr,uid,move_ids[0])
    obj_model = self.pool.get('ir.model')
    obj_model_id = obj_model.search(cr,uid,[ ('model','=',move.procurement_id.sale_line_id.order_id.__class__.__name__) ])
    if move.cabang:
    values = {
            'origin': move.origin,
            'company_id': move.company_id and move.company_id.id or False,
            'move_type': move.group_id and move.group_id.move_type or 'direct',
            'partner_id': move.partner_id.id or False,
            'picking_type_id': move.picking_type_id and move.picking_type_id.id or False,
            'group_id': procurement_group,
            'location_id':location_from,
            'location_dest_id': location_to,
            'cabang': move.cabang.id,
            'state': 'draft',
            'transaction_id': move.procurement_id.sale_line_id.order_id.id,
            'model_id': obj_model_id[0]
            }
        pick = pick_obj.create(cr, uid, values, context=context)
        self.write(cr, uid, move_ids, {'picking_id': pick}, context=context)
    res = super(stock,self)._picking_assign(cr, uid, move_ids, procurement_group, location_from, location_to, context=context)
    pick_obj.force_assign(cr,uid,pick)
    return res

but i getting error like this

File "/home/susi/odoo/addons/SAVIRA/mcs_sale_order/mcs_procurement_order.py", line 28, in_picking_assign    pick_obj.force_assign(cr,uid,pick)ValueError: "local variable 'pick' referenced before assignment" while evaluatingu'action_ship_create()'


anyone can help me what its mean? and how i fix it. Thanks before

1
ayman mohammed adam
On 10/26/16, 6:33 AM

dear Susi

you need to define pick=False variable out of if statement.

and you must check it before call it as parameter on pick_obj.force_assign(cr,uid,pick)

like this

if pick:
                pick_obj.force_assign(cr,uid,pick)


I hope I helped you...

dear ayman, thanks before for your answer. i have try your solution its not getting error again. but the value field that i want get its still empty. do you know why?

Susi
on 10/26/16, 10:33 PM
4

Nilmar Shereef

--Nilmar Shereef--
811
| 4 3 7
Calicut, India
--Nilmar Shereef--

Python Developer. Android Developer. .Net Developer

Nilmar Shereef
On 10/27/16, 1:04 AM

Hai Susi,.
  You assigned pick variable "pick = pick_obj.create(cr, uid, values, context=context)"  inside a if block in this function[ if move.cabang:]. In case this if condition fails, the pick will not assign. It will arise error message while you use pick variable in any other function or block. So you have to set a dummy value to pick outside of if block  

0
Divyang Jariwala
On 10/27/16, 1:17 AM

Hello Susi,

Local variable is accessible within a block only.

Here you have declare pick variable that is storing the result return by a create method.

that pick variable is accessible within a if block only.

if you need to access it then you must declare the same variable outside of block.


I Hope this will help you.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/26/16, 6:21 AM
Seen: 195 times
Last updated: 10/27/16, 1:17 AM