From 4f11653e57d4f2e4163b5ef69c0731a675a5e2bd Mon Sep 17 00:00:00 2001 From: HafidBuroiroh Date: Tue, 4 Nov 2025 15:24:27 +0700 Subject: push --- indoteknik_custom/models/sourcing_job_order.py | 35 ++++++++++++++++++++++++-- indoteknik_custom/views/sourcing.xml | 20 ++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py index 7b6f6569..cc80d684 100644 --- a/indoteknik_custom/models/sourcing_job_order.py +++ b/indoteknik_custom/models/sourcing_job_order.py @@ -1,5 +1,7 @@ from odoo import models, fields, api, _ from odoo.exceptions import UserError +from datetime import date, datetime +import requests import logging _logger = logging.getLogger(__name__) @@ -14,6 +16,8 @@ class SourcingJobOrder(models.Model): name = fields.Char(string='Job Number', default='New', copy=False, readonly=True) leads_id = fields.Many2one('crm.lead', string='Leads Number') user_id = fields.Many2one('res.users', string='MD Person', tracking=True) + so_id = fields.Many2one('sale.order', string='SO Number', tracking=True, required=True) + product_assets_filename = fields.Char(string="Nama File PDF") state = fields.Selection([ ('draft', 'Untaken'), ('taken', 'On Sourcing'), @@ -164,6 +168,10 @@ class SourcingJobOrder(models.Model): vals['state'] = 'taken' rec = super().create(vals) + + if vals.get('product_assets'): + rec._log_product_assets_upload() + return rec def write(self, vals): @@ -213,6 +221,9 @@ class SourcingJobOrder(models.Model): } res = super().write(vals) + if vals.get('product_assets'): + for rec in self: + rec._log_product_assets_upload() # --- Bandingkan setelah write dan buat log for rec in self: @@ -520,7 +531,6 @@ class SourcingJobOrder(models.Model): raise UserError("❌ Hanya Pembuat Sourcing Job ini yang dapat Confirm Approval.") rec.approval_sales = 'approve' - rec.state = 'done' rec.activity_feedback(['mail.mail_activity_data_todo']) @@ -570,7 +580,8 @@ class SourcingJobOrder(models.Model): def action_send_untaken_to_telegram(self): bot_sjo = '8335015210:AAGbObP0jQf7ptyqJhYdBYn5Rm0CWOd_yIM' - chat_sjo = '-5081839952' + # chat_group_sjo = '-5081839952' + chat_sjo = '6076436058' api_base = f'https://api.telegram.org/bot{bot_sjo}' data = self.search([('state', '=', 'draft')], order='create_date asc') @@ -596,6 +607,26 @@ class SourcingJobOrder(models.Model): _logger.error(f"⚠️ Error while sending Telegram message: {str(e)}") return True + + def _log_product_assets_upload(self): + """Tambahkan log note otomatis saat file PDF diunggah""" + if self.product_assets: + # Buat attachment dari file biner + attachment = self.env['ir.attachment'].create({ + 'name': self.product_assets_filename or 'SJO_Assets.pdf', + 'type': 'binary', + 'datas': self.product_assets, + 'res_model': self._name, + 'res_id': self.id, + 'mimetype': 'application/pdf', + }) + + # Tambahkan log note ke chatter dengan attachment + self.message_post( + body=_("SJO ini memiliki Dokumen yang diupload."), + attachment_ids=[attachment.id], + subtype_xmlid='mail.mt_note' + ) class SourcingJobOrderLine(models.Model): diff --git a/indoteknik_custom/views/sourcing.xml b/indoteknik_custom/views/sourcing.xml index f7e04f04..582a1b3f 100644 --- a/indoteknik_custom/views/sourcing.xml +++ b/indoteknik_custom/views/sourcing.xml @@ -100,6 +100,13 @@ groups="indoteknik_custom.group_role_merchandiser" attrs="{'invisible': [('can_convert_to_product', '=', False)]}"/> +