用python odoo打印报告

时间:2016-05-18 10:18:48

标签: python openerp odoo-9

如何打印customer.payment记录列表,使用向导打开状态。这是我的模块。我正在使用Odoo 9。

class CustomerPayment(models.Model):
    _name = 'customer.payment'
    _rec_name = 'name'


    name = fields.Char(default="New")
    invoice_number = fields.Many2one('account.invoice')
    customer = fields.Many2one('res.partner')
    application_id = fields.Many2one('admission.form')
    date = fields.Date()
    reference = fields.Char()
    cashier = fields.Many2one('res.users')
    journal_item = fields.Many2one('journal.item')
    payment_account = fields.Many2one('erp.account', default=default_payment_account)
    payment_line = fields.One2many('payment.line','payment_id')
    description = fields.Text()
    state = fields.Selection([('open','Open'), ('payed','Payed'),('refund','Refund')], default="open")
    total = fields.Float(compute="get_total")
    due_amount = fields.Float(compute="get_payable")
    payed = fields.Float()
    course_id = fields.Many2one('student.course')
    payable = fields.Float()
    discount = fields.Float(compute="get_discount")
    journal = fields.Many2one('erp.journal', default=get_default_journal)
    type = fields.Selection([('sale','Sale'),('purchase','Purchase')])

class report_wizard(models.TransientModel):
    _name = 'report.wizard'

这是功能样本,希望你得到我想要做的。 Account_report是模块名称,payment_report是使用打印按钮仅打印一条记录的报告。

@api.multi
def print_report(self)
   data = self.env['customer.payment'].search([('state','=','open')])
   return self.env['report'].render('account_report.payment_report', data)

2 个答案:

答案 0 :(得分:2)

该函数必须返回一个具有要打印的报告配置的对象。您可以尝试以下方式:

def print_report(self)
  ids = self.env['customer.payment'].search([('state','=','open')])       
  if not ids:  
    if not isinstance(ids, list):
      ids = [ids]        
  context = dict(self.env.context or {}, active_ids=ids, active_model=self._name)

  return {
    'type': 'ir.actions.report.xml',
    'report_name': 'account_report.payment_report',
    'context': context,
  }

Example 1

def print_report(self, cr, uid, ids, context=None):
    active_id = context.get('active_id', [])
    datas = {'ids' : [active_id]}
    return {
        'type': 'ir.actions.report.xml',
        'report_name': 'pos.receipt',
        'datas': datas,
    }

答案 1 :(得分:1)

@api.multi
def print_report(self):
return self.env['report'].get_action(self, 'account_report.payment_report')