odoo-11 - 从向导打印
问题描述
我想从向导打印一份报告。在此向导中,我恢复所选订单并使用所选订单调用 report_action 函数。
问题是我不知道如何将订单发送到这个函数。这是代码:
def _get_default_orders(self):
return self.env['sale.order'].browse(self.env.context.get('active_ids'))
order_ids = fields.Many2many('sale.order', string='Orders', default=_get_default_orders)
@api.multi
def processed_orders(self):
list = []
for orders in self:
if orders.order_ids:
list.append(orders)
datas = {
'ids': list,
'model': 'sale.order',
}
return self.env.ref('aloha_reports_templates.custom_report_sale_order').sudo().report_action(self, data=datas)
Odoo 生成错误,因为我没有将参数正确发送到report_action。
有人能帮我吗?
谢谢
解决方案
首先根据您的示例,在您的系统中,必须有 aloha_reports_templates.custom_report_sale_order 可用于报告的操作。
让我向您展示一个来自 odoo 11 社区代码文件的示例:account/models/account_invoice.py方法(invoice_print)
@api.multi
def invoice_print(self):
""" Print the invoice and mark it as sent, so that we can see more
easily the next step of the workflow
"""
self.ensure_one()
self.sent = True
if self.user_has_groups('account.group_account_invoice'):
return self.env.ref('account.account_invoices').report_action(self)
else:
return self.env.ref('account.account_invoices_without_payment').report_action(self)
根据 odoo 11 社区中的上述代码,已经创建了 account_invoices 报告操作,如下所示(account/views/account_report.xml)。
<report
id="account_invoices"
model="account.invoice"
string="Invoices"
report_type="qweb-pdf"
name="account.report_invoice_with_payments"
file="account.report_invoice_with_payments"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
print_report_name="(object._get_printed_report_name())"
groups="account.group_account_invoice"
/>
希望这可以帮助!
推荐阅读
- swift - 在 Swift 中的网格中查找总和的更好方法
- google-analytics - Google Analytics 中的用户数量似乎很奇怪
- amazon-web-services - 您可以将新图片上传到 S3 并使用相同的链接吗?
- git - 如何将发布提交合并为一个
- c# - UITableViewRowAction 不适用于 Xamarin 表单
- selenium - 尝试在 pepperfy.com 上获取学习灯的价格时出现错误 ArrayIndexOutOfBoundsException
- python - 在numpy中随机索引多维数组
- python - 如何删除 Python 循环中的先前迭代?
- lua - 有没有办法在 Lua 中对特定日期进行倒计时?
- jssor - JSSOR - 如何反转石头过渡幻灯片方向