This question has been flagged
1 Reply
3931 Views

Here is my code ,problem is when I click on  purchase_order_data1 button the sale order 'name' field should be add in   'so_number'  of purchase.order form( this is my custom field ).But its not coming .Need a help.......

<button name="purchase_order_data1" string="Test" type="object"/>


class sale_order(osv.Model):
    _inherit = "sale.order"
    _description = "Validate quote"
    _columns = {

}

 def purchase_order_data1(self,cr,uid,ids,context):
        if not context: context={}
        for id in ids:
            deg_obj=self.pool.get('sale.order').browse(cr,uid,id, context=context)
            my_id=deg_obj.name
            context.update({'default_so_number':deg_obj.name})
            return{
                   'view_type': 'form',
                   'view_mode': 'form',
                   'res_model': 'purchase.order',
                   'context': context,
                   'type': 'ir.actions.act_window',
                   'nodestroy':True,
                   'target':'inline',
                   }
#                 my_id=int(deg_obj.my_products)
#                 prr= int(deg_obj.categg_temp)
#                 pch= int(deg_obj.categ_temps)
#                 cch= int(deg_obj.categ_temp2)
                
 <record id="purchase_order_inherited" model="ir.ui.view">
                <field name="name">purchase</field>
                <field name="model">purchase.order</field>
                
                <field name="inherit_id" ref="purchase.purchase_order_form"/>
                <field name="arch" type="xml">
                <group>       
                   <field name="so_number"/>
                    <field name="project_name" />
                     <field name="client_po_number"/>
                
      </group>

class purchase_order(osv.Model):
    
    _inherit='purchase.order'


    _columns={
 'so_number':fields.integer('S.O.Number'),

}

Avatar
Discard
Best Answer

Try replacing your line

'context': context.update({'so_number': my_id}),

By:

'context': context.update({'default_so_number': my_id}),

Avatar
Discard
Author

what is default_so_number u mentioned in above code

This is the way to pass a default value for a field when opening a form view on a record which is not yet stored. You simply prepend the field name with default_

Author

But its not working dear.....

my_id=deg_obj.name is not correct. you should do my_id=deg_obj.id

Author

I tried Emaunel ,Based on your code that number is not coming into so_number custom field.its coming as empty

But by doing 'default_so_number':deg_obj.name you assign a string to a field that should be integer... As well you should not return in a for loop. You cannot return many views, only one, for one object.