diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-03 09:52:05 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-04-03 09:52:05 +0700 |
| commit | e3875c149ba913582a3fe28a31003e8332a7893e (patch) | |
| tree | 7538b3ac1d462e347cda3d136e889a0ac686c910 /indoteknik_custom/models/purchasing_job.py | |
| parent | b559bcdf167ba24cbbcf978461fb774e8eda2f07 (diff) | |
add filter user_id and fix responsible on automatic purchase
Diffstat (limited to 'indoteknik_custom/models/purchasing_job.py')
| -rw-r--r-- | indoteknik_custom/models/purchasing_job.py | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 1bbf68e3..6276d554 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -23,7 +23,7 @@ class PurchasingJob(models.Model): ('not_apo', 'Belum APO'), ('apo', 'APO') ], string='APO?') - purchase_representative_id = fields.Many2one('res.users', string="Purchase Representative", readonly=True, compute='compute_purchase_representative') + purchase_representative_id = fields.Many2one('res.users', string="Purchase Representative", readonly=True) note = fields.Char(string="Note Detail") def redirect_to_pjs(self): @@ -40,24 +40,18 @@ class PurchasingJob(models.Model): 'res_id': states.id, } - def compute_purchase_representative(self): - for rec in self: - po = self.env['purchase.order'].search([ - ('order_line.product_id', '=', rec.product_id.id), - ('user_id', '!=', False) - ], limit=1, order='id desc') - - user_id = False - - if po: - user_id = po.user_id - - rec.purchase_representative_id = user_id - def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" CREATE OR REPLACE VIEW %s AS ( + WITH latest_purchase_orders AS ( + SELECT + pol.product_id, + po.user_id, + ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank + FROM purchase_order po + RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id + ) SELECT pmp.product_id AS id, pmp.product_id, @@ -70,7 +64,8 @@ class PurchasingJob(models.Model): MAX(pmp.outgoing) AS outgoing, pmp.action, MAX(pjs.status_apo) AS status_apo, - MAX(pjs.note) AS note + MAX(pjs.note) AS note, + MAX(po.user_id) AS purchase_representative_id FROM v_procurement_monitoring_by_product pmp LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id LEFT JOIN ( @@ -81,8 +76,9 @@ class PurchasingJob(models.Model): LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id LEFT JOIN res_partner rp ON rp.id = sol.vendor_id ) AS sub ON sub.product_id = pmp.product_id + LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id AND po.order_rank = 1 WHERE pmp.action = 'kurang' - AND sub.vendor_id <> 1 + AND sub.vendor_id <> 1 GROUP BY pmp.product_id, pmp.brand, @@ -90,7 +86,7 @@ class PurchasingJob(models.Model): pmp.product, pmp.action, sub.vendor_id - ) + ) """ % self._table) |
