summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorHafidBuroiroh <hafidburoiroh09@gmail.com>2025-11-04 15:24:27 +0700
committerHafidBuroiroh <hafidburoiroh09@gmail.com>2025-11-04 15:24:27 +0700
commit4f11653e57d4f2e4163b5ef69c0731a675a5e2bd (patch)
tree7ae1e6a43fe9c5d36a39655c301a7fb566a1e071 /indoteknik_custom/models
parent416823e12f3b76b440e504bf170c8c27c02caca3 (diff)
push
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py35
1 files changed, 33 insertions, 2 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):