首页 > 解决方案 > 从向导打印

问题描述

我想从向导打印一份报告。在此向导中,我恢复所选订单并使用所选订单调用 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。

有人能帮我吗?

谢谢

标签: odoo-11

解决方案


首先根据您的示例,在您的系统中,必须有 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"
    />

希望这可以帮助!


推荐阅读