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

Where can I use @ in Odoo?

By
Billiard R Made
on 11/20/14, 5:06 AM 1,251 views

from openerp import api, models

Being new to Python and OpenERP I have quite a bunch of questions.  One of then is, in my code where can I use @?  I see an example I got from https://www.odoo.com/documentation/8.0/reference/reports.html and here I would also like to know what @api.multi is in this piece of code below.  May you also recommand reading material on Python, XML and Java relevant to OpenERP

class ParticularReport(models.AbstractModel):

    _name = 'report.<<module.reportname>>'

    @api.multi

    def render_html(self, data=None):

         report_obj = self.env['report']

         report = report_obj._get_report_from_name('<<module.reportname>>')

         docargs = {

                'doc_ids': self._ids,

                'doc_model': report.model,

                'docs': self,

        }

        return report_obj.render('<<module.reportname>>', docargs)

2

Yenthe

--Yenthe--
6696
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 11/20/14, 5:10 AM

For the general part:
I'm not exactly sure about what you would like to learn or find out but there is some great documentation to be found.
All developer documentation: https://www.odoo.com/documentation/8.0/
Tutorials: https://www.odoo.com/documentation/8.0/howtos/backend.html
Overview of parameters: https://www.odoo.com/documentation/8.0/reference.html


For the part about @api.multi (and @api.one):
The @api.one is specific for one record and can not be used for multiple records. It automaticly loops on records of of a Recordset for you. 
@api.many is for multiple records, where you can loop through it etc. It will be the current Recordset without the itiration. So any looping would need to be programmed by yourself, for whatever you want

An example of @api.one:

@api.one def _compute_name(self):
      self.name = str(random.randint(1, 1e6))

An example of @api.multi:

@api.multi def subscribe(self):
     for session in self.session_ids:
         session.attendee_ids |= self.attendee_ids
     return {}

You can read more about the @api.one and @api.multi here: http://odoo-new-api-guide-line.readthedocs.org/en/latest/decorator.html


I hope this gives you a good start and enough information. If you need more or have other questions do ask.
Yenthe

Thanks so much. So what is @ ??? Is anything that starts with @ a controller or what?

Billiard R Made
on 11/20/14, 5:41 AM

I can't tell you for sure where the @ stands for but I believe its built as a reference and is being used by the Odoo ORM. But I'd like this question open for somebody else to reply, as I'm not 100% sure of this. If my answer was helpful please upvote or accept it by the way! :)

Yenthe
on 11/20/14, 5:54 AM
0
Yvan
On 12/30/15, 8:11 AM

If you want to learn more about the power (or should I say magic...), take a look at the very good blog of Simon Franklin http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/. In this blog you learn step by step what a python decorator is and how powerful decorators are.
Personally, I often use decorators to automatically add log messages to important methods. Don't hesitate to ask you if want some more advises. 

Best regards

Yvan

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: 11/20/14, 5:06 AM
Seen: 1251 times
Last updated: 12/30/15, 8:11 AM