İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
1573 Görünümler

I created a module to customize pos receipt template. But when other module is installed after my module which also changes the same thing i change my changes get override. I want to know if there is an attribute that i can add so my module would load last. I tried using priority="100" but that didnt work.

?xml version="1.0" encoding="UTF-8"?>

templates id="template" xml:space="preserve">

​t t-name="pos_receipt.OrderReceipt" t-inherit="point_of_sale.OrderReceipt" priority="1" t- ​inherit-mode="extension"> 

​xpath expr="//p[@t-if='props.data.isRestaurant']" position="replace"> 

​​p t-if="props.data.isRestaurant">

 

​/xpath> 

​xpath expr="//p[@t-else='']" position="replace"> 

​p t-else="">

 

​/xpath> 

​/t>

​t t-name="pos_receipt.ReceiptHeader" t-inherit="point_of_sale.ReceiptHeader" t-inherit- ​mode="extension"> 

​xpath expr="//img" position="replace"> 

​img/> 

​/xpath> 

​/t>

/templates>

Avatar
Vazgeç
En İyi Yanıt

To ensure your module's changes take precedence and are loaded after other modules, you can use the following strategies:

1. Use the depends Attribute:

  • Ensure that your module explicitly depends on the other modules you want to override. This forces your module to load after the modules it depends on.
  • In your __manifest__.py file, add the other modules to the depends list:
pythonCopy code{
    'name': 'Your Module',
    'depends': ['point_of_sale', 'other_module_name'],
    # other attributes
}

2. Use sequence in data Section:

  • In your __manifest__.py, ensure your XML file is loaded after others by specifying the sequence in the data section.
  • For example:
pythonCopy code{
    'name': 'Your Module',
    'depends': ['point_of_sale'],
    'data': [
        'views/your_template.xml',
    ],
    'sequence': 150,  # Higher sequence ensures it loads later
}

3. Use the noupdate="1" Flag:

  • You can use the noupdate="1" attribute in your XML to prevent your changes from being overridden by subsequent updates or other modules.
xmlCopy code
    

4. Leverage the depends in Odoo 15+ (Advanced):

  • For Odoo 15 and later, there’s a more advanced mechanism where you can use the _order attribute in the class definition to ensure your code execution happens after other similar modules.
  • However, this is more applicable for Python code rather than XML template overrides.

Example of Updated XML:

Here's an updated XML structure with priority="100" as well as ensuring noupdate="1" and checking the sequence in the manifest:

xmlCopy code
    
         
             
                

Final Checks:

  • Ensure your module's sequence and dependencies are correctly set in __manifest__.py.
  • If the issue persists, verify that no other module is loaded afterward with a higher sequence or overrides in its own way that could conflict with your changes.

Avatar
Vazgeç
Üretici

The code parts are not visible. Can you fix that so I can see full solution )

<odoo>
<template id="template" xml:space="preserve" noupdate="1">
<t t-name="pos_receipt.OrderReceipt" t-inherit="point_of_sale.OrderReceipt" priority="100" t-inherit-mode="extension">
<xpath expr="//p[@t-if='props.data.isRestaurant']" position="replace">
<p t-if="props.data.isRestaurant">
<!-- Your customized content -->
</p>
</xpath>
<xpath expr="//p[@t-else='']" position="replace">
<p t-else="">
<!-- Your customized content -->
</p>
</xpath>
</t>

<t t-name="pos_receipt.ReceiptHeader" t-inherit="point_of_sale.ReceiptHeader" t-inherit-mode="extension">
<xpath expr="//img" position="replace">
<img/>
</xpath>
</t>
</template>
</odoo>

Üretici

Adding sequence to manifest worked for me. Thanks

En İyi Yanıt

Hi,

You can try this approach. Instead of replacing the image, which might affect other modules using this class, it’s better to hide it. This way, the image remains intact for other uses, and your changes will only apply where needed.

Avatar
Vazgeç
Üretici

I appreciate the corrections but that wasnt my request. The problem was written in my post. My code works quite right the problem is that if for example i create another module and install it after this module which change the same template tags my code gets overwritten. I want to know if there is a way to make my code not be overwritten.

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Tem 18
3753
2
Mar 15
6065
5
Nis 23
33675
0
Haz 25
467
0
Mar 24
1308