summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_custom/models/sourcing_job_order.py35
-rw-r--r--indoteknik_custom/views/sourcing.xml20
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)]}"/>
+ <button name="action_reject_by_sales"
+ string="Reject Approval"
+ type="object"
+ class="btn-danger"
+ groups="indoteknik_custom.group_role_sales"
+ attrs="{'invisible': [('approval_sales', 'in', [False, 'approve'])]}"/>
+
<button name="action_reject_takeover"
string="Reject Takeover"
type="object"
@@ -139,6 +146,7 @@
<group>
<!-- <field name="leads_id"/> -->
<field name="eta_sales"/>
+ <field name="so_id"/>
<field name="is_creator_same_user" invisible="1"/>
<field name="takeover_request" invisible="1"/>
<field name="can_request_takeover" invisible="1"/>
@@ -230,7 +238,7 @@
</page>
<page string="Documents">
- <field name="product_assets" widget="pdf_viewer"/>
+ <field name="product_assets" widget="pdf_viewer" filename="product_assets_filename"/>
</page>
<page string="Cancel Reason" attrs="{'invisible': [('state', 'in', ['done'])]}">
@@ -259,6 +267,16 @@
<field name="groups_id" eval="[(4, ref('indoteknik_custom.group_role_merchandiser'))]"/>
</record>
+ <record id="action_sourcing_job_order_send_untaken_telegram" model="ir.actions.server">
+ <field name="name">Send Untaken SJO to Telegram</field>
+ <field name="model_id" ref="model_sourcing_job_order"/>
+ <field name="binding_model_id" ref="model_sourcing_job_order"/>
+ <field name="binding_type">action</field>
+ <field name="state">code</field>
+ <field name="code">action = records.action_send_untaken_to_telegram()</field>
+ <field name="groups_id" eval="[(4, ref('indoteknik_custom.group_role_merchandiser'))]"/>
+ </record>
+
<record id="action_sourcing_job_order" model="ir.actions.act_window">
<field name="name">Sourcing Job Orders</field>
<field name="res_model">sourcing.job.order</field>