Atul Jain
Atul Jain

Reputation: 1055

how to print single partner ledger report from account reporting in openerp

I am using this function that prints all company reports:

def _print_report(self, cr, uid, ids, data, context=None):
        if context is None:
            context = {}
           data = self.pre_print_report(cr, uid, ids, data, context=context)
        data['form'].update(self.read(cr, uid, ids, ['initial_balance', 'filter',     'page_split', 'amount_currency'])[0])
        if data['form']['page_split']:
            return {
              'type': 'ir.actions.report.xml',
              'report_name': 'account.third_party_ledger',
              'datas': data,
        }
         return {
                'type': 'ir.actions.report.xml',
                'report_name': 'account.third_party_ledger_other',
                'datas': data,
        }

How can I adapt this to print a single company report?

Upvotes: 1

Views: 479

Answers (1)

adekock11
adekock11

Reputation: 614

I added a button to my res.partner.form which calls print_partner_ledger:

<button type="object" name="print_partner_ledger" string="Print Partner Ledger" />

Then I added this function to the res.partner object:

class res_partner(osv.Model):
_inherit = 'res.partner'

def print_partner_ledger(self, cr, uid, ids, context=None):
    # select all journals
    journal_obj = self.pool.get('account.journal')
    journal_ids = journal_obj.search(cr, uid, [], context=context)

    # the data variable is normally generated by the wizard but in our case we generate it manually
    data = {
        u'form': {
            u'amount_currency': False,
            u'chart_account_id': False, #print all chart accounts
            u'date_from': False,
            u'date_to': False,
            u'filter': u'filter_no',
            u'fiscalyear_id': False,
            u'id': 1, #don't know what this id is for
            u'initial_balance': False,
            u'journal_ids': journal_ids, #print all journals
            u'page_split': False,
            u'period_from': False,
            u'period_to': False,
            u'periods': [],
            u'result_selection': u'customer',
            u'target_move': u'posted',
            u'used_context': {
                            u'chart_account_id': False, #print all chart accounts
                            u'journal_ids': journal_ids, #print all journal
                            u'lang': u'en_US',
                            u'state': u'posted'}
            },
            u'ids': ids, #partner id
            u'model': u'res.partner'
    }

    return {
            'type': 'ir.actions.report.xml',
            'report_name': 'account.third_party_ledger_other',
            'datas': data,
    }

Spent hours on this, but finally got it working. I also made a module which installs the button on the res.partner form. Let me know if you want it

Upvotes: 3

Related Questions