diff options
| -rw-r--r-- | indoteknik_custom/models/purchasing_job.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py index 06985041..1c74f0e9 100644 --- a/indoteknik_custom/models/purchasing_job.py +++ b/indoteknik_custom/models/purchasing_job.py @@ -12,7 +12,7 @@ class PurchasingJob(models.Model): id = fields.Integer() product_id = fields.Many2one('product.product', string="Product") - vendor_id = fields.Many2one('res.partner', string="Vendor") + vendor_id = fields.Many2one('res.partner', string="Vendor", compute='compute_vendor_id') brand = fields.Char(string='Brand') item_code = fields.Char(string='Item Code') product = fields.Char(string='Product Name') @@ -25,6 +25,20 @@ class PurchasingJob(models.Model): ('apo', 'APO') ], string='APO?') + def compute_vendor_id(self): + for sale in self: + domain = [ + ('product_id', '=', sale.product_id.id) + ] + sales = self.env['v.sales.outstanding'].search(domain) + + vendor_id = False + + if sales: + vendor_id = sales[0].sale_line_id.vendor_id.id + + sale.vendor_id = vendor_id + def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" @@ -39,12 +53,9 @@ class PurchasingJob(models.Model): pmp.incoming, pmp.outgoing, pmp.action, - pjs.status_apo AS status_apo, - sol.vendor_id AS vendor_id + pjs.status_apo AS status_apo FROM v_procurement_monitoring_by_product pmp LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id - LEFT JOIN v_sales_outstanding so ON so.product_id = pmp.product_id - LEFT JOIN sale_order_line sol ON so.sale_line_id = sol.id WHERE pmp.action = 'kurang' ) """ % self._table) |
