summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/website_telegram.py63
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/website_telegram.xml62
5 files changed, 128 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index e1a67592..3104b9a3 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -59,6 +59,7 @@
'views/website_brand_homepage.xml',
'views/website_categories_homepage.xml',
'views/website_categories_management.xml',
+ 'views/website_telegram.xml',
'views/website_categories_lob.xml',
'views/sales_target.xml',
'views/purchase_outstanding.xml',
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 3d700ce0..1620c82e 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -128,3 +128,4 @@ from . import sales_order_reject
from . import approval_date_doc
from . import account_tax
from . import approval_unreserve
+from . import website_telegram
diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py
new file mode 100644
index 00000000..8fc6a8ea
--- /dev/null
+++ b/indoteknik_custom/models/website_telegram.py
@@ -0,0 +1,63 @@
+import requests
+
+import clipboard
+
+from odoo import models, fields, api
+
+class WebsiteTelegram(models.Model):
+ _name = 'website.telegram'
+ _description = 'Telegram Channel'
+
+ name = fields.Char(string='Bot Name', required=True)
+ bot_name = fields.Char(string='Bot Token', help="Create your bot from Bot Father form Telegram App", required=True, )
+ python_code = fields.Char(compute="_calc_python_code")
+ chatID = fields.Char(string='Channel Name', required=True, help="Create yor channel , Add members , Add Bot As an Admin")
+
+ test_message = fields.Char(string='Test Message', required=False, default='Test')
+
+ def send_to_telegram(self, message):
+ # if self.env.all.registry.db_name == 'odoo016':return
+
+ # message = self.env.all.registry.db_name + " : " + message
+ message = self.test_message
+
+ apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage'
+ try:
+ requests.post(apiURL, json={'chat_id': self.chatID, 'text': message})
+ except Exception as e:
+ print(e)
+
+ def test_send(self):
+ try:
+ self.env.cr.savepoint()
+
+ self.env['website.telegram'].search([('name', '=', self.name)])[0].send_to_telegram(self.test_message)
+ except Exception as e:
+ print(e)
+
+ @api.depends('name', 'chatID', 'bot_name')
+ def _calc_python_code(self):
+ for record in self:
+ if not record.name:
+ record.python_code = "pleas put a name"
+ elif not record.test_message:
+ record.test_message = "test"
+ else:
+ record.python_code = "self.env['website.telegram'].search([('name', '=', '" + record.name + "')])[0].send_to_telegram('" + record.test_message + "')"
+
+ def copy_chat_id(self):
+ record = self.browse(self.id)
+ clipboard.copy(record.python_code)
+
+ def paste_chat_id(self):
+ record = self.browse(self.id)
+ chat_id = clipboard.paste()
+ record.write({'chatID': chat_id})
+
+ def paste_bot_name(self):
+ record = self.browse(self.id)
+ bot_name = clipboard.paste()
+ record.write({'bot_name': bot_name})
+
+
+
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 19e3bdca..84147e04 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -24,6 +24,7 @@ access_website_categories_homepage,access.website.categories.homepage,model_webs
access_website_categories_lob,access.website.categories.lob,model_website_categories_lob,,1,1,1,1
access_website_categories_management,access.website.categories.management,model_website_categories_management,,1,1,1,1
access_website_categories_management_line,access.website.categories.management.line,model_website_categories_management_line,,1,1,1,1
+access_website_telegram,access.website.telegram,model_website_telegram,,1,1,1,1
access_sales_target,access.sales.target,model_sales_target,,1,1,1,1
access_purchase_outstanding,access.purchase.outstanding,model_purchase_outstanding,,1,1,1,1
access_sales_outstanding,access.sales.outstanding,model_sales_outstanding,,1,1,1,1
diff --git a/indoteknik_custom/views/website_telegram.xml b/indoteknik_custom/views/website_telegram.xml
new file mode 100644
index 00000000..9698bfc4
--- /dev/null
+++ b/indoteknik_custom/views/website_telegram.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <data>
+ <record id="website_telegram_action" model="ir.actions.act_window">
+ <field name="name">Channel Telegram</field>
+ <field name="res_model">website.telegram</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <record id="website_telegram_tree" model="ir.ui.view">
+ <field name="name">Channel Telegram</field>
+ <field name="model">website.telegram</field>
+ <field name="arch" type="xml">
+ <tree string="Channel List" editable="top">
+ <field name="name"/>
+ <field name="bot_name" placeholder="5#######:AAHCWT9t1XXXXXXXXXXXXX" />
+ <button name="paste_bot_name" type="object" icon="fa-paste"/>
+ <field name="chatID" placeholder="@ChannelName"/>
+ <button name="paste_chat_id" type="object" icon="fa-paste"/>
+ <field name="test_message"/>
+ <field name="python_code"/>
+ <button name="copy_chat_id" type="object" string="Copy Code" icon="fa-clipboard"/>
+ <button name="test_send" type="object" icon="fa-paper-plane" string="Send Test"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="website_telegram_form" model="ir.ui.view">
+ <field name="name">Channel Telegram</field>
+ <field name="model">website.telegram</field>
+ <field name="arch" type="xml">
+ <form string="Telegram Channel">
+ <sheet>
+ <group>
+ <field name="name"/>
+ <field name="bot_name"/>
+ <!-- <field name="code_name"/>-->
+ <field name="chatID"/>
+ <button name="paste_chat_id" type="object" icon="fa-paste"/>
+ </group>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="ir_actions_server_website_telegram_sync_to_solr" model="ir.actions.server">
+ <field name="name">Sync to solr</field>
+ <field name="model_id" ref="indoteknik_custom.model_website_telegram"/>
+ <field name="binding_model_id" ref="indoteknik_custom.model_website_telegram"/>
+ <field name="state">code</field>
+ <field name="code">model.action_sync_to_solr()</field>
+ </record>
+
+ <menuitem
+ id="website_telegram"
+ name="Channel Telegram"
+ parent="website_sale.menu_orders"
+ sequence="1"
+ action="website_telegram_action"
+ />
+ </data>
+</odoo>