Skip to Content
Menu
This question has been flagged
9 Replies
25494 Views

Can anyone please help this!!!


class FloatingPurchase(models.Model):

_name= "floating.purchase"

_description = "Purchase Order"


name = fields.Integer(string="Quantity", align="center", required=True)

product_id = fields.Many2one('product.template', string ="Product")

brand_id = fields.Many2one('product.brand', string="Product Brand", required=True)

part_number = fields.Many2one('product.parts', string ="Part Number", required=True)

vendors = fields.Many2one('res.partner', string= "Vendor")

store_id = fields.Many2one('res.store', string= "Shop")


@api.multi

def generate_purchase_history(self):

action = self.env.ref('purchase.action_purchase_line_product_tree')

domain="[('product_id', '=', self.product_id)]"

return {

'name': action.name,

'help': action.help,

'type': action.type,

'view_type': action.view_type,

'view_mode': action.view_mode,

'target': action.target,

'res_model': action.res_model,

'domain': domain


Avatar
Discard
Best Answer

Hi,

I think the problem is with the way you have set domain variable.

Please try like this:

@api.multi    
def generate_purchase_history(self):
    action = self.env.ref('purchase.action_purchase_line_product_tree')
    domain=[('product_id.id', '=', self.product_id.id)]
    return {
            'name': action.name,
            'help': action.help,
            'type': action.type,
            'view_type': action.view_type,
            'view_mode': action.view_mode,
            'target': action.target,
            'res_model': action.res_model,
            'domain': domain
            }

Hope this helps.

Avatar
Discard
Best Answer

domain="[('product_id', '=', self.product_id)]"

this domain set as string so view don't have self so remove "" from domain and do like

domain= [('product_id', '=', self.product_id)]


Thank you

Avatar
Discard
Best Answer

Hi,

Make proper indentation and Change 'product_id' field with relation 'product.product'. Like below :

 product_id = fields.Many2one('product.product')

@api.multi    
def generate_purchase_history(self):
    action = self.env.ref('purchase.action_purchase_line_product_tree')
    domain=[('product_id', '=', self.product_id)]        
    return {                
            'name': action.name,
            'help': action.help,
            'type': action.type,
            'view_type': action.view_type,
            'view_mode': action.view_mode,
            'target': action.target,
            'res_model': action.res_model,
            'domain': domain            
            }	
Avatar
Discard
Best Answer

Jithin

It seems that syntax of domain is wrong, you can define like

domain = [('product_id.id', '=', self.product_id.id)]

one more thing, put your code inside the method.

Thank You.

Avatar
Discard
Best Answer

Hello Jithin,


In purchase order line, product's object is product.product and you taken here product.template

Try with take product.product instead of product.template


product_id = fields.Many2one('product.product', string ="Product")


Hope this will helps you.

Thanks,


Avatar
Discard
Best Answer

Whenever a method is defined '@api.multi' it means, the method can accept a list of RecordSet, thus the param Self might hold list of BrowseRecords, in that case, Add a loop to do necessary.


@api.multi

def generate_purchase_history(self):

action = self.env.ref('purchase.action_purchase_line_product_tree')

ProductIds = []
for case in self:
     ProductIds.append(case.product_id.id)
 
domain= [('product_id', 'in',ProductIds )]
return {
        'name': action.name,
        'help': action.help,
        'type': action.type,
        'view_type': action.view_type,
        'view_mode': action.view_mode,
        'target': action.target,
        'res_model': action.res_model,
        'domain': domain
Avatar
Discard
Best Answer

The correct domain is:

domain="[('product_id', '=', self.product_id.id)]"

Avatar
Discard
Best Answer

Hi Jithin,

Self is not defined error can occur when your indentation is not proper. so, check your indentation.

another one thing i am seeing in your code is return statement doesn't have ending  "}" .

Avatar
Discard
Best Answer

I think you can't get "product_id" using "self.product_id"

Try something like this:

@api.multi
def generate_purchase_history(self):
for data in self:
     product = data.product_id.id
    action = self.env.ref('purchase.action_purchase_line_product_tree')
    domain= [('product_id', '=', product)]
    return {
        'name': action.name,
        'help': action.help,
        'type': action.type,
        'view_type': action.view_type,
        'view_mode': action.view_mode,
        'target': action.target,
        'res_model': action.res_model,
        'domain': domain
Avatar
Discard