تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1953 أدوات العرض
@ 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.

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
نوفمبر 24
1174
1
أبريل 23
2525
7
فبراير 23
9027
0
سبتمبر 22
1691
1
يوليو 22
1412