Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Odoo 8, Programatically run a report and add it as an attachment

Odoberať

Get notified when there's activity on this post

This question has been flagged
2861 Zobrazenia
Avatar
Michel Patz

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

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now