Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5256 Lượt xem

I want click button create sale order data product in form custom transfer to form sale order.

but error:  name 'product' is not defined



<button name="create_sale_order" string="Sale Order"  type="object" class="oe_highlight" />    

-----------------------------------------------------------------------------------------------------------------


class custom(models.Model):
    _name = 'a1'  

    contract_document_ids = fields.One2many('b2', 'b_id', string='test')


class contract_item(models.Model):    

_name = 'b2'
product = fields.Many2one('product.product', string='Product Name')  

b_id = fields.Many2one('a1')        


 def create_sale_order(self):          

  return {              

              'name': 'Create Sale Order',            

               'res_model': 'sale.order',        

                'type': 'ir.actions.act_window',         

               'context': {'default_product_id':product},      

                'view_type': 'form',     

                'view_mode': 'form',          

                 'views': [(self.env.ref('sale.view_order_form').id, 'form')],             

                'view_id': self.env.ref('sale.view_order_form').id,             

                'target': 'current',                }     

------------------------------------------------------------------------

please help me.


Ảnh đại diện
Huỷ bỏ
Tác giả

Hi malary, Thank you for your help, but i have an error:

AttributeError: 'a1' object has no attribute 'product',

Because product is the another class(b2)

Hello,

If your "create_sale_order' method is in b2 class and you call the product which is from same b2 class, then it will work.

please try this code,

def create_sale_order(self):

for record in self:

return {

'name': 'Create Sale Order',

'res_model': 'sale.order',

'type': 'ir.actions.act_window',

'context': {'default_product_id':record.product.id},

'view_type': 'form',

'view_mode': 'form',

'views': [(self.env.ref('sale.view_order_form').id, 'form')],

'view_id': self.env.ref('sale.view_order_form').id,

'target': 'current',

}

Thanks

Câu trả lời hay nhất

Hello,

I think the issue is you pass the product in context:

         'context': {'default_product_id':product}

Instead of product, you can pass self.product.id

     'context': {'default_product_id':self.product.id}


If you create sale order, then the product is in sale order line. You can not pass it in sale order. If you create some customisations, and this code is according to your customisations, then ok.

Hope it will help you,

Thanks

Ảnh đại diện
Huỷ bỏ