Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2712 Widoki

I'm using Odoo 17 and I added a custom button on the project form view that displays wizard view to recap some informations and then export them inside a PDF report. Everything works fine except one thing : I can't change the name of the PDF. 

When I don't generate the report through the native print button instead, in the project model, the field   works fine. But through a custom button, it doesn't, it keeps using the field  .

Any idea about how to change report file name through wizard?

Thanks a lot

Here is my code :


   
       My Custom PDF
       report.custom_module.my_report
       qweb-pdf
       custom_module.my_report
       custom_module.my_report
       'the name of the file'
       report
   
/
Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thanks a lot for your answer. Unfortunatly, I still have the issue. The report file name use the string instead of print_report_name. It drives me mad ! 

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Arthur LEHAVRE ,


To change the name of the PDF generated by your custom button in Odoo 17, you need to ensure that the filename is dynamically set in your report action. Here’s a step-by-step guide on how to achieve this:


1. Define the report action:

//Code 1 in Comment//


2. Modify the wizard to generate the report:


Ensure your wizard calls the report action with the context needed to set the filename.

//Code 2 in Comment//


3. Adjust the button in the form view to call the wizard:

   

Make sure your button in the project form view calls the wizard action.

//Code 3 in Comment//


4. Ensure the wizard action is defined:

   

Make sure your wizard action is correctly defined in the XML file.

//Code 4 in Comment//


Hope this helps.

   

If you need any help in customisation feel free to contact us.

       

Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

Awatar
Odrzuć

Code 1:

<report
id="my_custom_report"
model="project.project"
string="My Custom PDF"
report_type="qweb-pdf"
name="custom_module.my_report"
file="custom_module.my_report"
print_report_name="(object.name or 'report_name') + '_Report'"
/>

Code 2 :

class MyCustomWizard(models. TransientModel):
_name = 'custom_module.my_custom_wizard'
_description = 'Custom Wizard for PDF Report'

def action_generate_report(self):
return self.env.ref('custom_module.my_custom_report').report_action(self)

Code 3:

<record id="view_project_form" model="ir.ui.view">
<field name="name">project.form</field>
<field name="model">project.project</field>
<field name="arch" type="xml">
<form string="Project">
<!-- Your existing form view structure -->
<button name="action_generate_report" type="object" string="Generate PDF" class="btn-primary"/>
<!-- Your existing form view structure -->
</form>
</field>
</record>

Code 4:

<record id="action_my_custom_wizard" model="ir.actions.act_window">
<field name="name">My Custom Wizard</field>
<field name="res_model">custom_module.my_custom_wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

Powiązane posty Odpowiedzi Widoki Czynność
2
kwi 24
2630
4
paź 20
5569
1
mar 15
5248
1
kwi 24
31955
3
lut 24
12552