summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-01-14 19:19:00 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-01-14 19:19:00 +0700
commit4e1e2f93b0788c020bd3f1c1f802cf2f53997de5 (patch)
treed387392699ea68a2a2ace7422a6cb7c302f061dd
parente1c687df876eaa970cb40393cb4443abcfbd0b77 (diff)
<Miqdad> fix cron notif & add option to get product from picking
-rw-r--r--indoteknik_custom/models/gudang_service.py36
-rw-r--r--indoteknik_custom/views/gudang_service.xml2
2 files changed, 27 insertions, 11 deletions
diff --git a/indoteknik_custom/models/gudang_service.py b/indoteknik_custom/models/gudang_service.py
index 6944f169..600febfd 100644
--- a/indoteknik_custom/models/gudang_service.py
+++ b/indoteknik_custom/models/gudang_service.py
@@ -13,20 +13,41 @@ class GudangService(models.Model):
name = fields.Char('Name', readonly=True)
partner_id = fields.Many2one('res.partner', string='Customer', readonly=True)
origin = fields.Many2one('sale.order', string='Origin SO')
- # picking_id = fields.Many2one('stock.picking', string = 'Picking ID')
+ picking_id = fields.Many2one('stock.picking', string = 'Picking ID', domain="[('sale_id', '=', origin)]")
date = fields.Datetime('Date', default=fields.Datetime.now, required=True)
gudang_service_lines = fields.One2many('gudang.service.line', 'gudang_service_id', string='Gudang Service Lines')
remaining_date = fields.Char('Remaining Date', compute='_compute_remaining_date')
state = fields.Selection([('draft', 'Draft'), ('onprogress', 'On Progress'),('done', 'Done'), ('cancel', 'Cancel')], default='draft')
+ @api.onchange('picking_id')
+ def _onchange_picking_id(self):
+ if not self.picking_id:
+ self.gudang_service_lines = [(5, 0, 0)]
+ return
+
+ lines = [(5, 0, 0)]
+ for move in self.picking_id.move_ids_without_package:
+ if move.product_id:
+ lines.append((0, 0, {
+ 'product_id': move.product_id.id,
+ 'quantity': move.product_uom_qty,
+ 'origin_so': self.origin.id,
+ }))
+
+ self.gudang_service_lines = lines
+
+
def _send_logistic_notification(self):
- logistic_user = self.env.user.has_group('indoteknik_custom.group_role_logistic')
+ group = self.env.ref('indoteknik_custom.group_role_logistic', raise_if_not_found=False)
+ if not group:
+ return
- if not logistic_user:
+ users = group.users
+ if not users:
return
for rec in self:
- for user in logistic_user:
+ for user in users:
self.env['mail.activity'].create({
'res_model_id': self.env['ir.model']._get_id('gudang.service'),
'res_id': rec.id,
@@ -60,6 +81,7 @@ class GudangService(models.Model):
def action_submit(self):
self.state = 'onprogress'
+ self._send_logistic_notification
# self.send_odoo_notification()
def action_done(self):
@@ -81,12 +103,6 @@ class GudangService(models.Model):
# self.send_odoo_notification()
# return super(GudangService, self).write(vals)
- @api.depends('date')
- def _compute_remaining_date(self):
- for rec in self:
- if rec.date:
- rec.remaining_date = (datetime.now() - rec.date).days
-
@api.model
def create(self, vals):
if not vals.get('name') or vals['name'] == 'New':
diff --git a/indoteknik_custom/views/gudang_service.xml b/indoteknik_custom/views/gudang_service.xml
index 97bb0227..8c681451 100644
--- a/indoteknik_custom/views/gudang_service.xml
+++ b/indoteknik_custom/views/gudang_service.xml
@@ -45,7 +45,7 @@
<group>
<field name="origin"/>
<field name="partner_id"/>
- <!-- <field name="picking_id"/> -->
+ <field name="picking_id"/>
<field name="date"/>
<field name="remaining_date"/>
<field name="create_uid"/>