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 | |
| parent | b559bcdf167ba24cbbcf978461fb774e8eda2f07 (diff) | |
add filter user_id and fix responsible on automatic purchase
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 7 | ||||
| -rw-r--r-- | indoteknik_custom/models/purchasing_job.py | 32 | ||||
| -rw-r--r-- | indoteknik_custom/views/purchasing_job.xml | 1 |
3 files changed, 22 insertions, 18 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index 2e080bcf..9b5cd01d 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -30,6 +30,13 @@ class AutomaticPurchase(models.Model): total_qty_line = fields.Float(string='Total Qty Line', compute='_compute_total_qty') total_qty_so = fields.Float(string='Total Qty SO', compute='_compute_total_qty') + @api.onchange('apo_type') + def onchange_apo_type(self): + if self.apo_type == 'reordering': + self.responsible_id = 19 + else: + self.responsible_id = self.env.user.id + def _compute_total_qty(self): for data in self: qty_line = qty_so = 0 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) diff --git a/indoteknik_custom/views/purchasing_job.xml b/indoteknik_custom/views/purchasing_job.xml index 8f9be1de..2fe343b4 100644 --- a/indoteknik_custom/views/purchasing_job.xml +++ b/indoteknik_custom/views/purchasing_job.xml @@ -64,6 +64,7 @@ <field name="item_code"/> <field name="brand"/> <field name="vendor_id"/> + <field name="user_id"/> </search> </field> </record> |
