summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-01-14 18:55:22 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-01-14 18:55:22 +0700
commite1c687df876eaa970cb40393cb4443abcfbd0b77 (patch)
treef0eafc1c33808c2fa1bb9fac680509331eee6069
parentf77738e0c20c01a544dc233c12c1233793b45180 (diff)
<Miqdad>add cron notification
-rw-r--r--indoteknik_custom/models/gudang_service.py50
-rw-r--r--indoteknik_custom/views/gudang_service.xml11
2 files changed, 48 insertions, 13 deletions
diff --git a/indoteknik_custom/models/gudang_service.py b/indoteknik_custom/models/gudang_service.py
index d9b32e91..6944f169 100644
--- a/indoteknik_custom/models/gudang_service.py
+++ b/indoteknik_custom/models/gudang_service.py
@@ -19,22 +19,45 @@ class GudangService(models.Model):
remaining_date = fields.Char('Remaining Date', compute='_compute_remaining_date')
state = fields.Selection([('draft', 'Draft'), ('onprogress', 'On Progress'),('done', 'Done'), ('cancel', 'Cancel')], default='draft')
- def _compute_remaining_date(self):
- if self.state in ['done', 'cancel', 'draft']:
+ def _send_logistic_notification(self):
+ logistic_user = self.env.user.has_group('indoteknik_custom.group_role_logistic')
+
+ if not logistic_user:
return
+
for rec in self:
- if rec.date:
- rec.remaining_date = (datetime.now() - rec.date).days
+ for user in logistic_user:
+ self.env['mail.activity'].create({
+ 'res_model_id': self.env['ir.model']._get_id('gudang.service'),
+ 'res_id': rec.id,
+ 'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
+ 'user_id': user.id,
+ 'summary': 'Gudang Service On Progress',
+ 'note': _(
+ 'Gudang Service <b>%s</b> masih <b>On Progress</b> sejak %s'
+ ) % (rec.name, rec.date),
+ 'date_deadline': fields.Date.today(),
+ })
+
+ @api.model
+ def cron_notify_onprogress_gudang_service(self):
+ records = self.search([
+ ('state', '=', 'onprogress')
+ ])
+
+ if records:
+ records._send_logistic_notification()
+
+
+ @api.depends('date', 'state')
+ def _compute_remaining_date(self):
+ today = fields.Date.today()
+ for rec in self:
+ if rec.state in ['done', 'cancel', 'draft'] or not rec.date:
+ rec.remaining_date = 0
+ continue
+ rec.remaining_date = (today - rec.date.date()).days
- def send_odoo_notification(self):
- return {
- 'type': 'ir.actions.act_window',
- 'res_model': 'mail.message',
- 'view_mode': 'form',
- 'view_type': 'form',
- 'res_id': self.message_ids[-1].id,
- }
-
def action_submit(self):
self.state = 'onprogress'
# self.send_odoo_notification()
@@ -50,6 +73,7 @@ class GudangService(models.Model):
record.write({'state': 'draft'})
else:
raise UserError("Hanya record yang di-cancel yang bisa dikembalikan ke draft")
+
def action_cancel(self):
self.state = 'cancel'
diff --git a/indoteknik_custom/views/gudang_service.xml b/indoteknik_custom/views/gudang_service.xml
index ada1291b..97bb0227 100644
--- a/indoteknik_custom/views/gudang_service.xml
+++ b/indoteknik_custom/views/gudang_service.xml
@@ -81,4 +81,15 @@
action="action_gudang_service"
/>
</data>
+ <!-- Cron -->
+ <record id="ir_cron_gudang_service_logistik_notify" model="ir.cron">
+ <field name="name">Gudang Service Daily Notification</field>
+ <field name="model_id" ref="model_gudang_service"/>
+ <field name="state">code</field>
+ <field name="code">model.cron_notify_onprogress_gudang_service()</field>
+ <field name="interval_number">1</field>
+ <field name="interval_type">days</field>
+ <field name="numbercall">-1</field>
+ <field name="active">False</field>
+ </record>
</odoo>