diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-09-16 09:09:47 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-09-16 09:09:47 +0000 |
| commit | 07d8129d96f1e48838e27c33ad762673a04d465e (patch) | |
| tree | b3dc5f07488ddb86a60dc917ea5230680b04591e | |
| parent | 07a46fdbd16d72e60895d38047b6bb2e344dc18f (diff) | |
| parent | af7fc5db50d7c3f78b70a2b75186db4b4c1f3674 (diff) | |
Merged in sj_tele (pull request #416)
Sj tele
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 3 | ||||
| -rw-r--r-- | indoteknik_custom/models/report_logbook_sj.py | 43 | ||||
| -rw-r--r-- | indoteknik_custom/models/sj_tele.py | 102 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/report_logbook_sj.xml | 91 | ||||
| -rw-r--r-- | indoteknik_custom/views/sj_tele.xml | 15 |
7 files changed, 215 insertions, 43 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 09a3aa6f..791f77f6 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -179,6 +179,7 @@ # 'views/refund_sale_order.xml', 'views/update_date_planned_po_wizard_view.xml', # 'views/reimburse.xml', + 'views/sj_tele.xml' ], 'demo': [], 'css': [], diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 3a9f9312..c0aa7085 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -156,4 +156,5 @@ from . import refund_sale_order # from . import patch from . import tukar_guling from . import tukar_guling_po -from . import update_date_planned_po_wizard
\ No newline at end of file +from . import update_date_planned_po_wizard +from . import sj_tele
\ No newline at end of file diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py index 66edbf99..b45eab03 100644 --- a/indoteknik_custom/models/report_logbook_sj.py +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -4,6 +4,11 @@ from odoo import models, fields, api from odoo.exceptions import UserError from pytz import timezone from datetime import datetime +import requests +import json +import logging + +_logger = logging.getLogger(__name__) class ReportLogbookSJ(models.Model): _name = 'report.logbook.sj' @@ -83,6 +88,44 @@ class ReportLogbookSJ(models.Model): from odoo import models, fields, api + + + def action_send_to_telegram(self): + + entries = [] + pickings = self.report_logbook_sj_line.mapped('picking_id') + for p in pickings: + if p: + entries.append((p.name, p.id)) + + fallback_names = [l.name for l in self.report_logbook_sj_line if not l.picking_id and l.name] + if fallback_names: + picks = self.env['stock.picking'].search([('name', 'in', list(set(fallback_names)))]) + name2id = {p.name: p.id for p in picks} + for n in fallback_names: + entries.append((n, name2id.get(n))) + + seen, unique_entries = set(), [] + for name, pid in entries: + key = pid or name + if key and key not in seen: + seen.add(key) + unique_entries.append((name, pid)) + + header = f"{self.env.user.name} sudah mengisi di Logbook SJ Report:\n" + body = "\n".join(f"{name} ({pid or '-'})" for name, pid in unique_entries) if unique_entries else "- (tidak ada)" + text = header + body + + bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' + chat_id_mqdd = '-4885333032' + apiURL = f'https://api.telegram.org/bot{bot_mqdd}/sendMessage' + try: + hehe = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}) + _logger.info(hehe) + except Exception as e: + print(e) + + class ReportLogbookSJLine(models.Model): _name = 'report.logbook.sj.line' _order = 'sequence, id' # urut default di UI & ORM (drag pakai sequence) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py new file mode 100644 index 00000000..029adcbe --- /dev/null +++ b/indoteknik_custom/models/sj_tele.py @@ -0,0 +1,102 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +import requests +import json +import logging, subprocess +import time +from collections import OrderedDict + +_logger = logging.getLogger(__name__) + +class SjTele(models.Model): + _name = 'sj.tele' + _description = 'sj.tele' + + picking_id = fields.Many2one('stock.picking', string='Picking') + sale_id = fields.Many2one('sale.order', string='Sales Order') + picking_name = fields.Char(string='Picking Name') + sale_name = fields.Char(string='Sale Name') + create_date = fields.Datetime(string='Create Date') + date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') + + # @api.model + # def run_pentaho_carte(self): + # carte = "http://127.0.0.1:8080" + # job_kjb = r"C:/Users/Indoteknik/Desktop/tes.kjb" + # params = {"job": job_kjb, "level": "Basic", "block": "Y"} + # try: + # r = requests.get( + # f"{carte}/kettle/executeJob/", + # params=params, + # auth=("cluster", "cluster"), + # timeout=900, + # ) + # r.raise_for_status() + # # kalau Carte mengembalikan <result>ERROR</result>, anggap gagal + # if "<result>ERROR</result>" in r.text: + # raise UserError(f"Carte error: {r.text}") + # except Exception as e: + # _logger.exception("Carte call failed: %s", e) + # raise UserError(f"Gagal memanggil Carte: {e}") + + # time.sleep(3) + + # self.env['sj.tele'].sudo().woi() + + # return True + + def woi(self): + bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' + chat_id_mqdd = '-4885333032' + api_base = f'https://api.telegram.org/bot{bot_mqdd}' + + data = self.search([], order='create_date asc', limit=15) + + if not data: + text = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\nā
tidak ada data (semua sudah tercatat)." + try: + r = requests.post(api_base + "/sendMessage", + json={'chat_id': chat_id_mqdd, 'text': text}, + timeout=20) + r.raise_for_status() + except Exception as e: + _logger.exception("Gagal kirim Telegram (no data): %s", e) + return True + + + lines = [] + groups = OrderedDict() + + for rec in data: + name = rec.picking_name or (rec.picking_id.name if rec.picking_id else '') + pid = rec.picking_id.id if rec.picking_id else '' + so = rec.sale_id.name or rec.sale_name or '' + dttm = (rec.picking_id.date_doc_kirim if (rec.picking_id and rec.picking_id.date_doc_kirim) + else getattr(rec, 'date_doc_kirim', None)) + + # format header tanggal (string), tanpa konversi Waktu/WIB + if dttm: + date_header = dttm if isinstance(dttm, str) else fields.Datetime.to_string(dttm) + date_header = date_header[:10] + else: + date_header = '(Tidak ada tanggal kirim SJ)' + + if name: + groups.setdefault(date_header, []).append(f"- ({pid}) - {name} - {so}") + + # build output berurutan per tanggal + for header_date, items in groups.items(): + lines.append(header_date) + lines.extend(items) + + + header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n" + text = header + "\n".join(lines) + + try: + r = requests.post(api_base + "/sendMessage", + json={'chat_id': chat_id_mqdd, 'text': text}) + r.raise_for_status() + except Exception as e: + _logger.exception("Gagal kirim Telegram: %s", e) + return True
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 3a320510..0d2789b3 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -195,4 +195,5 @@ access_tukar_guling_mapping_koli_all_users,tukar.guling.mapping.koli.all.users,m access_purchase_order_update_date_wizard,access.purchase.order.update.date.wizard,model_purchase_order_update_date_wizard,base.group_user,1,1,1,1 access_sync_promise_date_wizard,access.sync.promise.date.wizard,model_sync_promise_date_wizard,base.group_user,1,1,1,1 access_sync_promise_date_wizard_line,access.sync.promise.date.wizard.line,model_sync_promise_date_wizard_line,base.group_user,1,1,1,1 -access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1
\ No newline at end of file +access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1 +access_sj_tele,access.sj.tele,model_sj_tele,base.group_system,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/report_logbook_sj.xml b/indoteknik_custom/views/report_logbook_sj.xml index 2b7cfa22..14bfecfb 100644 --- a/indoteknik_custom/views/report_logbook_sj.xml +++ b/indoteknik_custom/views/report_logbook_sj.xml @@ -12,9 +12,10 @@ <field name="date_approve"/> <field name="approve_by_finance"/> <field name="state"/> + </tree> </field> - </record> + </record> <record id="report_logbook_sj_line_tree" model="ir.ui.view"> <field name="name">report.logbook.sj.line.tree</field> @@ -44,50 +45,48 @@ <field name="arch" type="xml"> <form> <header> - <button name="approve" - string="Validate" - type="object" - /> + <button name="approve" string="Validate" type="object" /> + <button name="action_send_to_telegram" string="Kirim ke Telegram" type="object" /> </header> <sheet string="Report logbook SJ"> - <div class="oe_button_box" name="button_box"/> + <div class="oe_button_box" name="button_box"/> + <group> <group> - <group> - <field name="name" readonly="1"/> - <field name="date" readonly="1"/> - <field name="date_approve" readonly="1"/> - </group> - <group> - <field name="approve_by_finance" readonly="1"/> - <field name="state" readonly="1"/> - <field name="created_by" readonly="1"/> - <field name="approve_by" readonly="1"/> - <field name="count_line" readonly="1"/> - </group> + <field name="name" readonly="1"/> + <field name="date" readonly="1"/> + <field name="date_approve" readonly="1"/> </group> - <notebook> - <page string="Line"> - <field name="report_logbook_sj_line"/> - </page> - </notebook> - </sheet> - <div class="oe_chatter"> - <field name="message_follower_ids" widget="mail_followers"/> - <field name="message_ids" widget="mail_thread"/> - </div> + <group> + <field name="approve_by_finance" readonly="1"/> + <field name="state" readonly="1"/> + <field name="created_by" readonly="1"/> + <field name="approve_by" readonly="1"/> + <field name="count_line" readonly="1"/> + </group> + </group> + <notebook> + <page string="Line"> + <field name="report_logbook_sj_line"/> + </page> + </notebook> + </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> </form> </field> </record> <record id="report_logbook_sj_view_search" model="ir.ui.view"> - <field name="name">report.logbook.sj.search.view</field> <!-- Made the name more descriptive --> - <field name="model">report.logbook.sj</field> - <field name="arch" type="xml"> - <search string="Search Report"> - <field name="sj_number"/> - </search> - </field> - </record> + <field name="name">report.logbook.sj.search.view</field> <!-- Made the name more descriptive --> + <field name="model">report.logbook.sj</field> + <field name="arch" type="xml"> + <search string="Search Report"> + <field name="sj_number"/> + </search> + </field> + </record> <record id="report_logbook_sj_action" model="ir.actions.act_window"> <field name="name">Report Logbook SJ</field> @@ -96,9 +95,19 @@ <field name="view_mode">tree,form</field> </record> - <menuitem id="menu_report_logbook_sj" - name="Report Logbook SJ" - action="report_logbook_sj_action" - parent="account.menu_finance_reports" - sequence="200"/> + <menuitem id="menu_report_logbook_sj" name="Report Logbook SJ" action="report_logbook_sj_action" parent="account.menu_finance_reports" sequence="200"/> + + <data noupdate="1"> + <record id="cron_daily_logbook_gap_to_telegram" model="ir.cron"> + <field name="name">Daily Logbook SJ Gap ā Telegram</field> + <field name="model_id" ref="model_report_logbook_sj"/> + <field name="state">code</field> + <field name="code">model.cron_daily_logbook_gap_to_telegram()</field> + <field name="interval_number">1</field> + <field name="interval_type">days</field> + <field name="numbercall">-1</field> + <field name="user_id" ref="base.user_root"/> + <field name="active">False</field> + </record> + </data> </odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/sj_tele.xml b/indoteknik_custom/views/sj_tele.xml new file mode 100644 index 00000000..cefcc968 --- /dev/null +++ b/indoteknik_custom/views/sj_tele.xml @@ -0,0 +1,15 @@ +<odoo> + <data noupdate="1"> + <record id="woi" model="ir.cron"> + <field name="name">SJ TELE</field> + <field name="model_id" ref="model_sj_tele"/> + <field name="state">code</field> + <field name="code">model.woi()</field> + <field name="interval_number">1</field> + <field name="interval_type">days</field> + <field name="numbercall">-1</field> + <field name="user_id" ref="base.user_root"/> + <field name="active">False</field> + </record> + </data> +</odoo>
\ No newline at end of file |
