summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-07-22 10:54:44 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-07-22 10:54:44 +0700
commit87f38f9fcb68f04a2cc8157744622c2d0ebf1eab (patch)
treeb7718dd2159cea7e91f2181a5690296c178f7c02
parent946e4b76e8280daad6d4849e9ced33a54d770a84 (diff)
notif open purchasing job
-rw-r--r--indoteknik_custom/models/purchasing_job.py55
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/purchasing_job.xml10
3 files changed, 64 insertions, 2 deletions
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index 58f1c067..db733b5a 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -26,7 +26,46 @@ class PurchasingJob(models.Model):
purchase_representative_id = fields.Many2one('res.users', string="Purchase Representative", readonly=True)
note = fields.Char(string="Note Detail")
date_po = fields.Datetime(string='Date PO', copy=False)
- so_number = fields.Char(string='SO Number', copy=False)
+ so_number = fields.Text(string='SO Number', copy=False)
+ check_pj = fields.Boolean(compute='_get_check_pj', string='Linked')
+
+ def action_open_job_detail(self):
+ self.ensure_one()
+ Seen = self.env['purchasing.job.seen']
+ seen = Seen.search([
+ ('user_id', '=', self.env.uid),
+ ('product_id', '=', self.product_id.id)
+ ], limit=1)
+
+ if seen:
+ seen.so_snapshot = self.so_number
+ seen.seen_date = fields.Datetime.now()
+ else:
+ Seen.create({
+ 'user_id': self.env.uid,
+ 'product_id': self.product_id.id,
+ 'so_snapshot': self.so_number,
+ })
+
+ return {
+ 'name': 'Purchasing Job Detail',
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'v.purchasing.job',
+ 'res_id': self.id,
+ 'view_mode': 'form',
+ 'target': 'current',
+ }
+
+
+ @api.depends('so_number')
+ def _get_check_pj(self):
+ for rec in self:
+ seen = self.env['purchasing.job.seen'].search([
+ ('user_id', '=', self.env.uid),
+ ('product_id', '=', rec.product_id.id)
+ ], limit=1)
+ rec.check_pj = bool(seen and seen.so_snapshot == rec.so_number)
+
def unlink(self):
# Example: Delete related records from the underlying model
@@ -199,3 +238,17 @@ class OutstandingSales(models.Model):
and sp.name like '%OUT%'
)
""")
+
+class PurchasingJobSeen(models.Model):
+ _name = 'purchasing.job.seen'
+ _description = 'User Seen SO Snapshot'
+ _rec_name = 'product_id'
+
+ user_id = fields.Many2one('res.users', required=True, ondelete='cascade')
+ product_id = fields.Many2one('product.product', required=True, ondelete='cascade')
+ so_snapshot = fields.Text("Last Seen SO")
+ seen_date = fields.Datetime(default=fields.Datetime.now)
+
+ _sql_constraints = [
+ ('user_product_unique', 'unique(user_id, product_id)', 'User already tracked this product.')
+ ]
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 2b970cfd..dd00c5ad 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -183,3 +183,4 @@ access_production_purchase_match,access.production.purchase.match,model_producti
access_image_carousel,access.image.carousel,model_image_carousel,,1,1,1,1
access_v_sale_notin_matchpo,access.v.sale.notin.matchpo,model_v_sale_notin_matchpo,,1,1,1,1
access_approval_payment_term,access.approval.payment.term,model_approval_payment_term,,1,1,1,1
+access_purchasing_job_seen,purchasing.job.seen,model_purchasing_job_seen,,1,1,1,1
diff --git a/indoteknik_custom/views/purchasing_job.xml b/indoteknik_custom/views/purchasing_job.xml
index 976f1485..e3866d84 100644
--- a/indoteknik_custom/views/purchasing_job.xml
+++ b/indoteknik_custom/views/purchasing_job.xml
@@ -4,7 +4,7 @@
<field name="name">v.purchasing.job.tree</field>
<field name="model">v.purchasing.job</field>
<field name="arch" type="xml">
- <tree create="false" multi_edit="1">
+ <tree decoration-info="(check_pj == False)" create="false" multi_edit="1">
<field name="product_id"/>
<field name="vendor_id"/>
<field name="purchase_representative_id"/>
@@ -19,6 +19,14 @@
<field name="note"/>
<field name="date_po"/>
<field name="so_number"/>
+ <field name="check_pj" invisible="1"/>
+ <button name="action_open_job_detail"
+ string="📄"
+ type="object"
+ icon="fa-file"
+ attrs="{'invisible': [('check_pj','=',True)]}"
+ context="{}"/>
+
</tree>
</field>
</record>