[IMP] Only check pickings of purchases when state goes to done and optimize query
bzr revid: jco@openerp.com-20140224134126-jmk38b3gxtvbh1ru
This commit is contained in:
parent
18b02ee71e
commit
ed978bb905
|
@ -31,6 +31,7 @@ import openerp.addons.decimal_precision as dp
|
||||||
from openerp.osv.orm import browse_record, browse_null
|
from openerp.osv.orm import browse_record, browse_null
|
||||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP
|
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP
|
||||||
|
|
||||||
|
|
||||||
class purchase_order(osv.osv):
|
class purchase_order(osv.osv):
|
||||||
|
|
||||||
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
|
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||||
|
@ -155,12 +156,19 @@ class purchase_order(osv.osv):
|
||||||
|
|
||||||
def _get_picking_ids(self, cr, uid, ids, field_names, args, context=None):
|
def _get_picking_ids(self, cr, uid, ids, field_names, args, context=None):
|
||||||
res = {}
|
res = {}
|
||||||
for purchase_id in ids:
|
query = """
|
||||||
picking_ids = set()
|
SELECT picking_id, po.id FROM stock_picking p, stock_move m, purchase_order_line pol, purchase_order po
|
||||||
move_ids = self.pool.get('stock.move').search(cr, uid, [('purchase_line_id.order_id', '=', purchase_id)], context=context)
|
WHERE po.id in %s and po.id = pol.order_id and pol.id = m.purchase_line_id and m.picking_id = p.id
|
||||||
for move in self.pool.get('stock.move').browse(cr, uid, move_ids, context=context):
|
GROUP BY picking_id, po.id
|
||||||
picking_ids.add(move.picking_id.id)
|
|
||||||
res[purchase_id] = list(picking_ids)
|
"""
|
||||||
|
cr.execute(query, (tuple(ids), ))
|
||||||
|
picks = cr.fetchall()
|
||||||
|
for pick in picks:
|
||||||
|
if not res.get(pick[1]):
|
||||||
|
res[pick[1]] = [pick[0]]
|
||||||
|
else:
|
||||||
|
res[pick[1]].append(pick[0])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
STATE_SELECTION = [
|
STATE_SELECTION = [
|
||||||
|
|
|
@ -35,7 +35,7 @@ class stock_move(osv.osv):
|
||||||
ids = [ids]
|
ids = [ids]
|
||||||
res = super(stock_move, self).write(cr, uid, ids, vals, context=context)
|
res = super(stock_move, self).write(cr, uid, ids, vals, context=context)
|
||||||
from openerp import workflow
|
from openerp import workflow
|
||||||
if 'state' in vals:
|
if 'state' in vals and vals['state'] in ['done', 'cancel']:
|
||||||
for move in self.browse(cr, uid, ids, context=context):
|
for move in self.browse(cr, uid, ids, context=context):
|
||||||
if move.purchase_line_id and move.purchase_line_id.order_id:
|
if move.purchase_line_id and move.purchase_line_id.order_id:
|
||||||
order_id = move.purchase_line_id.order_id.id
|
order_id = move.purchase_line_id.order_id.id
|
||||||
|
|
|
@ -1488,11 +1488,12 @@ class stock_move(osv.osv):
|
||||||
if move.product_id.uom_id.category_id.id != move.product_uom.category_id.id:
|
if move.product_id.uom_id.category_id.id != move.product_uom.category_id.id:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
_constraints = [
|
_constraints = [
|
||||||
(_check_uom,
|
(_check_uom,
|
||||||
'You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.',
|
'You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.',
|
||||||
['product_uom'])]
|
['product_uom'])]
|
||||||
|
|
||||||
|
|
||||||
def copy_data(self, cr, uid, id, default=None, context=None):
|
def copy_data(self, cr, uid, id, default=None, context=None):
|
||||||
if default is None:
|
if default is None:
|
||||||
|
|
Loading…
Reference in New Issue