Skip to Content
Menu
This question has been flagged
2164 Views

Hello, 

I'm trying to implement the code explained in this page

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-programatically-run-a-report-and-add-it-as-an-attachment-36449

But i get this error:

Traceback (most recent call last):
  File "/opt/odoo/openerp/http.py", line 543, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/openerp/http.py", line 580, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/openerp/http.py", line 316, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/openerp/http.py", line 313, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/openerp/http.py", line 809, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/openerp/http.py", line 409, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/addons/web/controllers/main.py", line 955, in exec_workflow
    return request.session.exec_workflow(model, id, signal)
  File "/opt/odoo/openerp/http.py", line 1117, in exec_workflow
    r = self.proxy('object').exec_workflow(self.db, self.uid, self.password, model, signal, id)
  File "/opt/odoo/openerp/http.py", line 885, in proxy_method
    result = dispatch_rpc(self.service_name, method, args)
  File "/opt/odoo/openerp/http.py", line 115, in dispatch_rpc
    result = dispatch(method, params)
  File "/opt/odoo/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/openerp/service/model.py", line 188, in exec_workflow
    return exec_workflow_cr(cr, uid, obj, signal, *args)
  File "/opt/odoo/openerp/service/model.py", line 182, in exec_workflow_cr
    return execute_cr(cr, uid, obj, 'signal_workflow', [res_id], signal)[res_id]
  File "/opt/odoo/openerp/service/model.py", line 164, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 3571, in signal_workflow
    result[res_id] = workflow.trg_validate(uid, self._name, res_id, signal, cr)
  File "/opt/odoo/openerp/workflow/__init__.py", line 85, in trg_validate
    return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
  File "/opt/odoo/openerp/workflow/service.py", line 91, in validate
    res2 = wi.validate(signal)
  File "/opt/odoo/openerp/workflow/instance.py", line 80, in validate
    wi.process(signal=signal, force_running=force_running, stack=stack)
  File "/opt/odoo/openerp/workflow/workitem.py", line 120, in process
    ok = self._split_test(activity['split_mode'], signal, stack)
  File "/opt/odoo/openerp/workflow/workitem.py", line 248, in _split_test
    self._join_test(t[0], t[1], stack)
  File "/opt/odoo/openerp/workflow/workitem.py", line 257, in _join_test
    WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack)
  File "/opt/odoo/openerp/workflow/workitem.py", line 95, in create
    workflow_item.process(stack=stack)
  File "/opt/odoo/openerp/workflow/workitem.py", line 116, in process
    if not self._execute(activity, stack):
  File "/opt/odoo/openerp/workflow/workitem.py", line 162, in _execute
    returned_action = self.wkf_expr_execute(activity)
  File "/opt/odoo/openerp/workflow/workitem.py", line 313, in wkf_expr_execute
    return self.wkf_expr_eval_expr(activity['action'])
  File "/opt/odoo/openerp/workflow/workitem.py", line 291, in wkf_expr_eval_expr
    result = eval(line, env, nocopy=True)
  File "/opt/odoo/openerp/tools/safe_eval.py", line 314, in safe_eval
    return eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/odoo/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/addons/vs_visite/models.py", line 54, in action_fact
    (result, format) = openerp.report.render_report(cr, uid, record.id, report.report_name, {'model': self._name}, context=context)
  File "/opt/odoo/openerp/report/__init__.py", line 40, in render_report
    return registry['ir.actions.report.xml'].render_report(cr, uid, ids, name, data, context)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/addons/base/ir/ir_actions.py", line 154, in render_report
    return self.pool['report'].get_pdf(cr, uid, res_ids, new_report, data=data, context=context), 'pdf'
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/report/models/report.py", line 199, in get_pdf
    save_in_attachment = self._check_attachment_use(cr, uid, ids, report)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/report/models/report.py", line 342, in _check_attachment_use
    attach_ids = self.pool['ir.attachment'].search(cr, uid, alreadyindb)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/addons/calendar/calendar.py", line 1789, in search
    return super(ir_attachment, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 1646, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/addons/base/ir/ir_attachment.py", line 266, in _search
    access_rights_uid=access_rights_uid)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 4686, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/opt/odoo/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/openerp/models.py", line 4499, in _where_calc
    where_clause, where_params = e.to_sql()
  File "/opt/odoo/openerp/osv/expression.py", line 1277, in to_sql
    q, p = self.__leaf_to_sql(leaf)
  File "/opt/odoo/openerp/osv/expression.py", line 1144, in __leaf_to_sql
    "Invalid value %r in domain term %r" % (right, leaf)
ValueError: "Invalid value vs_visite.consultation(3,) in domain term ('res_id', '=', vs_visite.consultation(3,))" while evaluating
u'action_fact()'

 This is my code:

# -*- coding: utf-8 -*-

from openerp import models, fields, api,netsvc

from pprint import pprint

import openerp

class Consultation(models.Model):

_name = 'vs_visite.consultation'

name = fields.Char(string="NomCli", required=True)

state = fields.Selection([

('rdv', "Rendez-vous"),

('consul', "Consultn"),

('fin', "Clot"),

('fact', "Fact"),

], default='rdv')

@api.multi

def action_rdv(self):

self.state = 'rdv'

@api.multi

def action_consultation(self):

self.state = 'consul'

@api.multi

def action_fin(self):

self.state = 'fin'

@api.multi

def action_fact(self):

self.state = 'fact'

#,cr, uid, ids, field_name, arg,

cr= self._cr

uid= self._uid

ids= self._ids

context=None

attachment_obj = self.pool.get('ir.attachment')

print("before")

for record in self.browse(self):

print("for")

ir_actions_report = self.pool.get('ir.actions.report.xml')

print("snd")

matching_reports = ir_actions_report.search(cr, uid, [('name','=','Consultation')])

print("after")

if matching_reports:

report = ir_actions_report.browse(cr, uid, matching_reports[0])

report_service = 'report.' + report.report_name

#service = netsvc.LocalService(report_service)

print('pretest')

pprint(record.id)

(result, format) = openerp.report.render_report(cr, uid, record.id, report.report_name, {'model': self._name}, context=context)

print('succes')

#(result, format) = service.create(cr, uid, [record.id], {'model': self._name}, context=context)

eval_context = {'time': time, 'object': record}

if not report.attachment or not eval(report.attachment, eval_context):

# no auto-saving of report as attachment, need to do it manually

result = base64.b64encode(result)

file_name = re.sub(r'[^a-zA-Z0-9_-]', '_', 'Your Report Name')

file_name += ".pdf"

attachment_id = attachment_obj.create(cr, uid,

{

'name': file_name,

'datas': result,

'datas_fname': file_name,

'res_model': self._name,

'res_id': record.id,

'type': 'binary'

}, context=context)

self.name = self.name + ' - Facturé'

return True


I think this is a simple error, but I'm a beginner and i can't find where is the problem

Thank you for your help

Avatar
Discard