summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/purchasing_job.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-07-28 15:09:55 +0700
commitd15ce4e186e2b77f01e8dfd03886298cc733d4c1 (patch)
tree1b32a4c29c4fcea85070fcecb5b77a7d55d30029 /indoteknik_custom/models/purchasing_job.py
parentdeba962d7368a5c4e30441b5a640102608e3dde6 (diff)
parent36a53535dbdc5777266fd9276b4c557259dab6be (diff)
<hafid> merging odoo-backup
Diffstat (limited to 'indoteknik_custom/models/purchasing_job.py')
-rw-r--r--indoteknik_custom/models/purchasing_job.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index ea2f46cb..db733b5a 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -26,6 +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.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
@@ -66,6 +106,7 @@ class PurchasingJob(models.Model):
max(pjs.status_apo::text) AS status_apo,
max(pjs.note::text) AS note,
max(pjs.date_po::text) AS date_po,
+ pmp.so_number,
CASE
WHEN pmp.brand IN ('Tekiro', 'RYU', 'Rexco', 'RYU (Sparepart)') THEN 27
WHEN sub.vendor_id = 9688 THEN 397
@@ -83,7 +124,7 @@ class PurchasingJob(models.Model):
group by vso.product_id
) sub ON sub.product_id = pmp.product_id
WHERE pmp.action = 'kurang'::text AND sub.vendor_id IS NOT NULL
- GROUP BY pmp.product_id, pmp.brand, pmp.item_code, pmp.product, pmp.action, sub.vendor_id;
+ GROUP BY pmp.product_id, pmp.brand, pmp.item_code, pmp.product, pmp.action, sub.vendor_id, pmp.so_number;
""" % self._table)
def open_form_multi_generate_request_po(self):
@@ -197,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.')
+ ]