Odoo Help

Welcome!

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

1

Where can product_id be retrieved when a new product is created?

By
E.M.
on 9/29/15, 6:32 AM 469 views

I want to do some actions for every new created product.

In order to do that I need the product_id of the freshly new generated product.

I know that I can extend the create method of product.template as in:

class AdditionalActionsOnProductCreation ( models.Model )

    _inherit = 'product.template'

    @api.model
    def create(self, vals):
        ....
    # Creates the product using standard create metho
    new_product_template = super(AdditionalActionsOnProductCreation, self).create(vals

# Try to add the product_id and assign to ean13 field (just to test/see it easily)
    new_product_template.update({'ean13': new_product_template.product_id})
    
    return new_product_template                 

But product_id is not there, where should i retrieve it?

0

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 9/29/15, 6:56 AM

You did as Empiro suggested in this answer, I think you have to get a correct result. Why don't you inherit the 'product.product' class. Try and see

I have tried both new_product_template.product_id and new_product_product.product_id extending respectively product.template and product.product without success. " print new_product.product_id AttributeError: 'product.product' object has no attribute 'product_id'"

E.M.
on 9/29/15, 7:17 AM

Test with new_product.product_tmpl_id

Maurice Agée
on 10/1/15, 12:26 PM
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 10/1/15, 9:08 AM

Hi EM,

Inspite of inheriting product.template, why don't you inherit product.product.

As with the creation of every product.template a product.product record is created......so you can easily get this by overriding create method of product.product.

and one more thing , we don't have product_id in product.template, but product_templ_id(product.template) in product.product.
Hope it will help you  

"product_tmpl_id" not "product_templ_id"

Maurice Agée
on 10/1/15, 12:24 PM
0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 9/29/15, 8:17 AM

My suggestion, you create new base.action.rule and fire it when record is created.

Could you please elaborate? Any example on how to create one? Thanks

E.M.
on 9/29/15, 8:46 AM

For example, in module crm, see crm_action_rule_demo.xml

zbik
on 9/29/15, 9:09 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/29/15, 6:32 AM
Seen: 469 times
Last updated: 10/1/15, 9:08 AM