'This function returns quantity of product that needs to be deducted from the orderpoint computed quantity because there\'s already a procurement created with aim to fulfill it.'

@api.multi
def subtract_procurements_from_orderpoints(self):

    self._cr.execute("SELECT    orderpoint.id,    procurement.id,    procurement.product_uom,    procurement.product_qty,    template.uom_id,    move.product_qty\n                                                FROM    stock_warehouse_orderpoint    orderpoint\n                                                JOIN    procurement_order    AS    procurement    ON    procurement.orderpoint_id    =    orderpoint.id\n                                                JOIN    product_product    AS    product    ON    product.id    =    procurement.product_id\n                                                JOIN    product_template    AS    template    ON    template.id    =    product.product_tmpl_id\n                                                LEFT    JOIN    stock_move    AS    move    ON    move.procurement_id    =    procurement.id\n                                                WHERE    procurement.state    not    in    ('done',    'cancel')\n                                                                AND    (move.state    IS    NULL    OR    move.state    !=    'draft')\n                                                                AND    orderpoint.id    IN    %s\n                                                ORDER    BY    orderpoint.id,    procurement.id\n                                ", (tuple(self.ids),))
    UoM = self.env['product.uom']
    procurements_done = set()
    res = dict.fromkeys(self.ids, 0.0)
    for (orderpoint_id, procurement_id, product_uom_id, procurement_qty, template_uom_id, move_qty) in self._cr.fetchall():
        if (procurement_id not in procurements_done):
            procurements_done.add(procurement_id)
            res[orderpoint_id] += UoM.browse(product_uom_id)._compute_quantity(procurement_qty, UoM.browse(template_uom_id), round=False)
        if move_qty:
            res[orderpoint_id] -= move_qty
    return res
