hi odooers
i want to print two pdf reports ( invoice, and delivery report) while clicking on single custom button in odoo 16 e
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
To print two existing reports (invoice and delivery report) with a single custom button in Odoo 16, you can create a new button in the user interface and define a server action to handle the logic of generating and printing the reports. Here's a step-by-step guide:
1. Create a Server Action:
Go to Settings and enable the Developer Mode.
Navigate to Technical -> Actions -> Server Actions.
Create a new server action:
Action Type: ir.actions.server
Name: Choose a name for your server action.
Model: Select the model you want to associate the server action with (e.g., Sale Order, Invoice, or any relevant model).
Execution Context: Current Record
2. Define the Python Code:
In the server action, you need to define Python code that will generate and print the reports. Below is a sample Python code that you can adapt:
python
# Sample Python Code for the server action
invoice_ids = record.invoice_ids.filtered(lambda inv: inv.state == 'posted')
delivery_ids = record.picking_ids.filtered(lambda picking: picking.state == 'done')
# Generate and print the Invoice report
invoice_report = record.env.ref('account.report_invoice').render_qweb_pdf(invoice_ids.ids)
# Save or attach the invoice_report PDF as needed
# Generate and print the Delivery Order report
delivery_report = record.env.ref('stock.report_deliveryorder').render_qweb_pdf(delivery_ids.ids)
# Save or attach the delivery_report PDF as needed
In this code, record represents the current record for which the button is clicked. Adjust the code according to your specific model and logic.
3. Create a New Button:
Navigate to the model for which you want to add the button (e.g., Sale Order, Invoice, or any relevant model).
In the model's form view, add a new button to trigger the server action.
xml
Replace your_server_action_name with the actual name of your server action.
4. Adjust Security Settings:
Make sure that the user or user group has the necessary access rights to execute the server action and access the reports.
5. Test:
Test the button by navigating to a record of the associated model and clicking on the newly created button. Verify that both reports (invoice and delivery) are generated and printed as expected.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Dec 23
|
992 | ||
|
1
Oct 24
|
2813 | ||
|
1
Apr 24
|
711 | ||
|
2
Feb 24
|
1396 | ||
|
0
Dec 23
|
1249 |