コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
3077 ビュー

Hello together,

Can someone explain to me the best way to overwrite a field that has already been overwritten in another module.


In my specific case it is about the helpdesk.


There is a field sale_line_id from the model helpdesk.ticket. The field is overwritten in a module helpdesk_sale_timesheet, which inherits from helpdesk.ticket.


If I now try to overwrite it in my own module that inherits helpdesk.ticket, it will first go through my changes in my own module and then overwrite the field from helpdesk_sale_timesheet again.


Is there any way to add something like a priority?

What is the best solution for my problem?


My goal is to customize the domain of the overwritten field.

Maybe there is another way.


Thanks in advance 

André

アバター
破棄
著作者 最善の回答

Hello,

thanks for your answer. I tried this but the problem is the same. But i found i different solution for this:

Before:

'depends': ['web','base','videc_menu',helpdesk','helpdesk_sale_timesheet'],

After:

'depends': ['web','base','videc_menu','helpdesk_sale_timesheet'], 

This works fine now :)

アバター
破棄
最善の回答

Hi,

In Odoo, when multiple modules are modifying the same field, the order of inheritance and execution matters. In your case, you want to customize the domain of the sale_line_id field in the helpdesk.ticket model, which has already been modified by the helpdesk_sale_timesheet module.

To achieve your goal, you can use a technique called field re-declaration. This technique allows you to redefine a field in a way that incorporates changes from other modules while adding your own modifications. Here's how you can do it:

  1. Create a new module or use an existing one.
  2. In your module, inherit the helpdesk.ticket model.
  3. Redefine the sale_line_id field, including the changes you want to make to the domain.

Here's an example of how your Python code might look:

from odoo import models, fields

class HelpdeskTicketInherit(models.Model):
    _inherit = 'helpdesk.ticket'

    # Redefine the sale_line_id field with your custom domain
    sale_line_id = fields.Many2one(domain="[('your_custom_domain_here')]")

By doing this, your module's changes to the sale_line_id field will take precedence over those made by the helpdesk_sale_timesheet module, and your custom domain will be applied.

Remember to replace 'your_custom_domain_here' with the actual domain expression you want to use.

This approach ensures that your changes are applied without directly modifying the field defined in the helpdesk_sale_timesheet module, thus avoiding conflicts and maintaining compatibility with other modules.


Hope it helps

アバター
破棄