def area_request(request): if request.is_ajax() and request.method == 'POST': country = request.POST.get('country', {}) areas = sorted(country_timezones.get(country, [])) response = json.dumps(areas) return HttpResponse(response, mimetype="application/json")
def country_name_to_timezone(self, network: str, value: str = None) -> str: if value == "Unknown Country": return "" try: pytz.timezone(value) return value except pytz.exceptions.UnknownTimeZoneError: for src in ("name_official", "name_short", "regex", "ISO2", "ISO3"): code = self.country_converter.convert(value, to="ISO2", src=src) if code and code != "not found": break else: logger.warning( f"Did not find timezone for {network} from value {value}, returning empty!" ) return "" try: result = country_timezones.get(code, "")[0] except Exception as error: logger.debug(traceback.format_exc()) logger.warning( f"Error parsing timezone for {network} from value {value} with {error}, returning empty" ) result = "" return result
def _initialize_db(id, db_name, demo, lang, user_password, login='******', country_code=None, phone=None): try: db = odoo.sql_db.db_connect(db_name) with closing(db.cursor()) as cr: # TODO this should be removed as it is done by Registry.new(). odoo.modules.db.initialize(cr) odoo.tools.config['load_language'] = lang cr.commit() registry = odoo.modules.registry.Registry.new(db_name, demo, None, update_module=True) with closing(db.cursor()) as cr: env = odoo.api.Environment(cr, SUPERUSER_ID, {}) if lang: modules = env['ir.module.module'].search([('state', '=', 'installed')]) modules._update_translations(lang) if country_code: country = env['res.country'].search([('code', 'ilike', country_code)])[0] env['res.company'].browse(1).write({ 'country_id': country_code and country.id, 'currency_id': country_code and country.currency_id.id }) if len(country_timezones.get(country_code, [])) == 1: users = env['res.users'].search([]) users.write({'tz': country_timezones[country_code][0]}) if phone: env['res.company'].browse(1).write({'phone': phone}) if '@' in login: env['res.company'].browse(1).write({'email': login}) # update admin's password and lang and login values = {'password': user_password, 'lang': lang} if login: values['login'] = login emails = odoo.tools.email_split(login) if emails: values['email'] = emails[0] env.ref('base.user_admin').write(values) cr.execute('SELECT login, password FROM res_users ORDER BY login') cr.commit() except Exception as e: _logger.exception('CREATE DATABASE failed:')
def get_zones(): for country_code in SUPPORTED_COUNTRIES: timezones = country_timezones.get(country_code, []) for timezone in timezones: zone_name = f'{country_code}-{_timezone_name(timezone)}'.lower() # IMp is the AM/PM time format. We set it by default by choice. zone_format = f"{timezone}|'vm-received' q 'digits/at' IMp" yield {'name': zone_name, 'format': zone_format}
def check_timezone_count_in_country(self): self.timezone_list = country_timezones.get(self.iso, None) if not self.timezone_list: return False if self.location_timezone in self.timezone_list: tz = timezone(self.location_timezone) local_datetime_now = datetime.now(tz).replace(tzinfo=None) is_current_location_service_allowed = CountryMaster.objects.filter( id=self.country_id, start_date__lte=local_datetime_now, end_date__gte=local_datetime_now) if is_current_location_service_allowed: return True return False if self.country_timezone_incorrect_get_default(): return True return False
def _initialize_db(id, db_name, demo, lang, user_password, login='******', country_code=None, phone=None): try: db = odoo.sql_db.db_connect(db_name) with closing(db.cursor()) as cr: # TODO this should be removed as it is done by Registry.new(). odoo.modules.db.initialize(cr) odoo.tools.config['load_language'] = lang cr.commit() registry = odoo.modules.registry.Registry.new(db_name, demo, None, update_module=True) with closing(db.cursor()) as cr: env = odoo.api.Environment(cr, SUPERUSER_ID, {}) if lang: modules = env['ir.module.module'].search([('state', '=', 'installed')]) modules._update_translations(lang) if country_code: country = env['res.country'].search([('code', 'ilike', country_code)])[0] env['res.company'].browse(1).write({'country_id': country_code and country.id, 'currency_id': country_code and country.currency_id.id}) if len(country_timezones.get(country_code, [])) == 1: users = env['res.users'].search([]) users.write({'tz': country_timezones[country_code][0]}) if phone: env['res.company'].browse(1).write({'phone': phone}) if '@' in login: env['res.company'].browse(1).write({'email': login}) # update admin's password and lang and login values = {'password': user_password, 'lang': lang} if login: values['login'] = login emails = odoo.tools.email_split(login) if emails: values['email'] = emails[0] env.ref('base.user_admin').write(values) cr.execute('SELECT login, password FROM res_users ORDER BY login') cr.commit() except Exception as e: _logger.exception('CREATE DATABASE failed:')
def transform(self, record: dict) -> dict: """Transform data payload from tsv file to Order payload.""" record = Objectify(record) project = self.project order_id = uuid.uuid4() number_required_assets = record._get('number_required_assets', 10) # parse first and last name names = record.full_name.split(' ') first_name = names[0] if len(names) > 1: last_name = ' '.join(names[0:]) else: last_name = '' # parse country code based on the country name country = pycountry.countries.get(name=record.country.strip(' ')) if not country: print(f'Country not found {record.country}') country = country.alpha_2 if country else project.country formatted_address = f'{record.address}, {record.district}, {record.locality}, ' \ f'{record.postal_code}, {project.country}' new_data = { 'id': order_id, 'project_id': project.id, 'asset_types': ['Image'], 'category': 'accommodation', 'description': '', 'title': record.title, 'requirements': '', 'current_type': 'order', 'state': 'accepted', 'number_required_assets': number_required_assets, 'source': 'briefy', 'customer_id': project.customer_id, 'customer_order_id': record.customer_order_id, 'price': 10000, # TODO: use from project if exists 'delivery': { 'gdrive': record._get('download_link', '') }, 'price_currency': 'EUR', # TODO: use google maps api to get the geohash 'location': { 'id': uuid.uuid4(), 'order_id': order_id, 'state': 'created', 'locality': record.locality, 'country': country, 'email': record.email, 'formatted_address': formatted_address, 'coordinates': [0, 0], 'additional_phone': None, 'timezone': country_timezones.get(country, [project.timezone])[0], 'first_name': first_name, 'last_name': last_name, 'mobile': record.mobile, 'info': { 'additional_info': '', 'province': record.locality, 'locality': record.locality, 'sublocality': record.district, 'route': record.address, 'street_number': '', 'country': project.country, 'postal_code': record.postal_code } }, } return new_data