That was not clear. But it seems that OpenERP SA will continue to use snake case.
As discussed with Raphaël Collet. This convention should be the one to use after RC1.
from openerp import models
from openerp import fields
from openerp import _
from openerp import api
from openerp import exceptions
A typical module import would be:
from openerp import models, fields, api, _
Class should be initialized like this:
class Toto(models.Model): pass class Titi(models.TransientModel): pass
except_orm
exception is deprecated.
We should use openerp.exceptions.Warning
and subclasses instances
Note
Do not mix with built-in Python Warning.
Warning with a possibility to redirect the user instead of simply diplaying the warning message.
Should receive as parameters:
param int action_id: id of the action where to perform the redirection param string button_text: text to put on the button that will trigger the redirection.
Login/password error. No message, no traceback.
Access rights error.
Missing record(s)
Exception object holding a traceback for asynchronous reporting.
Some RPC calls (database creation and report generation) happen with an initial request followed by multiple, polling requests. This class is used to store the possible exception occurring in the thread serving the first request, and is then sent to a polling request.
Note
Traceback is misleading, this is really a sys.exc_info()
triplet.
When catching orm exception we should catch both types of exceptions:
try: pass except (Warning, except_orm) as exc: pass
Fields should be declared using new fields API. Putting string key is better than using a long property name:
class AClass(models.Model): name = fields.Char(string="This is a really long long name") # ok really_long_long_long_name = fields.Char()
That said the property name must be meaningful. Avoid name like 'nb' etc.
compute
option should not be used as a workaround to set default.
Defaut should only be used to provide property initialisation.
That said they may share the same function.
We should never alter self in a Model function. It will break the correlation with current Environment caches.
If you use the do_in_draft context manager of Environment it will not be committed but only be done in cache.
When using cursor you should use current environment cursor:
self.env.cr
except if you need to use threads:
with Environment.manage(): # class function env = Environment(cr, uid, context)
_name_get is deprecated.
You should define the display_name field with options:
compute
inverse
Should be done using @api.constrains
decorator in
conjunction with the @api.one
if performance allows it.
If no advance behavior is needed on Model view, standard view (non Qweb) should be the preferred choice.
General guidelines should be found: