summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-12-20 13:57:52 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-12-20 13:57:52 +0700
commitb4a8de6bd7ca7051eee16f877b4e5d8fd65e3056 (patch)
tree69674562e601740d343f7e6710f26d7d79d5acd7
parent9ba922eded6d752c2a4299c9c444238309877bb9 (diff)
<iman> add telegram
-rw-r--r--indoteknik_custom/models/ir_actions_report.py6
-rw-r--r--indoteknik_custom/models/res_partner.py1
-rw-r--r--indoteknik_custom/models/website_telegram.py26
-rw-r--r--indoteknik_custom/views/res_partner.xml1
4 files changed, 16 insertions, 18 deletions
diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py
index b7d4e372..7b1dcee8 100644
--- a/indoteknik_custom/models/ir_actions_report.py
+++ b/indoteknik_custom/models/ir_actions_report.py
@@ -1,5 +1,5 @@
from odoo import models
-import requests
+from odoo.http import request
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'
@@ -13,10 +13,12 @@ class IrActionsReport(models.Model):
sale_order = self.env['sale.order'].browse(so_id)
if sale_order.amount_total < 200000000:
return
+ # id ci vita 79160
+ partner = request.env['res.partner'].search([('id', '=', 112718)], limit=1)
telegram_data = {
'tittle': sale_order.name,
'about': sale_order.name,
- 'user_id': sale_order,
+ 'user_id': partner,
'id_data': sale_order.id,
'username': '@' + sale_order.name.replace('/', '')
}
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index da4a6cb6..c648c729 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -74,6 +74,7 @@ class ResPartner(models.Model):
"customer is crossed blocking amount."
"Set its value to 0.00 to disable "
"this feature", tracking=3)
+ telegram_id = fields.Char(string="Telegram")
@api.model
def _default_payment_term(self):
diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py
index ade6c326..7d76f27d 100644
--- a/indoteknik_custom/models/website_telegram.py
+++ b/indoteknik_custom/models/website_telegram.py
@@ -36,7 +36,7 @@ class WebsiteTelegram(models.Model):
for record in self:
usernames = []
for partner in record.user_id:
- if partner.mobile: # Pastikan mobile tidak None
+ if partner.telegram_id: # Pastikan mobile tidak None
usernames.append(partner.mobile)
# Gabungkan semua nomor menjadi satu string, dipisahkan koma
record.username_to_add = ', '.join(usernames)
@@ -59,15 +59,16 @@ class WebsiteTelegram(models.Model):
peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash),
))
self.invite_link = channel_link.link
- # username_to_add = ['@radiant81', '6285764475716', '@stephanchrst']
- username_to_add = ['6282339129611']
- for name in username_to_add:
- user_to_add = await client.get_entity(name)
+
+ # Iterasi untuk setiap username
+ for name in self.user_id:
+ user_to_add = await client.get_entity(name.telegram_id)
result_add_user = await client(functions.channels.InviteToChannelRequest(
channel=channel,
users=[user_to_add.id],
))
- message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101'
+ # message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=209&model=sale.order&view_type=form&cids=1&menu_id=101'
+ message = 'https://erp.indoteknik.com/web#id=' + self.id_data + '&action=357&model=sale.order&view_type=form&cids=1&menu_id=212'
message2 = self.tittle + ' di print oleh ' + self.env.user.name
result_massage = await client(SendMessageRequest(channel, message))
result_massage2 = await client(SendMessageRequest(channel, message2))
@@ -130,26 +131,19 @@ class WebsiteTelegram(models.Model):
27799517, 'df8ee44b0ed11108245037d47b511201') as client:
channel = await client.get_entity(self.invite_link)
- # Memproses username_to_add menjadi list
- usernames = self.username_to_add.split(', ') # Pisahkan berdasarkan koma dan spasi
-
# Iterasi untuk setiap username
- for username in usernames:
- if username: # Pastikan username tidak kosong
+ for username in self.user_id:
+ if username:
try:
- # Mendapatkan entitas user berdasarkan username
- user_to_add = await client.get_entity(username)
+ user_to_add = await client.get_entity(username.telegram_id)
- # Mengundang user ke channel
result_add_user = await client(functions.channels.InviteToChannelRequest(
channel=channel,
users=[user_to_add.id],
))
except Exception as e:
- # Tangani error (misal user tidak ditemukan atau sudah ada di channel)
print(f"Error adding user {username}: {e}")
- # Mengirim pesan ke channel
result_message = await client(SendMessageRequest(channel, message))
def test_send(self):
diff --git a/indoteknik_custom/views/res_partner.xml b/indoteknik_custom/views/res_partner.xml
index 1b164161..712ebdd2 100644
--- a/indoteknik_custom/views/res_partner.xml
+++ b/indoteknik_custom/views/res_partner.xml
@@ -65,6 +65,7 @@
<field name="vat" position="after">
<field name="email_finance" widget="email"/>
<field name="email_sales" widget="email"/>
+ <field name="telegram_id"/>
<field name="use_so_approval" attrs="{'invisible': [('parent_id', '!=', False), ('company_type', '!=', 'company')]}" />
<field name="use_only_ready_stock" attrs="{'invisible': [('parent_id', '!=', False), ('company_type', '!=', 'company')]}" />
<field name="web_role" attrs="{'invisible': ['|', ('parent_id', '=', False), ('company_type', '=', 'company')]}" />