This question has been flagged
2659 Views

Hi, I wrote a function to update my stock equipment. In fact I have 3 classes, one that contains all my equipment, which contains a point of the stock and the last which allows for supply, I put the function in the class of supply, I execute from a button as follows:

<button name="act_order_instock" type="objet" string="In stock" class="oe_highlight" attrs="{'invisible':[('state','=','instock')]}"/>  <field name="state" widget="statusbar" statusbar_visible = "draft,instock"/>

and here is the function:

def act_order_instock(self, cr, uid,ids,context=None):
    val = 0.0    
    res = {}
    for record in self.browse(cr, uid,ids,context=context):
        cr.execute("select quantity from material_equipmentstock p where id=%s",(record.equipmentstock_id.id,))
        res = cr.dictfetchall()
        if res:
            print'---------------------------------------------'        
            print(res)
            print'--------------------------------------------'
            for elt in res:
                st = elt['quantity']
                print elt
                val = st + record.quantity
            if val > 0:
                cr.execute("UPDATE material_equipmentstock SET quantity=%s "\
                  "where id=%s",(val,record.equipmentstock_id.id))
                self.write(cr, uid, ids,{'state':'instock'},context=context)
            else:
                raise osv.except_osv('Sorry', 'Impossible de faire l'approvisionnement!')      
        else:
                raise osv.except_osv('Sorry', 'Impossible')
    return True

The problem is that when I click the button, nothing happens, I have need of your help, thank you.

Avatar
Discard