diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-12-10 13:21:14 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-12-10 13:21:14 +0700 |
| commit | 1bf746c93dc5010e30490d0a5ed6a2a174726be0 (patch) | |
| tree | 27be1d61e8d5985e4d202a2723a063445f782348 | |
| parent | bab6a911535b771e988093725e0ba378c77297c6 (diff) | |
<iman> update code telegram print so when amount > 200jt
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/ir_actions_report.py | 29 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 34 | ||||
| -rw-r--r-- | indoteknik_custom/models/website_telegram.py | 43 |
4 files changed, 55 insertions, 52 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 1e0cedc9..b319883c 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -135,3 +135,4 @@ from . import find_page from . import approval_retur_picking from . import va_multi_approve from . import va_multi_reject +from . import ir_actions_report diff --git a/indoteknik_custom/models/ir_actions_report.py b/indoteknik_custom/models/ir_actions_report.py new file mode 100644 index 00000000..d620f8a7 --- /dev/null +++ b/indoteknik_custom/models/ir_actions_report.py @@ -0,0 +1,29 @@ +from odoo import models +import requests +class IrActionsReport(models.Model): + _inherit = 'ir.actions.report' + + def _get_readable_fields(self): + self.send_to_telegram() + return super()._get_readable_fields() + + def send_to_telegram(self): + so_id = self.env.context.get('active_id') + if so_id: + sale_order = self.env['sale.order'].browse(so_id) + if sale_order.amount_total < 200000000: + return + telegram_data = { + 'tittle': sale_order.name, + 'about': 'Permintaan retur ' + sale_order.name, + 'id_data': sale_order.id, + 'username': '@' + sale_order.name.replace('/', '') + } + channel_data = self.env['website.telegram'].search([('tittle', '=', sale_order.name)]) + if channel_data: + channel_data.send_to_telegram(sale_order.name + " Telah di print") + for pick in self: + self._check_telegram(pick) + else: + telegram = self.env['website.telegram'].create(telegram_data) + telegram.create_channel() diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 2095e957..31c45531 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -468,40 +468,6 @@ class StockPicking(models.Model): raise UserError('Harus Sales Admin yang Ask Return') else: raise UserError('Harus Purchasing yang Ask Return') - telegram_data = { - 'tittle': self.name, - 'about': 'Permintaan retur ' + self.name, - 'id_data': self.id, - 'username': '@'+self.name.replace('/', '') - } - channel_data = self.env['website.telegram'].search([('tittle', '=', self.name)]) - if channel_data: - for pick in self: - self._check_telegram(pick) - else: - telegram = request.env['website.telegram'].create(telegram_data) - telegram.create_channel() - for pick in self: - pick.approval_return_status = 'pengajuan1' - - def read(self, fields=None, load='_classic_read'): - # Panggil method 'read' bawaan terlebih dahulu - records = super(StockPicking, self).read(fields, load) - - # Jalankan _check_telegram untuk setiap record yang diakses - for record in self: - if record.approval_return_status == 'pengajuan1': - record._check_telegram() - - return records - - - def _check_telegram(self): - telegram = self.env['website.telegram'].search([('id_data', '=', self.id)]) - if telegram: - ask_return = telegram.receive_messages() - if ask_return: - self.approval_return_status = 'approved' def calculate_line_no(self): diff --git a/indoteknik_custom/models/website_telegram.py b/indoteknik_custom/models/website_telegram.py index 58816fe2..92707ea2 100644 --- a/indoteknik_custom/models/website_telegram.py +++ b/indoteknik_custom/models/website_telegram.py @@ -35,7 +35,7 @@ class WebsiteTelegram(models.Model): '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), 27799517, 'df8ee44b0ed11108245037d47b511201') as client: result = await client(functions.channels.CreateChannelRequest( - title='Permintaan retur ' + self.tittle, + title=self.tittle + ' Telah Diprint', about=self.about, broadcast=False, megagroup=True, @@ -45,30 +45,30 @@ 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 = ['@imsep81', '6285764475716', '@stephanchrst'] - username_to_add = ['@radiant81'] + # username_to_add = ['@radiant81', '6285764475716', '@stephanchrst'] + username_to_add = ['6282339129611'] for name in username_to_add: user_to_add = await client.get_entity(name) 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=stock.picking&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' result_massage = await client(SendMessageRequest(channel, message)) # Send the poll to the channel using PeerChannel with the channel's ID - result_polling = await client(SendMediaRequest( - peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), - media=InputMediaPoll(poll=Poll( - question=TextWithEntities(text="ASK RETURN?", entities=[]), - answers=[ - PollAnswer(text=TextWithEntities(text="Accept", entities=[]), option=b'\x01'), - PollAnswer(text=TextWithEntities(text="Reject", entities=[]), option=b'\x02'), - ], - id=2 - )), - message='Ask Return Polling' - )) + # result_polling = await client(SendMediaRequest( + # peer=InputPeerChannel(channel_id=channel.channel_id, access_hash=result.chats[0].access_hash), + # media=InputMediaPoll(poll=Poll( + # question=TextWithEntities(text="ASK RETURN?", entities=[]), + # answers=[ + # PollAnswer(text=TextWithEntities(text="Accept", entities=[]), option=b'\x01'), + # PollAnswer(text=TextWithEntities(text="Reject", entities=[]), option=b'\x02'), + # ], + # id=2 + # )), + # message='Ask Return Polling' + # )) def receive_messages(self): return asyncio.run(self._async_receive_messages()) @@ -101,12 +101,19 @@ class WebsiteTelegram(models.Model): return accept_found def send_to_telegram(self, message): - apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' + # apiURL = f'https://api.telegram.org/bot{self.bot_name}/sendMessage' try: - requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) + # requests.post(apiURL, json={'chat_id': self.chatID, 'text': message}) + asyncio.run(self._async_send_to_telegram(message)) except Exception as e: print(e) + async def _async_send_to_telegram(self, message): + async with TelegramClient(StringSession( + '1BVtsOJABu30MWCBFwYvvaYbFoIWi43r5a7TUZ2IWwrnSlXIwEhJS5k2y4UKjoDeMPKwhgUWn9lMk02zQjM0ZDzq61YyhkRBvZuu3hCxMsrtP92bkuZtL2g3g1VgI8s7rMhOD_WaGrZbuj-TmbTwIEbN5i1J4raDW2kYzmlLRCbT74xxrGjpzWCnVv7CSS9L2juXuut0lLMgli3_JZbqDO1IyBYh4ZFQYbMf7zv6moDR4MQp1qfnFArsikQcfxjlNXKFcSoyA_GjiIFfCuymwQVtdERXOAH03M_lm8fYbjvgxEkJvxR6hdCnYMcKpIujEEo9SmMmK7Vnl29g1TCPO5tlrDNXq3Ng='), + 27799517, 'df8ee44b0ed11108245037d47b511201') as client: + channel = await client.get_entity(self.invite_link) + result_massage = await client(SendMessageRequest(channel, message)) def test_send(self): try: self.env.cr.savepoint() |
