summaryrefslogtreecommitdiff
path: root/fixco_custom/models/purchasing_job.py
diff options
context:
space:
mode:
Diffstat (limited to 'fixco_custom/models/purchasing_job.py')
-rw-r--r--fixco_custom/models/purchasing_job.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/fixco_custom/models/purchasing_job.py b/fixco_custom/models/purchasing_job.py
index 4f301f9..1af47b7 100644
--- a/fixco_custom/models/purchasing_job.py
+++ b/fixco_custom/models/purchasing_job.py
@@ -54,7 +54,6 @@ class PurchasingJob(models.Model):
'partner_id': stock.vendor_id.id,
'taxes_id': stock.vendor_id.tax_id.id if stock.vendor_id.tax_id else False,
'price': price,
- 'subtotal': subtotal,
})
self.env['automatic.purchase.line'].create(lines_to_create)
@@ -71,43 +70,49 @@ class PurchasingJob(models.Model):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""
CREATE OR REPLACE VIEW %s AS
- SELECT
- row_number() OVER () AS id,
- a.item_code,
- a.product,
- a.onhand,
- a.incoming,
- a.outgoing,
- CASE
- WHEN (a.incoming + a.onhand) < a.outgoing THEN 'kurang'
- ELSE 'cukup'
- END AS action,
- a.product_id,
- pp2.vendor_id
- FROM (
- SELECT
- COALESCE(pp.default_code, pt.default_code) AS item_code,
- pt.name AS product,
- get_qty_onhand(pp.id::numeric) AS onhand,
- get_qty_incoming(pp.id::numeric) AS incoming,
- get_qty_outgoing(pp.id::numeric) AS outgoing,
- pp.id AS product_id
- FROM stock_move sm
- JOIN stock_picking sp ON sp.id = sm.picking_id
- JOIN product_product pp ON pp.id = sm.product_id
- JOIN product_template pt ON pt.id = pp.product_tmpl_id
- WHERE sp.state IN ('draft', 'waiting', 'confirmed', 'assigned')
- AND sp.name LIKE '%%OUT%%'
- AND sm.location_id = 55
- GROUP BY pp.id, pp.default_code, pt.default_code, pt.name
- ) a
- LEFT JOIN LATERAL (
- SELECT vendor_id
- FROM purchase_pricelist
- WHERE product_id = a.product_id
- ORDER BY id ASC
- LIMIT 1
- ) pp2 ON true
+ SELECT * FROM (
+ SELECT
+ row_number() OVER () AS id,
+ a.item_code,
+ a.product,
+ a.onhand,
+ a.incoming,
+ a.outgoing,
+ CASE
+ WHEN (a.incoming + a.onhand) < a.outgoing THEN 'kurang'
+ ELSE 'cukup'
+ END AS action,
+ a.product_id,
+ pp2.vendor_id
+ FROM (
+ SELECT
+ COALESCE(pp.default_code, pt.default_code) AS item_code,
+ pt.name AS product,
+ get_qty_onhand(pp.id::numeric) AS onhand,
+ get_qty_incoming(pp.id::numeric) AS incoming,
+ get_qty_outgoing(pp.id::numeric) AS outgoing,
+ pp.id AS product_id
+ FROM stock_move sm
+ JOIN stock_picking sp ON sp.id = sm.picking_id
+ JOIN product_product pp ON pp.id = sm.product_id
+ JOIN product_template pt ON pt.id = pp.product_tmpl_id
+ WHERE sp.state IN ('draft', 'waiting', 'confirmed', 'assigned')
+ AND sp.name LIKE '%%OUT%%'
+ AND sm.location_id = 55
+ GROUP BY pp.id, pp.default_code, pt.default_code, pt.name
+ ) a
+ LEFT JOIN LATERAL (
+ SELECT vendor_id
+ FROM purchase_pricelist
+ WHERE product_id = a.product_id
+ ORDER BY id ASC
+ LIMIT 1
+ ) pp2 ON true
+ ) final
+ WHERE final.action = 'kurang'
""" % self._table)
+ super(PurchasingJob, self).init()
+
+