def ws_connect(message): """ :param message: """ Menu.add_listener(message.reply_channel) message.reply_channel.send({'accept': True})
def choices(self, system, edit_menu=False): if edit_menu is False: if system.manager.options_item.menu is not None: choices = [(system.manager.options_item.menu.id, system.manager.options_item.menu)] else: manager = BaseManager() manager.model = Menu() manager.order = 'parent' manager.fetchOptions = { 'site': system.portal.activeSite.id, 'active': system.requester.rData['selectedactivity'], 'activesite': system.requester.rData['activesite'] } manager.fetch_items(for_select=True) items = manager.get_items_as_tree(system.requester.request, for_select=True) choices = [] if items is not None: for il in items: if il is not None: if il.name is not None: prefix = '' for i in range(0, il.depth): prefix = prefix + " " il.name = (prefix + il.name) choices.append((il.id, mark_safe(il.name))) else: choices = [(system.manager.item.id, system.manager.item)] self.fields['menu'].choices = choices
def __init__(self, request, *args, **kwargs): super(SystemObject, self).__init__(request, *args, **kwargs) self.manager = AdminManager() self.manager.fetchOptions = { 'site': self.portal.activeSite.id, 'active': self.requester.rData['selectedactivity'], 'activesite': self.requester.rData['activesite'] } self.urls.add = 'core.view.menu_admin.add_item' self.urls.edit = 'core.view.menu_admin.edit_item' self.urls.show_items = 'core.view.menu_admin.show_items' self.manager.model = Menu() self.manager.modelLanguage = None self.manager.form_class = AdmItemForm().__class__ self.manager.language_form_class = None self.manager.order = 'date' self.manager.debugger.filename = 'menu_admin.py' self.manager.moduleName = '__adm_Menu__' self.data.update( {'filter_activity': reverse('core.view.menu_admin.show_items')}) self.data.update({ 'savebutton': 1, 'saveaddbutton': 1, 'copybutton': 1, 'addbutton': 1 })
def crud_get_menu(odoo: OdooRPC, domain: List = [], offset: int = 0, limit: int = 20) -> List[Menu]: menu: List[Menu] = [] result = odoo.search_read(MODEL_NAME, domain, [], offset, limit) for row in result: menu.append(Menu(**row)) return menu
def install_x_telegram_user_menu(): x_telegram_user_action = crud_search_action_window( odoo, [["name", "=", "Telegram Users"]])[0] x_net_city_menu = crud_search_menu(odoo, [["name", "=", "NetCity"]])[0] x_telegram_user_menu = Menu( name="Telegram Users", action=f"ir.actions.act_window,{x_telegram_user_action}", parent_id=x_net_city_menu) crud_create_menu(odoo, x_telegram_user_menu)
def install_netcity_menu(): x_telegram_user_action = crud_search_action_window( odoo, [["name", "=", "Telegram Users"]])[0] image = load_image("assets/logo_fastapi.png") netcity_menu = Menu( name="NetCity", web_icon_data=image, action=f"ir.actions.act_window,{x_telegram_user_action}") crud_create_menu(odoo, netcity_menu)
def add_menu(request): reqdict = to_reqdict(request) menu_types = MenuDetail.objects.all() if request.method == 'GET': return render(request, 'add_menu.html', {"menu_types": menu_types}) if request.method == 'POST': try: menu = Menu() mtype = menu_types.get(id=reqdict.get('menu_type')) menu.name = reqdict.get('menu_name') menu.quantity = reqdict.get('quantity') menu.price = reqdict.get('price') menu.taste = reqdict.get('taste') menu.description = reqdict.get('description') menu.type = mtype menu.save() messages.success(request, f'Menu {menu.name} has been added') except Exception as e: messages.error(request, 'Failed to add Menu') print(e) return render(request, 'add_menu.html', {"menu_types": menu_types})
def install_x_rent_house_menu(): x_rent_house_action = crud_search_action_window( odoo, [["name", "=", "Casas de renta"]])[0] x_net_city_menu = crud_search_menu(odoo, [["name", "=", "NetCity"]])[0] x_rent_house_menu = Menu( name="Casas de renta", action=f"ir.actions.act_window,{x_rent_house_action}", parent_id=x_net_city_menu, ) crud_create_menu(odoo, x_rent_house_menu)
def install_x_app_release_menu(): x_app_release_action = crud_search_action_window( odoo, [["name", "=", "App Releases"]])[0] x_net_city_menu = crud_search_menu(odoo, [["name", "=", "NetCity"]])[0] x_app_release_menu = Menu( name="App Releases", action=f"ir.actions.act_window,{x_app_release_action}", parent_id=x_net_city_menu, ) crud_create_menu(odoo, x_app_release_menu)
def menu_create(request): """ :param request: :return: """ logger.debug('POST %s', str(request.POST)) data = None if 'data' not in request.POST else request.POST[ 'data'] # что создавать try: # пытаемся получить словарик из json строки, притом один единственный, # т.к. в пакетном режиме не работаем. object = json.loads(data)[0] except Exception as e: return HttpResponseServerError( "Deserialize json string (%s) error: %s" % (str(data), str(e))) new_menu = Menu() for key, value in object.items(): if key == 'parent_uuid' and hasattr(new_menu, 'parent'): try: # смотрим и подправляем родительскую ноду parent = None if value == 'root' else Menu.objects.get( uuid=value) setattr(new_menu, 'parent', parent) except Exception as e: return HttpResponseServerError( "Parent node (uuid: %s) read error: %s" % (str(key), str(e))) elif hasattr(new_menu, key): setattr(new_menu, key, value) try: new_menu.save() except Exception as e: return HttpResponseServerError("Save menu item error: %s" % str(e)) return JsonResponse({'success': True, 'msg': 'Menu create!'})
def handle(self, *args, **options): print("Deleting all entries in Menu table...") Menu.objects.all().delete() print("Deleted.") for item in self.sample_menu: print("Adding %s (%s)..." % (item[0], item[3])) Menu( name=item[0], price=item[1], description=item[2], course=item[3], category=item[4], allergy=item[5], calories=item[6], image=item[7], vegetarian=item[8], vegan=item[9], meat=item[10], stock=random.randrange(20, 31), cost=item[11], ).save() print("Sample menu added.")
def menu_read(request): """ Чтение меню :param request: :return: """ user = request.user # смотрим, что за пользователь is_superuser = user is not None and user.is_superuser # супер не супер group_set = None if not is_superuser: # обычный пользователь видит только в соответствии с группами try: # вытаскиваю его группы group_set = set( user.webface_user.groups.values_list('uuid', flat=True)) # группы except Exception as e: return HttpResponseServerError("User groups read error: %s" % str(e)) node = None if 'node' not in request.POST else request.POST[ 'node'] # какую ноду просят раскрыть node = None if node == 'root' else node # замена фантомной root на None try: menu_qs = Menu.objects.filter(parent=node) except Exception as e: return HttpResponseServerError("Read parent node (%s) error: %s" % (str(node), str(e))) try: # получить деревянные данные в линейном виде - списком data = Menu.get_lineal_data(menu_qs, is_superuser, group_set) except Exception as e: return HttpResponseServerError("Read menu items error: %s" % str(e)) # результат есть - возвращаем return JsonResponse({'success': True, 'data': data})
def choices(self, system, field='menu'): manager = BaseManager() manager.model = Menu() manager.order = 'parent' manager.fetchOptions = { 'site': system.portal.activeSite.id, 'active': system.requester.rData['selectedactivity'], 'activesite': system.requester.rData['activesite'] } manager.fetch_items(for_select=True) items = manager.get_items_as_tree(system.requester.request, for_select=True) choices = [] if items is not None: for il in items: prefix = '' for i in range(0,il.depth): prefix = prefix + " " il.name = (prefix + il.name) choices.append((il.id,mark_safe(il.name))) self.fields[field].choices = choices manager.model = MenuItem() manager.modelLanguage = MenuItemLanguage() manager.order = 'parent' manager.fetchOptions = { 'site': system.portal.activeSite.id, 'active': system.requester.rData['selectedactivity'], 'activesite': system.requester.rData['activesite'] } manager.fetch_items(for_select=True) items = manager.get_items_as_tree(system.requester.request, for_select=True) choices = [] if items is not None: manager.set_language(system.language.currentLanguage) for il in items: prefix = '' for i in range(0,il.depth): prefix = prefix + " " il.language.name = (prefix + il.language.name) choices.append((il.id,mark_safe(il.language.name))) self.fields['parent'].choices = choices
def crud_create_menu(odoo: OdooRPC, menu: Menu) -> int: result = odoo.create(MODEL_NAME, menu.dict()) return result
def ws_disconnect(message): """ :param message: """ Menu.discard_listener(message.reply_channel)