Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5674 Vizualizări

i will make condition end_date auto fill based selection field and start_date field

but have some error like this

File "...\Python\Python35\lib\site-packages\dateutil\relativedelta.py", line 393, in __radd__
    return self.__add__(other)
  File "...\Python\Python35\lib\site-packages\dateutil\relativedelta.py", line 351, in __add__
    raise TypeError("unsupported type for add operation")
TypeError: unsupported type for add operation

my py

from odoo import api, fields, models
from datetime import datetime, date, time
from dateutil.relativedelta import relativedelta
class LicenseID(models.Model):
_name = 'license.vehicle'
_inherit = 'ir.attachment'

name = fields.Selection([
('BPKB', 'BPKB'),
('STNK', 'STNK'),
('KIR', 'KIR'),
('UJI_EMISI', 'UJI EMISI'),
('KIU/SIPA/KKPKB', 'KIU/SIPA/KKPKB'),
('IBM', 'IBM'),
('STCK', 'STCK'),
('TNKB', 'TNKB')],
string='Document Name')
start_date = fields.Date(string='Start Date')
end_date = fields.Date(string='End Date')

@api.onchange('name', 'start_date')
def _change_date(self):
if self.name == 'STNK':
self.end_date = self.start_date + relativedelta(years=5)
self.end_date.strftime('%Y-%m-%d'),

can help me master ??



Imagine profil
Abandonează
Cel mai bun răspuns

Hello,

you should convert your start date (string type) into date type. (datetime.strptime)

For ref. see below code.

1) import libraries

from odoo.tools import DEFAULT_SERVER_DATE_FORMAT

from datetime import datetime


2) replace your method with this method in your code

                @api.onchange('name', 'start_date')

                def _change_date(self):

                    if self.name == 'STNK' and self.start_date:

                        date_start = datetime.strptime(self.start_date, DEFAULT_SERVER_DATE_FORMAT)

                        self.end_date = date_start + relativedelta(years=5)


Thanks,

Dipak


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
ian. 20
4725
1
aug. 19
4097
0
aug. 19
4399
1
iun. 18
5058
0
mai 15
4920