summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-09 15:59:34 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-09 15:59:34 +0700
commit94141d0871e9abed968d3c249eeaf7b3c1ae87d9 (patch)
tree2628529a5a001434ca5e4705156aba0448deec2b
parent04d994e53a36ea9a6f7a2c0dd3f5f1b2c0ca9a74 (diff)
<iman> update telegram create channel
-rw-r--r--indoteknik_custom/models/stock_picking.py7
-rw-r--r--indoteknik_custom/models/website_telegram.py39
-rw-r--r--indoteknik_custom/views/website_telegram.xml16
3 files changed, 40 insertions, 22 deletions
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 14190474..5397b59f 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -4,6 +4,7 @@ from odoo.tools.float_utils import float_is_zero
from datetime import datetime
from itertools import groupby
import pytz, datetime
+from odoo.http import request
class StockPicking(models.Model):
@@ -310,11 +311,17 @@ class StockPicking(models.Model):
self.approval_receipt_status = 'pengajuan1'
def ask_return_approval(self):
+ telegram_data = {
+ 'tittle': 'Permintaan retur ' + self.name,
+ 'about': 'Permintaan retur ' + self.name,
+ }
+ telegram = request.env['website.telegram'].create(telegram_data)
for pick in self:
if self.env.user.is_accounting:
pick.approval_return_status = 'approved'
else:
pick.approval_return_status = 'pengajuan1'
+ telegram.create_channel()
def calculate_line_no(self):
for picking in self:
diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py
index 5684eff8..c0e7be2f 100644
--- a/indoteknik_custom/models/website_telegram.py
+++ b/indoteknik_custom/models/website_telegram.py
@@ -1,19 +1,40 @@
import requests
-
import clipboard
-
from odoo import models, fields, api
+from telethon.sessions import StringSession
+from telethon.sync import TelegramClient
+from telethon import functions, types
+from telethon.tl.types import InputChannel, InputPeerChannel
+import asyncio
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')
+ tittle = fields.Char("Channel Title")
+ about = fields.Char("Channel Description")
+ is_broadcast = fields.Boolean("Is Broadcast", default=True)
+ is_megagroup = fields.Boolean("Is Megagroup", default=False)
+ # session_string = 'MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIRyy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwvplUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCOj4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB'
+
+ def create_channel(self, *args, **kwargs):
+ asyncio.run(self._async_create_channel())
+
+ async def _async_create_channel(self):
+ async with TelegramClient(StringSession('1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client:
+ result = await client(functions.channels.CreateChannelRequest(
+ title=self.tittle,
+ about=self.about,
+ broadcast=True,
+ megagroup=False,
+ ))
+ channel = result.updates[3].message.peer_id
+ username_to_add = ['@imsep81', '6285764475716', '@stephanchrst']
+ for name in username_to_add:
+ user_to_add = await client.get_entity(name)
+ result = await client(functions.channels.InviteToChannelRequest(
+ channel=channel,
+ users=[user_to_add.id],
+ ))
def send_to_telegram(self, message):
# if self.env.all.registry.db_name == 'odoo016':return
diff --git a/indoteknik_custom/views/website_telegram.xml b/indoteknik_custom/views/website_telegram.xml
index 58aaabda..887d62e1 100644
--- a/indoteknik_custom/views/website_telegram.xml
+++ b/indoteknik_custom/views/website_telegram.xml
@@ -12,15 +12,10 @@
<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"/>
+ <field name="tittle"/>
+ <field name="about"/>
<button name="test_send" type="object" icon="fa-paper-plane" string="Send Test"/>
+ <button name="create_channel" type="object" icon="fa-paper-plane" string="Create Channel"/>
<button name="receive_messages" type="object" icon="fa-paper-plane" string="GET Test"/>
</tree>
</field>
@@ -33,11 +28,6 @@
<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>