"""
prod_id = context and context.get('product_id', False)
+ if not prod_id:
+ return dict([(i, {}.fromkeys(field_names, 0.0)) for i in ids])
+
product_product_obj = self.pool.get('product.product')
cr.execute('select distinct product_id, location_id from stock_move where location_id in %s', (tuple(ids), ))
'state': fields.selection([
('draft', 'Draft'),
('auto', 'Waiting'),
- ('confirmed', 'Confirmed'),
- ('assigned', 'Available'),
+ ('confirmed', 'Waiting Availability'),
+ ('assigned', 'Ready to Process'),
('done', 'Done'),
('cancel', 'Cancelled'),
], 'State', readonly=True, select=True,
for pick in self.browse(cr, uid, ids, context=context):
if pick.state in ['done','cancel']:
raise osv.except_osv(_('Error'), _('You cannot remove the picking which is in %s state !')%(pick.state,))
- elif pick.state in ['confirmed','assigned', 'draft']:
+ else:
ids2 = [move.id for move in pick.move_lines]
ctx = context.copy()
ctx.update({'call_unlink':True})
move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
for move in complete:
if prodlot_ids.get(move.id):
- move_obj.write(cr, uid, move.id, {'prodlot_id': prodlot_ids[move.id]})
+ move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]})
for move in too_many:
product_qty = move_product_qty[move.id]
defaults = {
'assigned': _('is ready to process.'),
'cancel': _('is cancelled.'),
'done': _('is done.'),
- 'draft':_('is in draft state.'),
+ 'auto': _('is waiting.'),
+ 'draft': _('is in draft state.'),
}
res = data_obj.get_object_reference(cr, uid, 'stock', view_list.get(pick.type, 'view_picking_form'))
context.update({'view_id': res and res[1] or False})
'state': fields.selection([('draft', 'Draft'), ('waiting', 'Waiting'), ('confirmed', 'Not Available'), ('assigned', 'Available'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', readonly=True, select=True,
help='When the stock move is created it is in the \'Draft\' state.\n After that, it is set to \'Not Available\' state if the scheduler did not find the products.\n When products are reserved it is set to \'Available\'.\n When the picking is done the state is \'Done\'.\
\nThe state is \'Waiting\' if the move is waiting for another one.'),
- 'price_unit': fields.float('Unit Price', digits_compute= dp.get_precision('Account'), help="Technical field used to record the product cost set by the user during a picking confirmation (when average price costing method is used)"),
+ 'price_unit': fields.float('Unit Price', digits_compute= dp.get_precision('Purchase Price'), help="Technical field used to record the product cost set by the user during a picking confirmation (when average price costing method is used)"),
'price_currency_id': fields.many2one('res.currency', 'Currency for average price', help="Technical field used to record the currency chosen by the user during a picking confirmation (when average price costing method is used)"),
'company_id': fields.many2one('res.company', 'Company', required=True, select=True),
'partner_id': fields.related('picking_id','address_id','partner_id',type='many2one', relation="res.partner", string="Partner", store=True, select=True),
# used for colors in tree views:
'scrapped': fields.related('location_dest_id','scrap_location',type='boolean',relation='stock.location',string='Scrapped', readonly=True),
- 'tracking': fields.boolean('Track Lots'),
}
_constraints = [
(_check_tracking,
}
def write(self, cr, uid, ids, vals, context=None):
+ if isinstance(ids, (int, long)):
+ ids = [ids]
if uid != 1:
frozen_fields = set(['product_qty', 'product_uom', 'product_uos_qty', 'product_uos', 'location_id', 'location_dest_id', 'product_id'])
for move in self.browse(cr, uid, ids, context=context):
'product_uom': product.uom_id.id,
'product_uos': uos_id,
'product_qty': 1.00,
- 'tracking': product.track_production,
'product_uos_qty' : self.pool.get('stock.move').onchange_quantity(cr, uid, ids, prod_id, 1.00, product.uom_id.id, uos_id)['value']['product_uos_qty']
}
if not ids:
old_ptype = location_obj.picking_type_get(cr, uid, picking.move_lines[0].location_id, picking.move_lines[0].location_dest_id)
if old_ptype != picking.type:
old_pick_name = seq_obj.get(cr, uid, 'stock.picking.' + old_ptype)
- self.pool.get('stock.picking').write(cr, uid, picking.id, {'name': old_pick_name}, context=context)
+ self.pool.get('stock.picking').write(cr, uid, [picking.id], {'name': old_pick_name}, context=context)
else:
pickid = False
for move, (loc, dummy, delay, dummy, company_id, ptype) in todo:
move_obj = self.pool.get('account.move')
for j_id, move_lines in account_moves:
move_obj.create(cr, uid,
- {'name': move.name,
+ {
'journal_id': j_id,
'line_id': move_lines,
'ref': move.picking_id and move.picking_id.name})
todo = []
for move in self.browse(cr, uid, ids, context=context):
- #print 'DONE MOVE', move.id, move.product_id.name, move.move_dest_id.id, move.state, move.move_dest_id and move.move_dest_id.state
if move.state=="draft":
todo.append(move.id)
if todo:
prodlot_id = partial_datas and partial_datas.get('move%s_prodlot_id' % (move.id), False)
if prodlot_id:
self.write(cr, uid, [move.id], {'prodlot_id': prodlot_id}, context=context)
- if move.state not in ('confirmed','done', 'assigned'):
+ if move.state not in ('confirmed','done','assigned'):
todo.append(move.id)
if todo:
if quantity <= 0:
raise osv.except_osv(_('Warning!'), _('Please provide a positive quantity to scrap!'))
res = []
- to_done = []
for move in self.browse(cr, uid, ids, context=context):
move_qty = move.product_qty
uos_qty = quantity / move_qty * move.product_uos_qty
if move.location_id.usage <> 'internal':
default_val.update({'location_id': move.location_dest_id.id})
new_move = self.copy(cr, uid, move.id, default_val)
- res.append(new_move)
- to_done.append(new_move)
-
- if move.prodlot_id:
- # Create a new move with the qty of scrapped move without prodlot
- default_val = {
- 'product_qty': quantity,
- 'product_uos_qty': uos_qty,
- 'tracking_id': move.tracking_id.id,
- 'prodlot_id': False
- }
- newmove = self.copy(cr, uid, move.id, default_val)
- res.append(new_move)
- # Reduce amount of original move by qty of scrapped move
- if move.product_qty - quantity > 0:
- move.write({
- 'product_qty': move.product_qty - quantity,
- 'product_uos_qty': move.product_uos_qty - uos_qty,
- })
-
+ res += [new_move]
product_obj = self.pool.get('product.product')
for (id, name) in product_obj.name_get(cr, uid, [move.product_id.id]):
self.log(cr, uid, move.id, "%s x %s %s" % (move.product_qty, name, _("were scrapped")))
- self.action_done(cr, uid, to_done, context=context)
+ self.action_done(cr, uid, res)
return res
def action_split(self, cr, uid, ids, quantity, split_by_qty=1, prefix=False, with_lot=True, context=None):
'state': move.state,
'location_id': location_id or move.location_id.id,
}
- if (not move.prodlot_id.id) and (move.product_id.track_production and location_id):
- # IF product has checked track for production lot, move lines will be split by 1
- res += self.action_split(cr, uid, [move.id], quantity, split_by_qty=1, context=context)
- else:
- current_move = self.copy(cr, uid, move.id, default_val)
- res += [current_move]
+ current_move = self.copy(cr, uid, move.id, default_val)
+ res += [current_move]
update_val = {}
update_val['product_qty'] = quantity_rest
update_val['product_uos_qty'] = uos_qty_rest
else:
quantity_rest = quantity
uos_qty_rest = uos_qty
- if (not move.prodlot_id.id) and (move.product_id.track_production and location_id):
- res += self.action_split(cr, uid, [move.id], quantity_rest, split_by_qty=1, context=context)
- else:
- res += [move.id]
- update_val = {
+ res += [move.id]
+ update_val = {
'product_qty' : quantity_rest,
'product_uos_qty' : uos_qty_rest,
'location_id': location_id or move.location_id.id
- }
- self.write(cr, uid, [move.id], update_val)
+ }
+ self.write(cr, uid, [move.id], update_val)
product_obj = self.pool.get('product.product')
for new_move in self.browse(cr, uid, res, context=context):
defaults.update(prodlot_id=prodlot_id)
new_move = self.copy(cr, uid, move.id, defaults)
complete.append(self.browse(cr, uid, new_move))
- self.write(cr, uid, move.id,
+ self.write(cr, uid, [move.id],
{
'product_qty' : move.product_qty - product_qty,
'product_uos_qty':move.product_qty - product_qty,
for move in too_many:
- self.write(cr, uid, move.id,
+ self.write(cr, uid, [move.id],
{
'product_qty': move.product_qty,
'product_uos_qty': move.product_qty,
move_ids = []
for line in inv.inventory_line_id:
pid = line.product_id.id
- product_context.update(uom=line.product_uom.id,date=inv.date)
+ product_context.update(uom=line.product_uom.id, date=inv.date, prodlot_id=line.prod_lot_id.id)
amount = location_obj._product_get(cr, uid, line.location_id.id, [pid], product_context)[pid]
change = line.product_qty - amount
class stock_inventory_line(osv.osv):
_name = "stock.inventory.line"
_description = "Inventory Line"
+ _rec_name = "inventory_id"
_columns = {
'inventory_id': fields.many2one('stock.inventory', 'Inventory', ondelete='cascade', select=True),
'location_id': fields.many2one('stock.location', 'Location', required=True),
'company_id': fields.related('inventory_id','company_id',type='many2one',relation='res.company',string='Company',store=True, select=True, readonly=True),
'prod_lot_id': fields.many2one('stock.production.lot', 'Production Lot', domain="[('product_id','=',product_id)]"),
'state': fields.related('inventory_id','state',type='char',string='State',readonly=True),
- 'tracking': fields.boolean('Track Lots'),
}
def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, to_date=False):
@return: Dictionary of changed values
"""
if not product:
- return {}
- if not uom:
- prod = self.pool.get('product.product').browse(cr, uid, [product], {'uom': uom})[0]
- uom = prod.uom_id.id
+ return {'value': {'product_qty': 0.0, 'product_uom': False}}
+ obj_product = self.pool.get('product.product').browse(cr, uid, product)
+ uom = uom or obj_product.uom_id.id
amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom, 'to_date': to_date})[product]
- result = {'product_qty': amount, 'product_uom': uom, 'tracking':prod.track_production}
+ result = {'product_qty': amount, 'product_uom': uom}
return {'value': result}
stock_inventory_line()