Skip to Content
Menu
This question has been flagged
2 Replies
4593 Views

Hello, can someone help me, I want to generate a pdf from a wizard, I already have the template and the xml action, but when I call the wizard method to generate the pdf, it generates it blank without any information, currently what the wizard does is generate a ledger modified to another tree view of another model, so I want the option to also generate it in pdf with the same information of the method that it generates when generating the other view:

This is the method that generates another view of another model with the info:

def confirm_export(self):
move_lines = self.env['account.move.line'].search([
('account_id', 'in', self.account_ids.ids),
('date', '>=', self.start_date),
('date', '<=', self.end_date),
('move_id.state', '=', 'posted'), # Filtrar movimientos publicados
])

ledger_view_records = defaultdict(lambda: {'debit_total': 0.0, 'credit_total': 0.0, 'balance_total': 0.0,
'balance_acumulado': 0.0})
for move_line in move_lines.sorted(key=lambda r: r.date):
key = (move_line.date, move_line.journal_id, move_line.account_id)
ledger_view_records[key]['account_id'] = move_line.account_id.id
ledger_view_records[key]['journal_id'] = move_line.journal_id.id
ledger_view_records[key]['date'] = move_line.date
ledger_view_records[key]['currency_id'] = move_line.currency_id.id
ledger_view_records[key]['debit_total'] += move_line.debit
ledger_view_records[key]['credit_total'] += move_line.credit
ledger_view_records[key]['balance_acumulado'] += move_line.cumulated_balance
ledger_view_records[key]['balance_total'] += move_line.balance

export_general_ledger_view = self.env['export.general.ledger.view']
created_records = export_general_ledger_view.create(list(ledger_view_records.values()))

# Abrir la vista después de guardar los datos
action = self.env.ref('general_ledger_sv.action_export_general_ledger_view').read()[0]
action['domain'] = [('id', 'in', created_records.ids)]
return action

This is the xml action and template id:

<record id="report_general_ledger" model="ir.actions.report">
<field name="name">Libro Mayor PDFfield>
<
field name="model">export.general.ledger.viewfield>
<
field name="report_type">qweb-pdffield>
<
field name="report_name">general_ledger_sv.report_general_ledger_sv_template_idfield>
<
field name="report_file">general_ledger_sv.report_general_ledger_sv_template_idfield>
<
field name="binding_model_id" ref="general_ledger_sv.model_export_general_ledger_view"/>
<
field name="binding_type">reportfield>
<
field name="binding_view_types">treefield>
record>

This is the current method to export to pdf:


def generate_pdf(self):
# Obtener los valores del modelo export.general.ledger.view
ledger_view = self.env['export.general.ledger.view'].browse(self._context.get('active_ids', []))

data = {
'model_id': ledger_view.id,
'date': ledger_view.date,
'account_id': ledger_view.account_id,
'journal_id': ledger_view.journal_id,
'debit_total': ledger_view.debit_total,
'credit_total': ledger_view.credit_total,
'balance_total': ledger_view.balance_total,
'balance_acumulado': ledger_view.balance_acumulado,
'currency_id': ledger_view.currency_id,
}

docids = ledger_view.ids
return self.env.ref('general_ledger_sv.report_general_ledger').report_action(docids=docids, data=data)
Avatar
Discard
Best Answer

Hi,

When you are printing the data from wizard the data may not have been passed to the report and thus it fails to render the values in the template.

You can check the values, you are returning inside the variable docids and data from wizard and ensure the needed values are passed.

Also you can check out this video explaining the same:  https://www.youtube.com/watch?v=3UJ8UfP48B4


Thanks

Avatar
Discard
Best Answer

Hi,
In certain conditions, we need to print the report from a button or wizard. In that condition, we use the print button inside the wizard or form to call the report action.

Please refer to the blog topic How to Create a PDF Report in Odoo :https://www.cybrosys.com/blog/how-to-create-a-pdf-report-in-odoo-15

Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 24
31221
1
Apr 25
347
0
Mar 25
393
2
Jan 25
577
2
Jul 24
1849