Odoo Help

0
9 Answers
2
Avatar

Akhil P Sivan

--Akhil P Sivan--

4429
| 5 4 7
Kochi, India
--Akhil P Sivan--

Odoo Developer

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
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.

0
GiusyG
11/27/18, 9:31 AM

The correct domain is:

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

0
Avatar

Jignesh Mehta

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

- I have 3+ years of Industry Experience, specializing Odoo Development, Analysis, Customization, Implementation, Integration.
- I have done many Customization modules in Sale, Purchase, Point of Sale, Inventory, CRM and much more. Also Worked in the Odoo Themes like Business Theme or E-Commerce Theme.
- Develop Jewelery Manufacturing process from Scratch. It have more than 10 Department. Develop PDF and Excel reports for this project around 150 per format.

Jignesh Mehta
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,


0
Pravitha
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
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
Jigar Vaghela (jva)
5/8/18, 10:00 AM

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

0
Megha_SerpentCS
8/28/18, 5:53 AM

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.

0
Avatar
--deep--

Techno-Functional Associate with 7+ years of experience in Odoo (formerly known as OpenERP).

deep
11/27/18, 9:14 AM

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
0
Avatar

Aktiv software

--Aktiv software--
3800
| 5 3 7
Ahmedabad, India
--Aktiv software--

 Aktiv software

  • Skype : shah.jainesh

  • email : Sales@Aktivsoftware.com

Aktiv software
8/25/17, 7:13 AM

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            
            }	
Ask a Question
Writer
Keep Informed
1 follower(s)
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