Skip to Content
Menu
This question has been flagged
1 Reply
5478 Views

hi wanted to convert Georgian datetime to iranian date  time  in the pdf reports

here is the code :

convert_jalaly.py :

import datetime
import pytz
import logging
_logger = logging.getLogger(__name__)
try:
import jdatetime
except (ImportError, IOError) as err:
_logger.debug(err)

def convert_jalali(original_date):
if original_date:
original_date_list = original_date.strftime('%Y-%m-%d %H:%M:%S')
original_date_t = datetime.datetime.strptime(str(original_date_list), '%Y-%m-%d %H:%M:%S')
jalali_date = jdatetime.date.fromgregorian(day=original_date_t.day, month=original_date_t.month, year=original_date_t.year)
return ' '.join((original_date_t.strftime(""),
jalali_date.strftime('%Y/%m/%d')))


def convert_jalali_wt(original_date):
if original_date:
iran = pytz.timezone("Asia/Tehran")
original_date_i = original_date.astimezone(iran)
original_date_list = original_date_i.strftime('%Y-%m-%d %H:%M:%S')
original_date_t = datetime.datetime.strptime(str(original_date_list), '%Y-%m-%d %H:%M:%S')
jalali_date = jdatetime.date.fromgregorian(day=original_date_t.day, month=original_date_t.month, year=original_date_t.year)
return ' '.join((original_date_t.strftime("%H:%M:%S"),
jalali_date.strftime('%Y/%m/%d')))
and the seccond part of the code :



from odoo.addons.base_jalali_convert.convert_jalali import convert_jalali, convert_jalali_wt
from odoo import models, api


class SaleOrder(models.Model):
_inherit = 'sale.order'


def convert_jalali(self, obj):
self.ensure_one()
return convert_jalali_wt(obj.date_order)

def convert_jalali_q(self, obj):
self.ensure_one()
return convert_jalali(obj.date_order)

def convert_jalali_val(self, obj):
self.ensure_one()
return convert_jalali(obj.validity_date)
but when i try to create an pdf report in sales i face following error:

any help would be appreciated .

Traceback (most recent call last):
  File "/opt/odoo/odoo11/odoo/addons/base/ir/ir_qweb/qweb.py", line 347, in _compiled_fn
    return compiled(self, append, new, options, log)
  File "", line 1, in template_sale_report_saleorder_document_87
  File "", line 2, in body_call_content_86
  File "/opt/odoo/odoo11-custom-addons/sale_jalali_date/model/sale_jalali_date_printout.py", line 13, in convert_jalali
    return convert_jalali_wt(obj.date_order)
  File "/opt/odoo/odoo11-custom-addons/base_jalali_convert/convert_jalali.py", line 24, in convert_jalali_wt
    original_date_i = original_date.astimezone(iran)
AttributeError: 'str' object has no attribute 'astimezone'

Avatar
Discard
Best Answer

The issue is original_date passed to convert_jalali_wt is string so you need to convert it to date and you can use strptime.


Avatar
Discard
Related Posts Replies Views Activity
4
Jun 24
606
2
Mar 24
777
0
Nov 22
1550
0
Sep 17
3984
0
Mar 15
2707