~unifield-team/unifield-wm/improve-stock

« back to all changes in this revision

Viewing changes to kit/kit.py

  • Committer: Quentin THEURET
  • Date: 2016-02-12 10:24:09 UTC
  • Revision ID: qt@tempo-consulting.fr-20160212102409-w5zyu2v10v4pll35
[IMP] Use Product Stock availability on product_reserve method

Show diffs side-by-side

added added

removed removed

Lines of Context:
1435
1435
            # class report_stock_inventory(osv.osv): in specific_rules.py
1436
1436
            cr.execute("""
1437
1437
                        SELECT subs.product_uom, subs.prodlot_id, subs.expired_date, sum(subs.product_qty) AS product_qty FROM
1438
 
                            (SELECT product_uom, prodlot_id, expired_date, sum(product_qty) AS product_qty
1439
 
                                FROM stock_move
1440
 
                                WHERE location_dest_id=%s AND
1441
 
                                location_id<>%s AND
1442
 
                                product_id=%s AND
1443
 
                                state='done'
 
1438
                            (SELECT pt.uom_id AS product_uom, psa.prodlot_id, spl.life_date AS expired_date, sum(psa.quantity) AS product_qty
 
1439
                               FROM product_stock_availability psa
 
1440
                                LEFT JOIN product_product pp ON psa.id = pp.id
 
1441
                                LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
 
1442
                                LEFT JOIN stock_production_lot spl ON psa.prodlot_id = spl.id
 
1443
                                WHERE psa.location_id = %s AND
 
1444
                                      psa.product_id = %s
1444
1445
                                GROUP BY product_uom, prodlot_id, expired_date
1445
 
                            
 
1446
 
1446
1447
                                UNION
1447
1448
                            
1448
1449
                                SELECT product_uom, prodlot_id, expired_date, -sum(product_qty) AS product_qty
1450
1451
                                WHERE location_id=%s AND
1451
1452
                                location_dest_id<>%s AND
1452
1453
                                product_id=%s AND
1453
 
                                state in ('done', 'assigned')
 
1454
                                state in ('assigned')
1454
1455
                                GROUP BY product_uom, prodlot_id, expired_date) as subs
1455
1456
                        GROUP BY product_uom, prodlot_id, expired_date
1456
1457
                        ORDER BY prodlot_id asc, expired_date asc
1457
1458
                       """,
1458
 
                       (id, id, product_id, id, id, product_id))
 
1459
                       (id, product_id, id, id, product_id))
1459
1460
            results = cr.dictfetchall()
1460
1461
            # merge results according to uom if needed
1461
1462
            for r in results: