-1
A
回答
1
在一般情況Qweb報告可以打印在雙向
- HTML
每一次聽到,當你調用根據報告類型報告不同的報告方法正在調用。
如果調用報告PDF那麼get_pdf()方法被調用或如果你打電話報告類型爲HTML然後get_html()方法被稱爲報表模塊。
因此,在我們的情況下,您必須重寫我們模塊中的上述兩種方法,然後添加一些像這樣的東西。
改寫報表模塊的get_pdf()方法:
class Report(osv.Model):
_inherit = "report"
_description = "Report"
@api.v7
def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None):
"""This method generates and returns pdf version of a report.
"""
order_pool=self.pool.get('sale.order')
for order in order_pool.browse(cr, uid, ids, context=None):
if order.state:
if order.state == 'draft':
raise osv.except_osv(_("Warning!"), _("Your Printed Report is in Draft State ...!! "))
if context is None:
context = {}
if html is None:
html = self.get_html(cr, uid, ids, report_name, data=data, context=context)
html = html.decode('utf-8') # Ensure the current document is utf-8 encoded.
# Get the ir.actions.report.xml record we are working on.
report = self._get_report_from_name(cr, uid, report_name)
# Check if we have to save the report or if we have to get one from the db.
save_in_attachment = self._check_attachment_use(cr, uid, ids, report)
# Get the paperformat associated to the report, otherwise fallback on the company one.
if not report.paperformat_id:
user = self.pool['res.users'].browse(cr, uid, uid)
paperformat = user.company_id.paperformat_id
else:
paperformat = report.paperformat_id
# Preparing the minimal html pages
css = '' # Will contain local css
headerhtml = []
contenthtml = []
footerhtml = []
irconfig_obj = self.pool['ir.config_parameter']
base_url = irconfig_obj.get_param(cr, SUPERUSER_ID, 'report.url') or irconfig_obj.get_param(cr, SUPERUSER_ID, 'web.base.url')
# Minimal page renderer
view_obj = self.pool['ir.ui.view']
render_minimal = partial(view_obj.render, cr, uid, 'report.minimal_layout', context=context)
# The received html report must be simplified. We convert it in a xml tree
# in order to extract headers, bodies and footers.
try:
root = lxml.html.fromstring(html)
match_klass = "//div[contains(concat(' ', normalize-space(@class), ' '), ' {} ')]"
for node in root.xpath("//html/head/style"):
css += node.text
for node in root.xpath(match_klass.format('header')):
body = lxml.html.tostring(node)
header = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
headerhtml.append(header)
for node in root.xpath(match_klass.format('footer')):
body = lxml.html.tostring(node)
footer = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url))
footerhtml.append(footer)
for node in root.xpath(match_klass.format('page')):
# Previously, we marked some reports to be saved in attachment via their ids, so we
# must set a relation between report ids and report's content. We use the QWeb
# branding in order to do so: searching after a node having a data-oe-model
# attribute with the value of the current report model and read its oe-id attribute
if ids and len(ids) == 1:
reportid = ids[0]
else:
oemodelnode = node.find(".//*[@data-oe-model='%s']" % report.model)
if oemodelnode is not None:
reportid = oemodelnode.get('data-oe-id')
if reportid:
reportid = int(reportid)
else:
reportid = False
# Extract the body
body = lxml.html.tostring(node)
reportcontent = render_minimal(dict(css=css, subst=False, body=body, base_url=base_url))
contenthtml.append(tuple([reportid, reportcontent]))
except lxml.etree.XMLSyntaxError:
contenthtml = []
contenthtml.append(html)
save_in_attachment = {} # Don't save this potentially malformed document
# Get paperformat arguments set in the root html tag. They are prioritized over
# paperformat-record arguments.
specific_paperformat_args = {}
for attribute in root.items():
if attribute[0].startswith('data-report-'):
specific_paperformat_args[attribute[0]] = attribute[1]
# Run wkhtmltopdf process
return self._run_wkhtmltopdf(
cr, uid, headerhtml, footerhtml, contenthtml, context.get('landscape'),
paperformat, specific_paperformat_args, save_in_attachment
)
由於相同的方法,你可以在你的模塊中爲get_html覆蓋(),並檢查它
聽到的代碼將檢查銷售訂單報告行動。
上面的代碼可以從我身邊成功測試。
我希望這對你有所幫助.. :)
相關問題
- 1. Odoo Qweb報告
- 2. odoo qweb報告當前用戶lang
- 3. odoo:使用嚮導打印qweb報告
- 4. qweb報告odoo中字數的總額
- 5. odoo/OpenERP V8 - QWeb報告教程
- 6. Qweb報告report_name不起作用
- 7. Odoo - 在qweb報告中添加頁碼
- 8. 阻止UIWebView警報
- 9. Odoo 8 QWEB /創建自定義報告/ QWebException錯誤
- 10. 如何在報告中使用rowspan? | Qweb,Odoo 10
- 11. 使用Qweb產生在odoo PDF報告9
- 12. 如何在我的QWeb報告中使用python函數?
- 13. 如何在Odoo 8 QWeb報告中格式化日期?
- 14. 如何管理QWEB報告中的空間
- 15. 如何創建odoo 9.0的QWeb報告一步一步
- 16. 如何在qweb報告中打印時間時更改時區?
- 17. Odoo - 從qweb報告中調用python函數
- 18. 在Qweb報告中獲取公司的currency_id Odoo 10
- 19. 當在odoo報告中評估時Qweb異常
- 20. Odoo 9自定義qweb報告與CSS不起作用
- 21. 如何在qWeb報告中設置PDF名稱,Odoo?
- 22. Odoo版本8中的Qweb模板報告
- 23. 在qweb報告中獲取文檔附件列表Odoo
- 24. 如何在Odoo 10 QWeb報告中格式化日期?
- 25. Odoo 9.0c:如何讓qweb報告中的當前用戶?
- 26. 的ListView阻止AdMob廣告
- 27. 此Android權限是否阻止我獲取錯誤報告?
- 28. 任務報告IsCompleted,但仍然阻止結果?
- 29. IE隱私報告,阻止iframe中的Cookie
- 30. BIRT報告阻止隱藏的查詢被執行