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

« back to all changes in this revision

Viewing changes to stock_override/stock.py

  • Committer: Quentin THEURET
  • Date: 2016-02-12 13:09:26 UTC
  • Revision ID: qt@tempo-consulting.fr-20160212130926-mevui4okzh5tyg50
[IMP] Use sql statement instead of ORM search - Also modify a condition to do not write move if not necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1151
1151
            context = {}
1152
1152
        move_obj = self.pool.get('stock.move')
1153
1153
        if not context.get('already_checked'):
1154
 
            for pick in self.browse(cr, uid, ids, context=context):
 
1154
            cr.execute('''
 
1155
                SELECT m.id AS id FROM
 
1156
                  stock_move m
 
1157
                LEFT JOIN
 
1158
                  product_product pp
 
1159
                  ON pp.id = m.product_id
 
1160
                WHERE pp.perishable = 't'
 
1161
                AND m.picking_id in %s
 
1162
            ''', (tuple(ids), ))
 
1163
            move_ids = [x[0] for x in cr.fetchall()]
 
1164
            #move_ids = self.pool.get('stock.move').search(cr, uid, [
 
1165
            #    ('product_id.perishable', '=', True),
 
1166
            #    ('picking_id', 'in', ids),
 
1167
            #], context=context)
 
1168
            #for pick in self.browse(cr, uid, ids, context=context):
1155
1169
                # perishable for perishable or batch management
1156
 
                move_obj.fefo_update(cr, uid, [move.id for move in pick.move_lines if move.product_id.perishable], context)  # FEFO
 
1170
            move_obj.fefo_update(cr, uid, move_ids, context)  # FEFO
1157
1171
        context['already_checked'] = True
1158
1172
        return super(stock_picking, self)._hook_action_assign_batch(cr, uid, ids, context=context)
1159
1173
 
1706
1720
 
1707
1721
        loc_obj = self.pool.get('stock.location')
1708
1722
        prodlot_obj = self.pool.get('stock.production.lot')
 
1723
        compare_date = context.get('rw_date', False)
 
1724
        if compare_date:
 
1725
            compare_date = datetime.strptime(compare_date[0:10], '%Y-%m-%d')
 
1726
        else:
 
1727
            today = datetime.today()
 
1728
            compare_date = datetime(today.year, today.month, today.day)
 
1729
 
1709
1730
        for move in self.browse(cr, uid, ids, context):
1710
 
            compare_date = context.get('rw_date', False)
1711
1731
            move_unlinked = False
1712
 
            if compare_date:
1713
 
                compare_date = datetime.strptime(compare_date[0:10], '%Y-%m-%d')
1714
 
            else:
1715
 
                today = datetime.today()
1716
 
                compare_date = datetime(today.year, today.month, today.day)
1717
1732
            # FEFO logic
1718
1733
            if move.state == 'assigned' and not move.prodlot_id:  # a check_availability has already been done in action_assign, so we take only the 'assigned' lines
1719
1734
                needed_qty = move.product_qty
1784
1799
                            if not self.search(cr, uid, [('move_dest_id', '=',
1785
1800
                                move.id)], limit=1, order='NO_ORDER', context=context):
1786
1801
                                self.write(cr, uid, move.id, {'prodlot_id': False}, context)
1787
 
            elif move.state == 'confirmed':
 
1802
            elif move.state == 'confirmed' and move.prodlot_id:
1788
1803
                # we remove the prodlot_id in case that the move is not available
1789
1804
                self.write(cr, uid, move.id, {'prodlot_id': False}, context)
1790
1805
        return True