This question has been flagged

Hi, I need to create custom template for Quotations/Invoices and inheriting parts of it is not option - I need to inherit all of its contents and replace it with customised content. 

I'm working on template report_saleorder_document

I tried to do it like this:

In my custom module in folder report I created sale_order_report_inherited.xml in which I put this code (only upper part of it is in screenshot) - see screenshot here https://ibb.co/5xWFnGw

I added that file in manifest.py and added 'sale' in depends. When I try to change some text in this template nothing changes on quotation pdf - what am I doing wrong - how to inherit entire template? Thank you!

Avatar
Discard
Best Answer

Hi,

You can achieve this in two ways. Either you can inherit the report_saleorder_document and replace it from the < t t-call web.external_layout> using xpath.

<template id="custom_report_saleorder_document" inherit_id="sale.report_saleorder_document">


    <xpath expr="//t[@t-call='web.external_layout'" position="replace">


        <t t-call="web.externale_layout>


            ---- Your Codes----


        </t>


    </xpath>


</template>


Or, you can call your custom template where the report_saleorder_document is being called. For that, create a custom temlplate, and where t-call for report_saleorder_document is happening, replace it using xpath and call your newly created template.

Regards

Avatar
Discard
Best Answer

To inherit an entire template in Odoo, you need to create a new XML file with the same structure as the original template. Then, you can copy the contents of the original template into your new XML file and modify it as needed.

Here is an example of how you could inherit the report_saleorder_document template:

  1. Create a new XML file in your custom module, for example my_module/views/report_saleorder_document_inherited.xml
  2. In this new XML file, create a new template that extends the original report_saleorder_document template. This is done using the t-extend attribute:
id="report_saleorder_document_inherited" inherit_id="sale.report_saleorder_document">
    ...

  1. Inside this new template, you can now copy the entire contents of the original report_saleorder_document template and modify it as needed.

  2. In your module's __manifest__.py file, make sure to add the sale module to the depends list, as well as the new XML file you created to the data list:

'depends': ['sale'],
'data': [
    'views/report_saleorder_document_inherited.xml',
],
  1. Finally, you need to tell Odoo to use your new template instead of the original one. You can do this by adding a report_saleorder_document_inherited entry to the ir.actions.report.xml_id dictionary in your __manifest__.py file:
'ir.actions.report.xml_id': [
    ('report_saleorder_document', 'my_module.report_saleorder_document_inherited'),
],

After installing your module, the system should now use your custom template for quotations and invoices instead of the original one. Note that you may need to clear the cache and restart the server for the changes to take effect.

Avatar
Discard