Odoo Help

0

0
1 Answer
2
Avatar

Niyas Raphy

--Niyas Raphy--
24539
| 7 7 11
Wayanad, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

Twitter:https://twitter.com/niyasraphy
LinkedIn: https://www.linkedin.com/in/niyasraphy/
FB:https://www.facebook.com/niyasraphy123

Happy to help :)

Niyas Raphy
2019/06/15 5:22

Hi,

You can try like this, suppose if you have the barcode in the variable named barcode_sample(you can change accordingly)


Try this  code:

barcode_sample = "contains value to test"
product = self.env['product.product'].search([('barcode', '=', barcode_sample)], limit=1)
if product:

    product_template = product.product_tmpl_id.id
else:

    archieved_product = self.env['product.product'].search([('active', '=', False), ('barcode', '=', barcode_sample)], limit=1)


The above code will check the product.product model for matching barcode in it, if it exists it will return the corresponding product template in the variable product_template. if it does not exist, it will check the archived records in product.product model and return value in archieved_product variable


Thanks

3 Comments
Gedomo GmbH, Hannes
2019/06/15 5:39

Hello,

thank you! This seems working, but:

I get later errors in my code, because an archieved product miss values, which a active have:

'int' object has no attribute 'seller_ids'

prod.seller_ids.unlink()

I guess if I fix this error, I have later again some errors.

When I found a product, which is archieved ... can I activade it before I continue with my code? So same, as I click in webfront to "active".

Maybe in this way?:

vals = {'active': True} # Active the product

prod.write(vals)

thank you!

Niyas Raphy
2019/06/15 5:59

In the above code in the variable product_template you will get the id of the record, if you need the record there change the line to

product_template = product.product_tmpl_id

Gedomo GmbH, Hannes
2019/06/15 6:18

Oh, thank you :-)

Running now fine!

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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now