diff --git a/text_commander/README.rst b/text_commander/README.rst new file mode 100644 index 000000000..7a99bad35 --- /dev/null +++ b/text_commander/README.rst @@ -0,0 +1,48 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +Text Commander +=============== +This module helps you to open models or single model record and create record +of a model through command palette. + +Configuration +============= +Install this module. Then use the hotkey ctrl + k. + +Company +======= +* `Cybrosys Techno Solutions `__ + +License +------- +General Public License, Version 3 (AGPL v3). +(http://www.gnu.org/licenses/agpl-3.0-standalone.html) + +Credits +======= +Developer: (V16) Ramees Jaman KT, contact: odoo@cybrosys.com, + +Contacts +======== +* Mail Contact : odoo@cybrosys.com +* Website : https://cybrosys.com + +Bug Tracker +=========== +Bugs are tracked on GitHub Issues. In case of trouble, please check there if +your issue has already been reported. + +Maintainer +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit `Our Website `__ + +Further information +=================== +HTML Description: ``__ diff --git a/text_commander/__init__.py b/text_commander/__init__.py new file mode 100644 index 000000000..5a836e1f8 --- /dev/null +++ b/text_commander/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Ramees Jaman KT (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +from . import models diff --git a/text_commander/__manifest__.py b/text_commander/__manifest__.py new file mode 100644 index 000000000..52f6087d5 --- /dev/null +++ b/text_commander/__manifest__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Ramees Jaman KT (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +{ + 'name': 'Text Commander', + 'version': '16.0.1.0.0', + 'category': 'Extra tools', + 'summary': 'Customized command palette ', + 'description': 'This module helps you to open models or single model ' + 'record and create record of a model through command ' + 'palette', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': 'https://www.cybrosys.com', + 'depends': ['base_setup'], + 'assets': { + "web.assets_backend": [ + '/text_commander/static/src/xml/model_command_item.xml', + '/text_commander/static/src/js/command_palette.js', + '/text_commander/static/src/js/model_providers.js', + ] + }, + 'images': [ + 'static/description/banner.png'], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/text_commander/doc/RELEASE_NOTES.md b/text_commander/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..a754a3ae2 --- /dev/null +++ b/text_commander/doc/RELEASE_NOTES.md @@ -0,0 +1,5 @@ +## Module +#### 23.11.2023 +#### Version 16.0.1.0.0 +#### ADD +- Initial commit for Text Commander diff --git a/text_commander/models/__init__.py b/text_commander/models/__init__.py new file mode 100644 index 000000000..59f3ce457 --- /dev/null +++ b/text_commander/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Ramees Jaman KT (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################## +from . import ir_model diff --git a/text_commander/models/ir_model.py b/text_commander/models/ir_model.py new file mode 100644 index 000000000..775e39e46 --- /dev/null +++ b/text_commander/models/ir_model.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2023-TODAY Cybrosys Technologies(). +# Author: Ramees Jaman KT (odoo@cybrosys.com) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +############################################################################# +from odoo import api, models + + +class IrModel(models.Model): + """ Class to check the model and get the record values as specified by + the user """ + _inherit = 'ir.model' + + @api.model + def check_model(self, data): + """ Check model from frontend""" + self.env.cr.execute("""select model,name from ir_model + where lower(name->>'en_US')=lower('%s') limit 1""" % data) + model = self.env.cr.dictfetchall() + return model + + @api.model + def get_records(self, data): + """ Function for fetching record from database""" + if data['regex'] == 1: + if self.env[data['model']].fields_get('name')['name']['translate']: + self.env.cr.execute( + """SELECT id FROM %s WHERE lower(name->>'en_US') + LIKE '%%%s%%'""" % ( + data['model'].replace('.', '_'), + data['record'].lower())) + record = [d['id'] for d in self.env.cr.dictfetchall()] + return record + else: + self.env.cr.execute( + """SELECT id FROM %s WHERE lower(name) LIKE '%%%s%%'""" % ( + data['model'].replace('.', '_'), + data['record'].lower())) + record = [d['id'] for d in self.env.cr.dictfetchall()] + return record + if data['regex'] == 2: + if data['field_type'] == 'many2one': + self.env.cr.execute( + """SELECT id FROM %s WHERE lower(name) LIKE '%%%s%%'""" % ( + data['field_relation'].replace('.', '_'), + data['field_string'].lstrip().lower())) + record = [d['id'] for d in self.env.cr.dictfetchall()] + return self.env[data['model']].search( + [(data['field'], 'in', record)]).ids + elif data['field_type'] == 'selection': + for state, label in self._get_selection_values(data): + if data['field_string'].lstrip().lower() == label.lower(): + data['field_string'] = state + return self.env[data['model']].search( + [(data['field'], '=', data['field_string'])]).ids + else: + self.env.cr.execute( + """SELECT id from %s where lower(%s) like '%%%s%%'""" % ( + data['model'].replace('.', '_'), data['field'], + data['field_string'].lstrip().lower())) + record = [rec['id'] for rec in self.env.cr.dictfetchall()] + return record + + def _get_selection_values(self, data): + """ Function for getting selection values""" + return \ + self.env[data['model']].fields_get(data['field'])[data['field']][ + 'selection'] + + @api.model + def check_fields_model(self, data): + """Function for checking field of a model""" + string = "" + for rec in range(len(data['field_string'])): + if rec != 0: + string += " " + data['field_string'][rec] + else: + string += data['field_string'][rec] + self.env.cr.execute( + """select name ,ttype,relation from ir_model_fields where + model = '%s' and lower(field_description->>'en_US') = + lower('%s') limit 1""" % ( + data['model'], string)) + res = self.env.cr.dictfetchall() + if res: + res[0]['del'] = string + return res + elif rec == len(data['field_string']) - 1: + res = [] + return res diff --git a/text_commander/static/description/assets/icons/check.png b/text_commander/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/text_commander/static/description/assets/icons/check.png differ diff --git a/text_commander/static/description/assets/icons/chevron.png b/text_commander/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/text_commander/static/description/assets/icons/chevron.png differ diff --git a/text_commander/static/description/assets/icons/cogs.png b/text_commander/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/text_commander/static/description/assets/icons/cogs.png differ diff --git a/text_commander/static/description/assets/icons/consultation.png b/text_commander/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/text_commander/static/description/assets/icons/consultation.png differ diff --git a/text_commander/static/description/assets/icons/ecom-black.png b/text_commander/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/text_commander/static/description/assets/icons/ecom-black.png differ diff --git a/text_commander/static/description/assets/icons/education-black.png b/text_commander/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/text_commander/static/description/assets/icons/education-black.png differ diff --git a/text_commander/static/description/assets/icons/hotel-black.png b/text_commander/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/text_commander/static/description/assets/icons/hotel-black.png differ diff --git a/text_commander/static/description/assets/icons/license.png b/text_commander/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/text_commander/static/description/assets/icons/license.png differ diff --git a/text_commander/static/description/assets/icons/lifebuoy.png b/text_commander/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/text_commander/static/description/assets/icons/lifebuoy.png differ diff --git a/text_commander/static/description/assets/icons/manufacturing-black.png b/text_commander/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/text_commander/static/description/assets/icons/manufacturing-black.png differ diff --git a/text_commander/static/description/assets/icons/pos-black.png b/text_commander/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/text_commander/static/description/assets/icons/pos-black.png differ diff --git a/text_commander/static/description/assets/icons/puzzle.png b/text_commander/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/text_commander/static/description/assets/icons/puzzle.png differ diff --git a/text_commander/static/description/assets/icons/restaurant-black.png b/text_commander/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/text_commander/static/description/assets/icons/restaurant-black.png differ diff --git a/text_commander/static/description/assets/icons/service-black.png b/text_commander/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/text_commander/static/description/assets/icons/service-black.png differ diff --git a/text_commander/static/description/assets/icons/trading-black.png b/text_commander/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/text_commander/static/description/assets/icons/trading-black.png differ diff --git a/text_commander/static/description/assets/icons/training.png b/text_commander/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/text_commander/static/description/assets/icons/training.png differ diff --git a/text_commander/static/description/assets/icons/update.png b/text_commander/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/text_commander/static/description/assets/icons/update.png differ diff --git a/text_commander/static/description/assets/icons/user.png b/text_commander/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/text_commander/static/description/assets/icons/user.png differ diff --git a/text_commander/static/description/assets/icons/wrench.png b/text_commander/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/text_commander/static/description/assets/icons/wrench.png differ diff --git a/text_commander/static/description/assets/misc/categories.png b/text_commander/static/description/assets/misc/categories.png new file mode 100644 index 000000000..bedf1e0b1 Binary files /dev/null and b/text_commander/static/description/assets/misc/categories.png differ diff --git a/text_commander/static/description/assets/misc/check-box.png b/text_commander/static/description/assets/misc/check-box.png new file mode 100644 index 000000000..42caf24b9 Binary files /dev/null and b/text_commander/static/description/assets/misc/check-box.png differ diff --git a/text_commander/static/description/assets/misc/compass.png b/text_commander/static/description/assets/misc/compass.png new file mode 100644 index 000000000..d5fed8faa Binary files /dev/null and b/text_commander/static/description/assets/misc/compass.png differ diff --git a/text_commander/static/description/assets/misc/corporate.png b/text_commander/static/description/assets/misc/corporate.png new file mode 100644 index 000000000..2eb13edbf Binary files /dev/null and b/text_commander/static/description/assets/misc/corporate.png differ diff --git a/text_commander/static/description/assets/misc/customer-support.png b/text_commander/static/description/assets/misc/customer-support.png new file mode 100644 index 000000000..79efc72ed Binary files /dev/null and b/text_commander/static/description/assets/misc/customer-support.png differ diff --git a/text_commander/static/description/assets/misc/cybrosys-logo.png b/text_commander/static/description/assets/misc/cybrosys-logo.png new file mode 100644 index 000000000..cc3cc0ccf Binary files /dev/null and b/text_commander/static/description/assets/misc/cybrosys-logo.png differ diff --git a/text_commander/static/description/assets/misc/features.png b/text_commander/static/description/assets/misc/features.png new file mode 100644 index 000000000..b41769f77 Binary files /dev/null and b/text_commander/static/description/assets/misc/features.png differ diff --git a/text_commander/static/description/assets/misc/logo.png b/text_commander/static/description/assets/misc/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/text_commander/static/description/assets/misc/logo.png differ diff --git a/text_commander/static/description/assets/misc/pictures.png b/text_commander/static/description/assets/misc/pictures.png new file mode 100644 index 000000000..56d255fe9 Binary files /dev/null and b/text_commander/static/description/assets/misc/pictures.png differ diff --git a/text_commander/static/description/assets/misc/pie-chart.png b/text_commander/static/description/assets/misc/pie-chart.png new file mode 100644 index 000000000..426e05244 Binary files /dev/null and b/text_commander/static/description/assets/misc/pie-chart.png differ diff --git a/text_commander/static/description/assets/misc/right-arrow.png b/text_commander/static/description/assets/misc/right-arrow.png new file mode 100644 index 000000000..730984a06 Binary files /dev/null and b/text_commander/static/description/assets/misc/right-arrow.png differ diff --git a/text_commander/static/description/assets/misc/star.png b/text_commander/static/description/assets/misc/star.png new file mode 100644 index 000000000..2eb9ab29f Binary files /dev/null and b/text_commander/static/description/assets/misc/star.png differ diff --git a/text_commander/static/description/assets/misc/support.png b/text_commander/static/description/assets/misc/support.png new file mode 100644 index 000000000..4f18b8b82 Binary files /dev/null and b/text_commander/static/description/assets/misc/support.png differ diff --git a/text_commander/static/description/assets/misc/whatsapp.png b/text_commander/static/description/assets/misc/whatsapp.png new file mode 100644 index 000000000..d513a5356 Binary files /dev/null and b/text_commander/static/description/assets/misc/whatsapp.png differ diff --git a/text_commander/static/description/assets/modules/1.png b/text_commander/static/description/assets/modules/1.png new file mode 100644 index 000000000..9b2631b84 Binary files /dev/null and b/text_commander/static/description/assets/modules/1.png differ diff --git a/text_commander/static/description/assets/modules/2.png b/text_commander/static/description/assets/modules/2.png new file mode 100644 index 000000000..6d637752d Binary files /dev/null and b/text_commander/static/description/assets/modules/2.png differ diff --git a/text_commander/static/description/assets/modules/3.png b/text_commander/static/description/assets/modules/3.png new file mode 100644 index 000000000..3c3ff1afb Binary files /dev/null and b/text_commander/static/description/assets/modules/3.png differ diff --git a/text_commander/static/description/assets/modules/4.png b/text_commander/static/description/assets/modules/4.png new file mode 100644 index 000000000..99298bf4b Binary files /dev/null and b/text_commander/static/description/assets/modules/4.png differ diff --git a/text_commander/static/description/assets/modules/5.png b/text_commander/static/description/assets/modules/5.png new file mode 100644 index 000000000..018fe5702 Binary files /dev/null and b/text_commander/static/description/assets/modules/5.png differ diff --git a/text_commander/static/description/assets/modules/6.png b/text_commander/static/description/assets/modules/6.png new file mode 100644 index 000000000..f3c986fc1 Binary files /dev/null and b/text_commander/static/description/assets/modules/6.png differ diff --git a/text_commander/static/description/assets/modules/7.png b/text_commander/static/description/assets/modules/7.png new file mode 100644 index 000000000..eb3f8652f Binary files /dev/null and b/text_commander/static/description/assets/modules/7.png differ diff --git a/text_commander/static/description/assets/screenshots/1.png b/text_commander/static/description/assets/screenshots/1.png new file mode 100644 index 000000000..4f60fa597 Binary files /dev/null and b/text_commander/static/description/assets/screenshots/1.png differ diff --git a/text_commander/static/description/assets/screenshots/2.png b/text_commander/static/description/assets/screenshots/2.png new file mode 100644 index 000000000..e643bd840 Binary files /dev/null and b/text_commander/static/description/assets/screenshots/2.png differ diff --git a/text_commander/static/description/assets/screenshots/3.png b/text_commander/static/description/assets/screenshots/3.png new file mode 100644 index 000000000..e836606e7 Binary files /dev/null and b/text_commander/static/description/assets/screenshots/3.png differ diff --git a/text_commander/static/description/assets/screenshots/4.png b/text_commander/static/description/assets/screenshots/4.png new file mode 100644 index 000000000..141b03011 Binary files /dev/null and b/text_commander/static/description/assets/screenshots/4.png differ diff --git a/text_commander/static/description/assets/screenshots/hero.gif b/text_commander/static/description/assets/screenshots/hero.gif new file mode 100644 index 000000000..e299b559e Binary files /dev/null and b/text_commander/static/description/assets/screenshots/hero.gif differ diff --git a/text_commander/static/description/banner.png b/text_commander/static/description/banner.png new file mode 100644 index 000000000..b86a07f51 Binary files /dev/null and b/text_commander/static/description/banner.png differ diff --git a/text_commander/static/description/icon.png b/text_commander/static/description/icon.png new file mode 100644 index 000000000..8468b962e Binary files /dev/null and b/text_commander/static/description/icon.png differ diff --git a/text_commander/static/description/index.html b/text_commander/static/description/index.html new file mode 100644 index 000000000..69d4bbbe6 --- /dev/null +++ b/text_commander/static/description/index.html @@ -0,0 +1,631 @@ +
+ +
+ +
+
+ Community +
+
Enterprise +
+
+
+ +
+
+
+ +

+ Text Commander

+

+ Open or Create Records of a Model through Command + Palette

+ + +
+
+
+ + +
+ + +
+
+ +
+

+ Explore This + Module

+
+ + + + +
+
+ +
+

+ Overview +

+
+
+
+ This module helps you to open models or single model record and create + record of a model through command palette with input text. +
+
+ + + +
+
+ +
+

+ Features +

+
+
+
+
+ + Open single record and multiple record +
+
+ + Open records of model based on condition. +
+
+ + Create records of model through command. +
+
+ +
+ + + +
+
+ +
+

+ Screenshots +

+
+
+
+ +
+

+ To open the Command Prompt, press Ctrl + K and then use the '!' + command to proceed with additional actions. +

+ +
+ +
+

+ Condition based command +

+ +
+
+

+ Command for single record +

+ +
+
+

+ Command for create record +

+ +
+ +
+
+ + + +
+
+ +
+

+ Related + Products +

+
+
+
+ +
+
+ + + + +
+
+ +
+

+ Our Services +

+
+ +
+
+
+
+ +
+
+ Odoo + Customization
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Support
+
+ + +
+
+ +
+
+ Hire + Odoo + Developer
+
+ +
+
+ +
+
+ Odoo + Integration
+
+ +
+
+ +
+
+ Odoo + Migration
+
+ + +
+
+ +
+
+ Odoo + Consultancy
+
+ +
+
+ +
+
+ Odoo + Implementation
+
+ +
+
+ +
+
+ Odoo + Licensing Consultancy
+
+
+ +
+ + + +
+
+ +
+

+ Our + Industries +

+
+ +
+
+
+
+ +
+ Trading +
+

+ Easily procure + and + sell your products

+
+
+ +
+
+ +
+ POS +
+

+ Easy + configuration + and convivial experience

+
+
+ +
+
+ +
+ Education +
+

+ A platform for + educational management

+
+
+ +
+
+ +
+ Manufacturing +
+

+ Plan, track and + schedule your operations

+
+
+ +
+
+ +
+ E-commerce & Website +
+

+ Mobile + friendly, + awe-inspiring product pages

+
+
+ +
+
+ +
+ Service Management +
+

+ Keep track of + services and invoice

+
+
+ +
+
+ +
+ Restaurant +
+

+ Run your bar or + restaurant methodically

+
+
+ +
+
+ +
+ Hotel Management +
+

+ An + all-inclusive + hotel management application

+
+
+
+
+ + +
+
+ +
+

+ Support +

+
+
+
+
+
+
+ +
+
+

Need Help?

+

Got questions or need help? + Get in touch.

+ +

+ odoo@cybrosys.com

+
+
+
+
+
+
+
+ +
+
+

WhatsApp

+

Say hi to us on WhatsApp!

+ +

+ +91 86068 + 27707

+
+
+
+
+
+
+
+ +
+
+
+ \ No newline at end of file diff --git a/text_commander/static/src/js/command_palette.js b/text_commander/static/src/js/command_palette.js new file mode 100644 index 000000000..b1e2210db --- /dev/null +++ b/text_commander/static/src/js/command_palette.js @@ -0,0 +1,329 @@ +/** @odoo-module **/ +var core = require('web.core'); +const rpc = require("web.rpc"); +const Dialog = require('web.Dialog'); +import { CommandPalette } from "@web/core/commands/command_palette"; +import { patch } from 'web.utils'; +import { useService } from "@web/core/utils/hooks"; +var _t = core._t; +//Patching the CommandPalette for adding condition while using "!" command +patch(CommandPalette.prototype, 'text_commander/static/src/js/command_palette.js', { + setup() { + this._super() + this.action = useService("action"); + }, + //Here we patch the CommandPalette to access commands from the user + onKeyDown(ev) { + if (ev.key == 'Enter' && this.state.namespace == '!'){ + var self = this + if (this.state.searchValue.split(" ")[0] == 'Open'){ + const regex = /^Open.*\/.*$/; + const regex1 = /^Open.*(?:of|in).*$/; + const regex2 = /^Open.*/ + var searchValue = this.state.searchValue + if (regex.test(searchValue)){ + var parts = searchValue.split("/"); + var model = parts[0].replace("Open ", ""); + rpc.query({ + model:'ir.model', + method:'check_model', + args:[model] + }).then(function(res){ + if(res.length!=0){ + self.model = res[0]['model'] + self.model_name = res[0]['name']['en_US'] + var data = { + 'model':self.model, + 'record':parts[1], + 'regex':1, + } + rpc.query({ + model:'ir.model', + method:'get_records', + args:[data] + }).then(function(res){ + if (res.length !=1){ + self.action.doAction({ + name:self.model_name, + type: 'ir.actions.act_window', + res_model: self.model, + domain: [["id", "in", res]], + views: [[false, "list"], [false, "form"]], + view_mode: "list,form", + target: "current", + }); + } + else{ + self.action.doAction({ + type: "ir.actions.act_window", + res_model: self.model, + views: [[false, 'form']], + target: 'current', + res_id:res[0] + }); + } + self.props.close() + }) + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:model + _t(" model not found") + }), + }).open(); + } + }) + } + else if(regex1.test(searchValue)){ + const pattern = /^Open\s(.*)\s(?:of|in).*$/ + const match = searchValue.match(pattern); + if (match){ + rpc.query({ + model:'ir.model', + method:'check_model', + args:[match[1]] + }).then(function(res){ + if (res.length!=0){ + self.model = res[0]['model'] + self._fields_check(self.model) + var data = { + 'model':self.model, + } + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:match[1] + _t(" model not found") + }), + }).open(); + } + }) + } + } + else if(regex2.test(searchValue)){ + const reg = /^Open\s*/i; + const parts = searchValue.split(reg); + rpc.query({ + model:'ir.model', + method:'check_model', + args:[parts[1]] + }).then(function(res){ + if (res.length!=0){ + self.action.doAction({ + name:res[0]['name']['en_US'], + type: 'ir.actions.act_window', + res_model: res[0]['model'], + views: [[false, "list"], [false, "form"]], + view_mode: "list,form", + target: "current", + }); + self.props.close(); + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:parts[1] + _t(" model not found") + }), + }).open(); + } + }) + + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:_t("not matching command") + }), + }).open(); + } + } + else if(this.state.searchValue.split(" ")[0] == 'Create'){ + const regex = /^Create.*/ + const searchValue = this.state.searchValue + if (regex.test(searchValue)){ + const reg = /^Create\s*/i; + const parts = searchValue.split(reg); + rpc.query({ + model:'ir.model', + method:'check_model', + args:[parts[1]] + }).then(function(res){ + if (res.length!=0){ + self.action.doAction({ + type: "ir.actions.act_window", + res_model: res[0]['model'], + views: [[false, 'form']], + target: 'current', + }); + self.props.close(); + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:parts[1] + _t(" model not found") + }), + }).open(); + } + }) + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:_t("command not found") + }), + }).open(); + } + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:_t("command not found") + }), + }).open(); + } + } + }, + //Check fields + _fields_check(model){ + var self = this + const searchValue = this.state.searchValue + const pattern = /^Open\s.*\s(of|in)\s(.*)$/ + const match = searchValue.match(pattern) + if (match){ + const string = match[2].split(" ") + var field_string = "" + var data = { + 'model':model, + 'field_string':string, + 'regex':2, + } + rpc.query({ + model:'ir.model', + method:'check_fields_model', + args:[data] + }).then(function(res){ + if (res.length!=0){ + data['field_string'] = match[2].replace(res[0]['del'],"") + data['field'] = res[0]['name'] + data['field_type'] = res[0]['ttype'] + data['field_relation'] = res[0]['relation'] + rpc.query({ + model:'ir.model', + method:'get_records', + args:[data] + }).then(function(res){ + self.action.doAction({ + name:'Records', + type: 'ir.actions.act_window', + res_model: model, + domain: [["id", "in", res]], + views: [[false, "list"], [false, "form"]], + view_mode: "list,form", + target: "current", + }) + }) + self.props.close() + } + else{ + self.props.close() + var buttons = [ + { + text: _t("Ok"), + classes: 'btn-primary', + close: true, + }, + ]; + new Dialog(self, { + size: 'medium', + buttons: buttons, + $content: $('
', { + text:_t("field not found") + }), + }).open(); + } + }) + } + }, + //Executing the command + async executeCommand(command) { + if (this.state.namespace != '!'){ + const config = await command.action(); + if (config) { + this.setCommandPaletteConfig(config); + } + else { + this.props.close(); + } + } + } +}); diff --git a/text_commander/static/src/js/model_providers.js b/text_commander/static/src/js/model_providers.js new file mode 100644 index 000000000..3dffa009c --- /dev/null +++ b/text_commander/static/src/js/model_providers.js @@ -0,0 +1,27 @@ +/** @odoo-module **/ + +import { _lt } from "@web/core/l10n/translation"; +import { registry } from "@web/core/registry"; +import { Component } from "@odoo/owl"; +//Creates a class for rendering the template when the commander is entered +class ModelItemCommand extends Component {} +ModelItemCommand.template = "text_commander.ModelItemsCommand"; +//Creating a new namespace +const ModelItemCommandRegistry = registry.category("command_setup"); +ModelItemCommandRegistry.add("!", { + debounceDelay: 200, + emptyMessage: _lt("Commands: "), + name: _lt("Record"), + placeholder: _lt("Search for a record..."), +}); +const ModelItemCommandProvider = registry.category("command_provider"); +ModelItemCommandProvider.add("model",{ + namespace: "!", + async provide(env, options){ + const suggestion = [] + suggestion.push({ + Component: ModelItemCommand, + }); + return suggestion + }, +}); diff --git a/text_commander/static/src/xml/model_command_item.xml b/text_commander/static/src/xml/model_command_item.xml new file mode 100644 index 000000000..61841866d --- /dev/null +++ b/text_commander/static/src/xml/model_command_item.xml @@ -0,0 +1,33 @@ + +