Giter Site home page Giter Site logo

oca-decorators's Introduction

License: LGPL-3 | PyPi Package | PyPi Versions

Build Status | Test Coverage | Code Climate

Python OCA

This library contains helpers for Odoo developers, such as:

  • oca.decorators.foreach - A replacement for the deprecated odoo.api.one

Installation

Install this package into your Odoo environment.

Using Pip:

pip install oca-decorators

Using Git:

git clone https://github.com/OCA/oca-decorators python oca-decorators/setup.py install

Setup

Usage

Known Issues / Road Map

Credits

Images

Contributors

Maintainer

Odoo Community Association

This library is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.

oca-decorators's People

Contributors

lasley avatar lmignon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oca-decorators's Issues

[RFC] oca.mixins

seems a good idea to me. We already have some modules adding mixins, they might have a better home in a library. But we'd create a new project for that, right?

I also want to create GroupableMixin some time which adds the function grouped(*fields) yielding recordsets grouped by the fields given.

oca.decorators.foreach: Doesn't work or not properly used

As there's no instruction on how to use it, I have made this sample code:

import oca.decorators
from odoo import models, fields


class Model(models.Model):
    _name = 'test'

    field = fields.Boolean(compute="_compute_field")

    @oca.decorators.foreach
    def _compute_field(self):
        self.field = False

and I get the error:

Odoo Server Error

Traceback (most recent call last):
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 650, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 687, in dispatch
result = self._call_function(**self.params)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 323, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 316, in checked_call
result = self.endpoint(*a, **kw)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 966, in call
return self.method(*args, **kw)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/http.py", line 516, in response_wrap
response = f(*args, **kw)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/addons/web/controllers/main.py", line 895, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/addons/web/controllers/main.py", line 887, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/models.py", line 5305, in search_read
result = self.read(cr, uid, record_ids, fields, context=read_ctx)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/models.py", line 3208, in read
result = BaseModel.read(records, fields, load=load)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/models.py", line 3254, in read
values[name] = field.convert_to_read(record[name], use_name_get)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/models.py", line 5769, in getitem
return self._fields[key].get(self, type(self))
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/fields.py", line 831, in get
self.determine_value(record)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/fields.py", line 940, in determine_value
self.compute_value(recs)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/fields.py", line 895, in compute_value
self._compute_value(records)
File "/Datos/Installs/ERP/odoo/9.0/odoo-community/openerp/fields.py", line 885, in _compute_value
getattr(records, self.compute)()
File "/usr/local/lib/python2.7/dist-packages/oca/decorators/foreach.py", line 72, in _foreach
wrapper = decorator(loop, method)
File "/usr/lib/python2.7/dist-packages/decorator.py", line 239, in decorator
return decorate(_func, caller)
File "/usr/lib/python2.7/dist-packages/decorator.py", line 229, in decorate
evaldict, wrapped=func)
File "/usr/lib/python2.7/dist-packages/decorator.py", line 216, in create
self = cls(func, name, signature, defaults, doc, module)
File "/usr/lib/python2.7/dist-packages/decorator.py", line 99, in init
self.name = func.name
AttributeError: 'test' object has no attribute 'name'

Am I doing anything wrong?

[RFC] new api.groups decorator

Implementation

def groups(*groups):
    # check if current user are member of one of the given groups.
    # If not, raise an error. "To do this action, you should be member of ..."

Call sample

@oca.decorators.groups('group_1', 'group_2', '...')
def function_name(self, args):
    # custom action

Main interest

The check will be done if function is called by

  • (1) another function,
  • (2) an xml-rpc call,
  • (3) a button in a view. (<button name='function_name' />)

So it is a more secured approach that writing <button name='function_name' groups='group_xml_id'/> that does'nt prevent for the time being case 1 or 2.

Ref of the previous discussion

OCA/server-tools#944

CC : @NL66278, @ lasley, @pedrobaeza

RFC: Add oca.decorators.onwrite

This is something I've been waiting for a long time, but now that we have this, I don't know which one would be the way to go.

Read the motivation and discussion on implementation from odoo/odoo#11042.

Summarizing, basically I'd love to legally abuse @api.constrains to have a method that gets executed whenever write() or create() are called and include the defined fields.

One way to do it would be just onwrite = odoo.api.constrains, and leave further work when a incompatibility arises, given the decorator can actually be abused.

Another way to do it would be to do it fine from the beginning. The decorator would be something like:

def onwrite(*fields):
    ...

When no fields come in, it is called on every write and create. When there are fields, it is called only when write and create dicts include keys those fields. Recursion should be prevented automatically.

The doubt is how to overload both methods automatically when all I have is a decorator... ๐Ÿค”

Ideas?

Nothing happens after install

I installed this lib through pip install oca-decorators. Actually I need it for the pos_pricelist module for Odoo. Before installation of this lib I cannot install the pricelist Odoo module, after I also can't. Even though the installation of oca-decorators went successful according to the command line. I've tried a reboot, restarting Odoo server but to no avail...

correct way to import / use this lib

Hi,

The OCA module pos_pricelist (v10.0) is using this lib since a few days. Even the import is protected, the code is broken any installation that has no this lib installed, even if the module is not installed.

What is the good way to import & use this lib, without breaking such deployment.

OCA/pos#249

kind regard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.