Skip to Content
Menu
This question has been flagged
2 Replies
781 Views

Hello everybody


I need to add python code for my field:

I want have a toggle boolean, true if today - "warranty date"


can you help me?

thanks

Avatar
Discard
Author Best Answer

sorry, but my message was truncated.

I'd like a boolean_toggle field that is set to true if warranty date - current date is less than 2 years.

Avatar
Discard

i have modified the answer please check to see if work or not

Best Answer

You can try something like this:

1. define your field:

from odoo.tools import relativedelta

toggle_field = fields.Boolean(string="Your Toggle field", compute="_compute_toggle_field", store=True)

2. Create a compute method for your field

@api.depends("warranty_date")

def _compute_toggle_field(self):

​for r in self:

​if r.warranty_date and (r.warranty_date - fields.Date.today()

​r.toggle_field = True

​else:

​r.toggle_field = False


3. Finally bring your field to the xml file


Hope this help

Avatar
Discard