I made this function, to execute a query into PostgreSQL, and subtract a quantity from a field to another, when a purchase order is done in OpenErp, the subtraction is made between the two fields, each one belonging to a different class in OpenErp
def cert_rev(self, uid, arg, ids, context=None):
res = {}
for record in self.browse(cr, uid, ids, context):
cr.execute('''SELECT product_qty FROM purchase_order_line
WHERE cert_v IS TRUE
AND state IS approved
sum(certificados_line.Cantidad - purchase_order_line.product_qty)''')
res = cr.fetchone()
Then call it in a column
, like this:
'se_consumio' : fields.function(cert_rev, type='float', string='Prueba Material consumido'),
But it is not working right now, it is giving me this error:
Client Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\http.py", line 204, in dispatch
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\controllers\main.py", line 1130, in call_kw
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\controllers\main.py", line 1122, in _call_kw
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\session.py", line 42, in proxy
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\session.py", line 30, in proxy_method
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\session.py", line 103, in send
Server Traceback (most recent call last):
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\openerp\addons\web\session.py", line 89, in send
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\osv.py", line 197, in execute
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\orm.py", line 3604, in read
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\orm.py", line 3724, in _read_flat
File "C:\Program Files\OpenERP 7.0-20130520-231036\Server\server\.\openerp\osv\fields.py", line 1131, in get
TypeError: cert_rev() takes at most 5 arguments (7 given)
It's my first time doing a query cr.execute
from a module in openerp, so i don't know if i'm missing something, this kind of error is sort of common in python, but can't get any clue on this one.
Anyone can shed some light on this?
Thanks in advance!
P.S. product_qty
is part of a class called purchase_order_line
:
'product_qty': fields.float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
And Cantidad
is part of a class called certificados_line
:
'Cantidad' : fields.float('Cantidad'),
The module which has this certificados_line
class, has purchase
as a dependency on __openerp__.py
file.