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.

0

Hello World method for product.product

By
E.M.
on 6/14/15, 2:33 PM 593 views

I am trying to understand how to extend Odoo. As first step I want to implement a new method named 'hello_world' for product.product class.


This methods does the mandatory 'Hello World', which according to other posts should be seen if odoo is launched in command line:

    print 'Hello World'


Then I set up an automated action which executes python code to launch that method every time a new product is created, so I will have my first new method in Odoo implemented.


I edit and add the following to addons/product/product.py:

class product_product(osv.osv):

[...]

    def hello_world():

        print 'Hello World'


And add the following server action:

Base model: Product

Action: Execute Python Code


Python Code:

self.hello_world()


And I try this flamboyant method by creating a new product through the GUI and getting the following error:

ValueError: "'product.product' object has no attribute 'hello_world'" while evaluating

u'# Available locals:\n# - time, datetime, dateutil: Python libraries\n# - env: Odoo Environement\n# - model: Model of the record on which the action is triggered\n# - object: Record on which the action is triggered if there is one, otherwise None\n# - workflow: Workflow engine\n# - Warning: Warning Exception to use with raise\n# To return an action, assign: action = {...}\nself.hello_world()'


Note: I am aware that the right way of doing this is extending Odoo through modules, but it is needed to understand this before moving forward.

Did you restart the Odoo server? Modification of Python files require a server restart to take effect.

Limitless Virtual Enterprise, Andre de Kock
on 6/15/15, 4:46 AM
0

Odoo

--Odoo --
1328
| 5 2 5
kerala, India
--Odoo --

Working as a Odoo Functional and Technical Expert

Odoo
On 9/11/15, 3:48 AM

Better one Please Follow the odoo official documentation.This is not the proper way for extending the odoo Feature use Inheritance Method

0
CV
On 9/11/15, 3:29 AM

Hello E.M.,


Please try this in python code:

def hello_world(self):

    print 'Hello World'

 

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: 6/14/15, 2:33 PM
Seen: 593 times
Last updated: 9/11/15, 3:48 AM