4
votes

How to print the list of customer.payment records, which state are in open using wizard. Here is my module. I am using 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'

Here is function sample, hope you get what I am trying to do. Account_report is module name and payment_report is a report which print only one record using print button.

@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
@Ommed Totatkhel Do you resolve problem?user_odoo

2 Answers

2
votes

The function must return an object with the report configuration to print. You can try something like:

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
votes
@api.multi
def print_report(self):
return self.env['report'].get_action(self, 'account_report.payment_report')