def format_date_tz(date, tz=None): if isinstance(date, str): date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S").replace(tzinfo=pytz.utc) if tz is None: tz = pytz.timezone(tools.detect_server_timezone()) f = tools.DEFAULT_SERVER_DATETIME_FORMAT return tools.server_to_local_timestamp(date, f, f, tz)
# GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import time from datetime import datetime, timedelta from osv import fields, osv from crm import crm from openerp import tools import pytz tzlocal = pytz.timezone(tools.detect_server_timezone()) AVAILABLE_STATES = [ ('draft', 'Черновик'), ('agreement', 'Согласование'), ('approval', 'Утверждение'), ('appointment', 'Назначение ответственного'), ('adoption_in_work', 'Принятие в работу'), ('in_the_work', 'В работу'), ('closed', 'Вакансия закрыта'), ('completion_agr', 'На доработку(Согласование)'), ('completion_app', 'На доработку(Утверждение)'), ('completion_adop', 'На доработку(Принятие в работу)'), ('cancel', 'Отменена') ]
def format_date_tz(date, tz=None): if isinstance(date, str): date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S").replace(tzinfo=pytz.utc) if tz is None: tz = pytz.timezone(tools.detect_server_timezone()) return tz.normalize(date).strftime('%Y-%m-%d %H:%M:%S')
def support(self, **kwargs): def dict_to_str(title, dictvar): ret = "\n\n%s" % title for field in dictvar: ret += "\n%s" % field return ret _TECHNICAL = ['show_info', 'view_from', 'view_callback'] # Only use for behavior, don't stock it _BLACKLIST = ['id', 'create_uid', 'create_date', 'write_uid', 'write_date', 'user_id', 'active'] # Allow in description _REQUIRED = ['mobile', 'customer_first_name', 'customer_second_name' ,'description'] # Could be improved including required from model post_file = [] # List of file to add to ir_attachment once we have the ID post_description = [] # Info to add after the message # Values field is initialized with defaults values = { 'user_id': SUPERUSER_ID, 'date': str(datetime.utcnow()), 'create_date_n': str(datetime.utcnow()), 'state':'new', 'claimcateg': 'comment', 'country_key':194, 'delay_open_notified':False, 'delay_assigned_notified':False, 'delay_solved_notified':False, } for field_name, field_value in kwargs.items(): if hasattr(field_value, 'filename'): if field_name=="attachment": values[field_name] = base64.encodestring(field_value.read()) values["attachment_fname"]= field_value.filename elif field_name=="attachment2": values[field_name] = base64.encodestring(field_value.read()) values["attachment2_fname"]= field_value.filename elif field_name in request.registry['maw.claim']._fields and field_name not in _BLACKLIST: if field_name=="date": sys_tz = detect_server_timezone() utc_tz = pytz.timezone(sys_tz) ar_timezone = pytz.timezone('Asia/Riyadh') fmt = '%Y-%m-%dT%H:%M' naive = datetime.strptime(field_value, fmt) #utc_dt = utc_tz.localize(naive, is_dst=None) local_dt = ar_timezone.localize(naive, is_dst=None) utc_dt = local_dt.astimezone (utc_tz) if utc_dt: values[field_name]=str(utc_dt) else: values[field_name] = field_value else: values[field_name] = field_value elif field_name not in _TECHNICAL: # allow to add some free fields or blacklisted field like ID post_description.append("%s: %s" % (field_name, field_value)) if "name" not in kwargs and values.get("customer_first_name"): # if kwarg.name is empty, it's an error, we cannot copy the contact_name values["name"] = values.get("customer_first_name") # fields validation : Check that required field from model crm_lead exists error = set(field for field in _REQUIRED if not values.get(field)) if error: values = dict(values, error=error, kwargs=kwargs.items()) return request.website.render(kwargs.get("view_from", "mawgif_support.mawgif_support"), values) # description is required, so it is always already initialized if post_description: values['description'] += dict_to_str(_("Custom Fields: "), post_description) if kwargs.get("show_info"): post_description = [] environ = request.httprequest.headers.environ post_description.append("%s: %s" % ("IP", environ.get("REMOTE_ADDR"))) post_description.append("%s: %s" % ("USER_AGENT", environ.get("HTTP_USER_AGENT"))) post_description.append("%s: %s" % ("ACCEPT_LANGUAGE", environ.get("HTTP_ACCEPT_LANGUAGE"))) post_description.append("%s: %s" % ("REFERER", environ.get("HTTP_REFERER"))) values['description'] += dict_to_str(_("Environ Fields: "), post_description) claim_id = self.create_support_ticket(request, dict(values), kwargs) values.update(claim_id=claim_id) return self.get_support_response(values, kwargs)
def support(self, **kwargs): def dict_to_str(title, dictvar): ret = "\n\n%s" % title for field in dictvar: ret += "\n%s" % field return ret _TECHNICAL = ['show_info', 'view_from', 'view_callback'] # Only use for behavior, don't stock it _BLACKLIST = [ 'id', 'create_uid', 'create_date', 'write_uid', 'write_date', 'user_id', 'active' ] # Allow in description _REQUIRED = [ 'mobile', 'customer_first_name', 'customer_second_name', 'description' ] # Could be improved including required from model post_file = [ ] # List of file to add to ir_attachment once we have the ID post_description = [] # Info to add after the message # Values field is initialized with defaults values = { 'user_id': SUPERUSER_ID, 'date': str(datetime.utcnow()), 'create_date_n': str(datetime.utcnow()), 'state': 'new', 'claimcateg': 'comment', 'country_key': 194, 'delay_open_notified': False, 'delay_assigned_notified': False, 'delay_solved_notified': False, } for field_name, field_value in kwargs.items(): if hasattr(field_value, 'filename'): if field_name == "attachment": values[field_name] = base64.encodestring( field_value.read()) values["attachment_fname"] = field_value.filename elif field_name == "attachment2": values[field_name] = base64.encodestring( field_value.read()) values["attachment2_fname"] = field_value.filename elif field_name in request.registry[ 'maw.claim']._fields and field_name not in _BLACKLIST: if field_name == "date": sys_tz = detect_server_timezone() utc_tz = pytz.timezone(sys_tz) ar_timezone = pytz.timezone('Asia/Riyadh') fmt = '%Y-%m-%dT%H:%M' naive = datetime.strptime(field_value, fmt) #utc_dt = utc_tz.localize(naive, is_dst=None) local_dt = ar_timezone.localize(naive, is_dst=None) utc_dt = local_dt.astimezone(utc_tz) if utc_dt: values[field_name] = str(utc_dt) else: values[field_name] = field_value else: values[field_name] = field_value elif field_name not in _TECHNICAL: # allow to add some free fields or blacklisted field like ID post_description.append("%s: %s" % (field_name, field_value)) if "name" not in kwargs and values.get( "customer_first_name" ): # if kwarg.name is empty, it's an error, we cannot copy the contact_name values["name"] = values.get("customer_first_name") # fields validation : Check that required field from model crm_lead exists error = set(field for field in _REQUIRED if not values.get(field)) if error: values = dict(values, error=error, kwargs=kwargs.items()) return request.website.render( kwargs.get("view_from", "mawgif_support.mawgif_support"), values) # description is required, so it is always already initialized if post_description: values['description'] += dict_to_str(_("Custom Fields: "), post_description) if kwargs.get("show_info"): post_description = [] environ = request.httprequest.headers.environ post_description.append("%s: %s" % ("IP", environ.get("REMOTE_ADDR"))) post_description.append( "%s: %s" % ("USER_AGENT", environ.get("HTTP_USER_AGENT"))) post_description.append( "%s: %s" % ("ACCEPT_LANGUAGE", environ.get("HTTP_ACCEPT_LANGUAGE"))) post_description.append("%s: %s" % ("REFERER", environ.get("HTTP_REFERER"))) values['description'] += dict_to_str(_("Environ Fields: "), post_description) claim_id = self.create_support_ticket(request, dict(values), kwargs) values.update(claim_id=claim_id) return self.get_support_response(values, kwargs)