Skip to Content
Menu
This question has been flagged
1 Reply
1674 Views
@ api.onchange ( 'duration' ) 
def compute_status ( self ): 
if self .duration! = 0 :
for record in self .subscription:
record.write ({ 'subscription_months_calc' : record.duration + record.subscription_months_calc})
record. write ({ 'subscription_expiry_date' : record.subscription_registration_date + relativedelta (
months = record.subscription_months_calc)})


I have wrote the above function to make change into my another custom module. It is not changing the value nor it is giving an error. Kindly help me.

Avatar
Discard
Best Answer

Hi,

Please try his code

from odoo.fields import Date
from dateutil.relativedelta import relativedelta

@api.onchange('duration')
def compute_status(self):
if self.duration: 
   
for record in self.subscription:
       
record.write({'subscription_months_calc': record.duration + record.subscription_months_calc})
       
       
if record.subscription_registration_date:
            expiry_date = Date.from_string(
record.subscription_registration_date) + relativedelta(
                months=
record.subscription_months_calc)
           
record.write({'subscription_expiry_date': Date.to_string(expiry_date)})

Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
640
1
Apr 23
2043
7
Feb 23
8397
0
Sep 22
1350
1
Jul 22
884