Odoo Help

0

Error: NameError: name 'self' is not defined

By
Jithin
on 9/1/16, 8:26 AM 483 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


2

Akhil P Sivan

--Akhil P Sivan--
3930
| 5 3 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 1/29/17, 6:07 AM

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.

1
Pravitha
On 1/12/17, 2:55 AM

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
0
Divyang Jariwala
On 9/8/16, 2:36 AM

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  "}" .

0

Jignesh Mehta

--Jignesh Mehta--
2184
| 6 5 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 9/2/16, 12:08 AM

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,


About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/1/16, 8:26 AM
Seen: 483 times
Last updated: 1/29/17, 6:07 AM