From 369221b47101072e094ad2d02fe2edd2b47690aa Mon Sep 17 00:00:00 2001 From: Olivier Laurent Date: Fri, 28 Aug 2009 11:40:49 +0200 Subject: [PATCH] [FIX] pep8 bzr revid: olt@tinyerp.com-20090828094049-9ls3emo12g34r0d8 --- addons/stock/stock.py | 463 ++++++++++++++++++++++-------------------- 1 file changed, 243 insertions(+), 220 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 4398877df43..2a372d4eeed 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -23,12 +23,11 @@ from mx import DateTime import time import netsvc -from osv import fields,osv -import ir +from osv import fields, osv from tools import config from tools.translate import _ import tools -from xml.dom import minidom + #---------------------------------------------------------- # Incoterms @@ -44,8 +43,10 @@ class stock_incoterms(osv.osv): _defaults = { 'active': lambda *a: True, } + stock_incoterms() + #---------------------------------------------------------- # Stock Location #---------------------------------------------------------- @@ -85,7 +86,6 @@ class stock_location(osv.osv): res[loc]['stock_virtual'] = prod.virtual_available return res - def product_detail(self, cr, uid, id, field, context={}): res = {} res[id] = {} @@ -93,13 +93,13 @@ class stock_location(osv.osv): field_to_read = 'virtual_available' if field == 'stock_real_value': field_to_read = 'qty_available' - cr.execute('select distinct product_id from stock_move where (location_id=%s) or (location_dest_id=%s)',(id,id)) + cr.execute('select distinct product_id from stock_move where (location_id=%s) or (location_dest_id=%s)', (id, id)) result = cr.dictfetchall() if result: for r in result: c = (context or {}).copy() c['location'] = id - product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read,'standard_price'], context=c) + product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read, 'standard_price'], context=c) final_value += (product[field_to_read] * product['standard_price']) return final_value @@ -109,30 +109,30 @@ class stock_location(osv.osv): result[id] = {}.fromkeys(field_names, 0.0) for field_name in field_names: for loc in ids: - ret_dict = self.product_detail(cr,uid,loc,field=field_name) + ret_dict = self.product_detail(cr, uid, loc, field=field_name) result[loc][field_name] = ret_dict return result _columns = { 'name': fields.char('Location Name', size=64, required=True, translate=True), 'active': fields.boolean('Active'), - 'usage': fields.selection([('supplier','Supplier Location'),('view','View'),('internal','Internal Location'),('customer','Customer Location'),('inventory','Inventory'),('procurement','Procurement'),('production','Production')], 'Location Type', required=True), - 'allocation_method': fields.selection([('fifo','FIFO'),('lifo','LIFO'),('nearest','Nearest')], 'Allocation Method', required=True), + 'usage': fields.selection([('supplier', 'Supplier Location'), ('view', 'View'), ('internal', 'Internal Location'), ('customer', 'Customer Location'), ('inventory', 'Inventory'), ('procurement', 'Procurement'), ('production', 'Production')], 'Location Type', required=True), + 'allocation_method': fields.selection([('fifo', 'FIFO'), ('lifo', 'LIFO'), ('nearest', 'Nearest')], 'Allocation Method', required=True), 'complete_name': fields.function(_complete_name, method=True, type='char', size=100, string="Location Name"), 'stock_real': fields.function(_product_qty_available, method=True, type='float', string='Real Stock', multi="stock"), 'stock_virtual': fields.function(_product_qty_available, method=True, type='float', string='Virtual Stock', multi="stock"), - 'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type','!=','view')]), + 'account_id': fields.many2one('account.account', string='Inventory Account', domain=[('type', '!=', 'view')]), 'location_id': fields.many2one('stock.location', 'Parent Location', select=True, ondelete='cascade'), 'child_ids': fields.one2many('stock.location', 'location_id', 'Contains'), 'chained_location_id': fields.many2one('stock.location', 'Chained Location If Fixed'), - 'chained_location_type': fields.selection([('none','None'),('customer', 'Customer'),('fixed','Fixed Location')], + 'chained_location_type': fields.selection([('none', 'None'), ('customer', 'Customer'), ('fixed', 'Fixed Location')], 'Chained Location Type', required=True), 'chained_auto_packing': fields.selection( - [('auto','Automatic Move'), ('manual','Manual Operation'),('transparent','Automatic No Step Added')], + [('auto', 'Automatic Move'), ('manual', 'Manual Operation'), ('transparent', 'Automatic No Step Added')], 'Automatic Move', required=True, help="This is used only if you selected a chained location type.\n" \ @@ -168,10 +168,10 @@ class stock_location(osv.osv): def chained_location_get(self, cr, uid, location, partner=None, product=None, context={}): result = None - if location.chained_location_type=='customer': + if location.chained_location_type == 'customer': if partner: result = partner.property_stock_customer - elif location.chained_location_type=='fixed': + elif location.chained_location_type == 'fixed': result = location.chained_location_id if result: return result, location.chained_auto_packing, location.chained_delay @@ -179,9 +179,9 @@ class stock_location(osv.osv): def picking_type_get(self, cr, uid, from_location, to_location, context={}): result = 'internal' - if (from_location.usage=='internal') and (to_location and to_location.usage in ('customer','supplier')): + if (from_location.usage=='internal') and (to_location and to_location.usage in ('customer', 'supplier')): result = 'delivery' - elif (from_location.usage in ('supplier','customer')) and (to_location.usage=='internal'): + elif (from_location.usage in ('supplier', 'customer')) and (to_location.usage=='internal'): result = 'in' return result @@ -234,7 +234,7 @@ class stock_location(osv.osv): 'variants': product.variants or '', 'uom': product.uom_id.name, 'prod_qty': qty[product_id], - 'price_value':price, + 'price_value': price, }) result['total'] = quantity_total result['total_price'] = total_price @@ -243,11 +243,11 @@ class stock_location(osv.osv): def _product_get_multi_location(self, cr, uid, ids, product_ids=False, context={}, states=['done'], what=('in', 'out')): product_obj = self.pool.get('product.product') context.update({ - 'states':states, - 'what':what, - 'location':ids + 'states': states, + 'what': what, + 'location': ids }) - return product_obj.get_product_available(cr,uid,product_ids,context=context) + return product_obj.get_product_available(cr, uid, product_ids, context=context) def _product_get(self, cr, uid, id, product_ids=False, context={}, states=['done']): ids = id and [id] or [] @@ -260,7 +260,7 @@ class stock_location(osv.osv): return self._product_get_multi_location(cr, uid, location_ids, product_ids, context, states) def _product_virtual_get(self, cr, uid, id, product_ids=False, context={}, states=['done']): - return self._product_all_get(cr, uid, id, product_ids, context, ['confirmed','waiting','assigned','done']) + return self._product_all_get(cr, uid, id, product_ids, context, ['confirmed', 'waiting', 'assigned', 'done']) # # TODO: @@ -273,35 +273,37 @@ class stock_location(osv.osv): result = [] amount = 0.0 for id in self.search(cr, uid, [('location_id', 'child_of', ids)]): - cr.execute("select product_uom,sum(product_qty) as product_qty from stock_move where location_dest_id=%s and location_id<>%s and product_id=%s and state='done' group by product_uom", (id,id,product_id)) + cr.execute("select product_uom,sum(product_qty) as product_qty from stock_move where location_dest_id=%s and location_id<>%s and product_id=%s and state='done' group by product_uom", (id, id, product_id)) results = cr.dictfetchall() - cr.execute("select product_uom,-sum(product_qty) as product_qty from stock_move where location_id=%s and location_dest_id<>%s and product_id=%s and state in ('done', 'assigned') group by product_uom", (id,id,product_id)) + cr.execute("select product_uom,-sum(product_qty) as product_qty from stock_move where location_id=%s and location_dest_id<>%s and product_id=%s and state in ('done', 'assigned') group by product_uom", (id, id, product_id)) results += cr.dictfetchall() total = 0.0 results2 = 0.0 for r in results: - amount = self.pool.get('product.uom')._compute_qty(cr, uid, r['product_uom'],r['product_qty'], context.get('uom',False)) + amount = self.pool.get('product.uom')._compute_qty(cr, uid, r['product_uom'], r['product_qty'], context.get('uom', False)) results2 += amount total += amount - if total<=0.0: + if total <= 0.0: continue amount = results2 - if amount>0: - if amount>min(total,product_qty): - amount = min(product_qty,total) - result.append((amount,id)) + if amount > 0: + if amount > min(total, product_qty): + amount = min(product_qty, total) + result.append((amount, id)) product_qty -= amount total -= amount - if product_qty<=0.0: + if product_qty <= 0.0: return result - if total<=0.0: + if total <= 0.0: continue return False + stock_location() + class stock_tracking(osv.osv): _name = "stock.tracking" _description = "Stock Tracking Lots" @@ -322,73 +324,78 @@ class stock_tracking(osv.osv): 'name': fields.char('Tracking', size=64, required=True), 'active': fields.boolean('Active'), 'serial': fields.char('Reference', size=64), - 'move_ids' : fields.one2many('stock.move', 'tracking_id', 'Moves Tracked'), + 'move_ids': fields.one2many('stock.move', 'tracking_id', 'Moves Tracked'), 'date': fields.datetime('Date Created', required=True), } _defaults = { 'active': lambda *a: 1, - 'name' : make_sscc, + 'name': make_sscc, 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), } def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80): if not args: - args=[] + args = [] if not context: - context={} - ids = self.search(cr, user, [('serial','=',name)]+ args, limit=limit, context=context) - ids += self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context) + context = {} + ids = self.search(cr, user, [('serial', '=', name)]+ args, limit=limit, context=context) + ids += self.search(cr, user, [('name', operator, name)]+ args, limit=limit, context=context) return self.name_get(cr, user, ids, context) def name_get(self, cr, uid, ids, context={}): if not len(ids): return [] - res = [(r['id'], r['name']+' ['+(r['serial'] or '')+']') for r in self.read(cr, uid, ids, ['name','serial'], context)] + res = [(r['id'], r['name']+' ['+(r['serial'] or '')+']') for r in self.read(cr, uid, ids, ['name', 'serial'], context)] return res - def unlink(self, cr ,uid, ids, context=None): + def unlink(self, cr, uid, ids, context=None): raise osv.except_osv(_('Error'), _('You can not remove a lot line !')) + stock_tracking() + #---------------------------------------------------------- # Stock Picking #---------------------------------------------------------- class stock_picking(osv.osv): _name = "stock.picking" _description = "Packing List" + def _set_maximum_date(self, cr, uid, ids, name, value, arg, context): - if not value: return False + if not value: + return False if isinstance(ids, (int, long)): - ids=[ids] + ids = [ids] for pick in self.browse(cr, uid, ids, context): - sql_str="""update stock_move set + sql_str = """update stock_move set date_planned='%s' where - picking_id=%d """ % (value,pick.id) + picking_id=%d """ % (value, pick.id) if pick.max_date: - sql_str += " and (date_planned='"+pick.max_date+"' or date_planned>'"+value+"')" + sql_str += " and (date_planned='" + pick.max_date + "' or date_planned>'" + value + "')" cr.execute(sql_str) return True def _set_minimum_date(self, cr, uid, ids, name, value, arg, context): - if not value: return False + if not value: + return False if isinstance(ids, (int, long)): - ids=[ids] + ids = [ids] for pick in self.browse(cr, uid, ids, context): - sql_str="""update stock_move set + sql_str = """update stock_move set date_planned='%s' where - picking_id=%s """ % (value,pick.id) + picking_id=%s """ % (value, pick.id) if pick.min_date: - sql_str += " and (date_planned='"+pick.min_date+"' or date_planned<'"+value+"')" + sql_str += " and (date_planned='" + pick.min_date + "' or date_planned<'" + value + "')" cr.execute(sql_str) return True def get_min_max_date(self, cr, uid, ids, field_name, arg, context={}): res = {} for id in ids: - res[id] = {'min_date':False, 'max_date': False} + res[id] = {'min_date': False, 'max_date': False} if not ids: return res cr.execute("""select @@ -401,7 +408,7 @@ class stock_picking(osv.osv): picking_id in (""" + ','.join(map(str, ids)) + """) group by picking_id""") - for pick, dt1,dt2 in cr.fetchall(): + for pick, dt1, dt2 in cr.fetchall(): res[pick]['min_date'] = dt1 res[pick]['max_date'] = dt2 return res @@ -409,45 +416,45 @@ class stock_picking(osv.osv): def create(self, cr, user, vals, context=None): if ('name' not in vals) or (vals.get('name')=='/'): vals['name'] = self.pool.get('ir.sequence').get(cr, user, 'stock.picking') + return super(stock_picking, self).create(cr, user, vals, context) _columns = { 'name': fields.char('Reference', size=64, select=True), 'origin': fields.char('Origin Reference', size=64), 'backorder_id': fields.many2one('stock.picking', 'Back Order'), - 'type': fields.selection([('out','Sending Goods'),('in','Getting Goods'),('internal','Internal'),('delivery','Delivery')], 'Shipping Type', required=True, select=True), + 'type': fields.selection([('out', 'Sending Goods'), ('in', 'Getting Goods'), ('internal', 'Internal'), ('delivery', 'Delivery')], 'Shipping Type', required=True, select=True), 'active': fields.boolean('Active'), 'note': fields.text('Notes'), 'location_id': fields.many2one('stock.location', 'Location'), 'location_dest_id': fields.many2one('stock.location', 'Dest. Location'), - 'move_type': fields.selection([('direct','Direct Delivery'),('one','All at once')],'Delivery Method', required=True), + 'move_type': fields.selection([('direct', 'Direct Delivery'), ('one', 'All at once')], 'Delivery Method', required=True), 'state': fields.selection([ - ('draft','Draft'), - ('auto','Waiting'), - ('confirmed','Confirmed'), - ('assigned','Available'), - ('done','Done'), - ('cancel','Canceled'), + ('draft', 'Draft'), + ('auto', 'Waiting'), + ('confirmed', 'Confirmed'), + ('assigned', 'Available'), + ('done', 'Done'), + ('cancel', 'Canceled'), ], 'Status', readonly=True, select=True), 'min_date': fields.function(get_min_max_date, fnct_inv=_set_minimum_date, multi="min_max_date", - method=True,store=True, type='datetime', string='Planned Date', select=1), - 'date':fields.datetime('Date Order'), - 'date_done':fields.datetime('Date Done'), + method=True, store=True, type='datetime', string='Planned Date', select=1), + 'date': fields.datetime('Date Order'), + 'date_done': fields.datetime('Date Done'), 'max_date': fields.function(get_min_max_date, fnct_inv=_set_maximum_date, multi="min_max_date", - method=True,store=True, type='datetime', string='Max. Planned Date', select=2), - 'move_lines': fields.one2many('stock.move', 'picking_id', 'Move lines',states={'done':[('readonly',True)],'cancel':[('readonly',True)]}), - + method=True, store=True, type='datetime', string='Max. Planned Date', select=2), + 'move_lines': fields.one2many('stock.move', 'picking_id', 'Move lines', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}), 'auto_picking': fields.boolean('Auto-Packing'), 'address_id': fields.many2one('res.partner.address', 'Partner'), - 'invoice_state':fields.selection([ - ("invoiced","Invoiced"), - ("2binvoiced","To Be Invoiced"), - ("none","Not from Packing")], "Invoice Status", - select=True, required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'invoice_state': fields.selection([ + ("invoiced", "Invoiced"), + ("2binvoiced", "To Be Invoiced"), + ("none", "Not from Packing")], "Invoice Status", + select=True, required=True, readonly=True, states={'draft': [('readonly', False)]}), } _defaults = { - 'name': lambda self,cr,uid,context: '/', + 'name': lambda self, cr, uid, context: '/', 'active': lambda *a: 1, 'state': lambda *a: 'draft', 'move_type': lambda *a: 'direct', @@ -455,6 +462,7 @@ class stock_picking(osv.osv): 'invoice_state': lambda *a: 'none', 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), } + def copy(self, cr, uid, id, default=None, context={}): if default is None: default = {} @@ -463,7 +471,7 @@ class stock_picking(osv.osv): return super(stock_picking, self).copy(cr, uid, id, default, context) def onchange_partner_in(self, cr, uid, context, partner_id=None): - return { } + return {} def action_explode(self, cr, uid, moves, context={}): return moves @@ -473,7 +481,7 @@ class stock_picking(osv.osv): todo = [] for picking in self.browse(cr, uid, ids): for r in picking.move_lines: - if r.state=='draft': + if r.state == 'draft': todo.append(r.id) todo = self.action_explode(cr, uid, todo, context) if len(todo): @@ -493,7 +501,7 @@ class stock_picking(osv.osv): def action_assign(self, cr, uid, ids, *args): for pick in self.browse(cr, uid, ids): - move_ids = [x.id for x in pick.move_lines if x.state=='confirmed'] + move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed'] self.pool.get('stock.move').action_assign(cr, uid, move_ids) return True @@ -525,7 +533,7 @@ class stock_picking(osv.osv): wf_service.trg_write(uid, 'stock.picking', pick.id, cr) self.action_move(cr, uid, [pick.id]) - wf_service.trg_validate(uid, 'stock.picking', pick.id , 'button_done', cr) + wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_done', cr) return True def cancel_assign(self, cr, uid, ids, *args): @@ -537,17 +545,17 @@ class stock_picking(osv.osv): return True def action_assign_wkf(self, cr, uid, ids): - self.write(cr, uid, ids, {'state':'assigned'}) + self.write(cr, uid, ids, {'state': 'assigned'}) return True def test_finnished(self, cr, uid, ids): - move_ids=self.pool.get('stock.move').search(cr,uid,[('picking_id','in',ids)]) - for move in self.pool.get('stock.move').browse(cr,uid,move_ids): - if move.state not in ('done','cancel') : + move_ids = self.pool.get('stock.move').search(cr, uid, [('picking_id', 'in', ids)]) + for move in self.pool.get('stock.move').browse(cr, uid, move_ids): + if move.state not in ('done', 'cancel'): if move.product_qty != 0.0: return False else: - move.write(cr,uid,[move.id],{'state':'done'}) + move.write(cr, uid, [move.id], {'state': 'done'}) return True def test_assigned(self, cr, uid, ids): @@ -555,32 +563,32 @@ class stock_picking(osv.osv): for pick in self.browse(cr, uid, ids): mt = pick.move_type for move in pick.move_lines: - if (move.state in ('confirmed','draft')) and (mt=='one'): + if (move.state in ('confirmed', 'draft')) and (mt=='one'): return False if (mt=='direct') and (move.state=='assigned') and (move.product_qty): return True - ok = ok and (move.state in ('cancel','done','assigned')) + ok = ok and (move.state in ('cancel', 'done', 'assigned')) return ok def action_cancel(self, cr, uid, ids, context={}): for pick in self.browse(cr, uid, ids): ids2 = [move.id for move in pick.move_lines] self.pool.get('stock.move').action_cancel(cr, uid, ids2, context) - self.write(cr,uid, ids, {'state':'cancel', 'invoice_state':'none'}) + self.write(cr, uid, ids, {'state': 'cancel', 'invoice_state': 'none'}) return True # # TODO: change and create a move if not parents # def action_done(self, cr, uid, ids, context=None): - self.write(cr,uid, ids, {'state':'done', 'date_done': time.strftime('%Y-%m-%d %H:%M:%S')}) + self.write(cr, uid, ids, {'state': 'done', 'date_done': time.strftime('%Y-%m-%d %H:%M:%S')}) return True def action_move(self, cr, uid, ids, context={}): for pick in self.browse(cr, uid, ids): todo = [] for move in pick.move_lines: - if move.state=='assigned': + if move.state == 'assigned': todo.append(move.id) if len(todo): @@ -667,7 +675,7 @@ class stock_picking(osv.osv): if type in ('out_invoice', 'out_refund'): account_id = partner.property_account_receivable.id - payment_term_id=self._get_payment_term(cursor, user, picking) + payment_term_id = self._get_payment_term(cursor, user, picking) else: account_id = partner.property_account_payable.id @@ -677,13 +685,13 @@ class stock_picking(osv.osv): comment = self._get_comment_invoice(cursor, user, picking) if group and partner.id in invoices_group: invoice_id = invoices_group[partner.id] - invoice=invoice_obj.browse(cursor, user,invoice_id) + invoice = invoice_obj.browse(cursor, user, invoice_id) invoice_vals = { - 'name': (invoice.name or '') +', '+(picking.name or ''), - 'origin': (invoice.origin or '')+', '+(picking.name or '')+(picking.origin and (':' + picking.origin) or ''), - 'comment':(comment and (invoice.comment and invoice.comment+"\n"+comment or comment)) or (invoice.comment and invoice.comment or ''), + 'name': (invoice.name or '') + ', ' + (picking.name or ''), + 'origin': (invoice.origin or '') + ', ' + (picking.name or '') + (picking.origin and (':' + picking.origin) or ''), + 'comment': (comment and (invoice.comment and invoice.comment+"\n"+comment or comment)) or (invoice.comment and invoice.comment or ''), } - invoice_obj.write(cursor, user, [invoice_id],invoice_vals,context=context) + invoice_obj.write(cursor, user, [invoice_id], invoice_vals, context=context) else: invoice_vals = { 'name': picking.name, @@ -707,9 +715,9 @@ class stock_picking(osv.osv): invoices_group[partner.id] = invoice_id res[picking.id] = invoice_id for move_line in picking.move_lines: - origin=move_line.picking_id.name + origin = move_line.picking_id.name if move_line.picking_id.origin: - origin+=':' + move_line.picking_id.origin + origin += ':' + move_line.picking_id.origin if group: name = (picking.name or '') + '-' + move_line.name else: @@ -738,7 +746,7 @@ class stock_picking(osv.osv): account_id = self.pool.get('account.fiscal.position').map_account(cursor, user, partner.property_account_position, account_id) invoice_line_id = invoice_line_obj.create(cursor, user, { 'name': name, - 'origin':origin, + 'origin': origin, 'invoice_id': invoice_id, 'uos_id': move_line.product_uos.id, 'product_id': move_line.product_id.id, @@ -762,7 +770,7 @@ class stock_picking(osv.osv): }, context=context) return res - def test_cancel(self,cr, uid, ids, context={}): + def test_cancel(self, cr, uid, ids, context={}): for pick in self.browse(cr, uid, ids, context=context): if not pick.move_lines: return False @@ -770,6 +778,7 @@ class stock_picking(osv.osv): if move.state not in ('cancel',): return False return True + stock_picking() @@ -778,21 +787,20 @@ class stock_production_lot(osv.osv): if not ids: return [] reads = self.read(cr, uid, ids, ['name', 'ref'], context) - res=[] + res = [] for record in reads: - name=record['name'] + name = record['name'] if record['ref']: - name=name+'/'+record['ref'] + name = name + '/' + record['ref'] res.append((record['id'], name)) return res - _name = 'stock.production.lot' _description = 'Production lot' def _get_stock(self, cr, uid, ids, field_name, arg, context={}): if 'location_id' not in context: - locations = self.pool.get('stock.location').search(cr, uid, [('usage','=','internal')], context=context) + locations = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context) else: locations = context['location_id'] and [context['location_id']] or [] @@ -817,34 +825,34 @@ class stock_production_lot(osv.osv): return res def _stock_search(self, cr, uid, obj, name, args): - locations = self.pool.get('stock.location').search(cr, uid, [('usage','=','internal')]) + locations = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')]) cr.execute('''select prodlot_id, sum(name) from stock_report_prodlots where - location_id in ('''+','.join(map(str, locations)) +''') + location_id in ('''+','.join(map(str, locations)) + ''') group by prodlot_id having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2]) ) res = cr.fetchall() - ids = [('id','in',map(lambda x:x[0], res))] + ids = [('id', 'in', map(lambda x: x[0], res))] return ids _columns = { 'name': fields.char('Serial', size=64, required=True), 'ref': fields.char('Internal Ref', size=64), - 'product_id': fields.many2one('product.product','Product',required=True), + 'product_id': fields.many2one('product.product', 'Product', required=True), 'date': fields.datetime('Created Date', required=True), 'stock_available': fields.function(_get_stock, fnct_search=_stock_search, method=True, type="float", string="Available", select="2"), - 'revisions': fields.one2many('stock.production.lot.revision','lot_id','Revisions'), + 'revisions': fields.one2many('stock.production.lot.revision', 'lot_id', 'Revisions'), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), - 'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'stock.lot.serial'), - 'product_id': lambda x,y,z,c: c.get('product_id',False), + 'name': lambda x, y, z, c: x.pool.get('ir.sequence').get(y, z, 'stock.lot.serial'), + 'product_id': lambda x, y, z, c: c.get('product_id', False), } _sql_constraints = [ ('name_ref_uniq', 'unique (name, ref)', 'The serial/ref must be unique !'), @@ -852,6 +860,7 @@ class stock_production_lot(osv.osv): stock_production_lot() + class stock_production_lot_revision(osv.osv): _name = 'stock.production.lot.revision' _description = 'Production lot revisions' @@ -865,9 +874,10 @@ class stock_production_lot_revision(osv.osv): } _defaults = { - 'author_id': lambda x,y,z,c: z, + 'author_id': lambda x, y, z, c: z, 'date': lambda *a: time.strftime('%Y-%m-%d'), } + stock_production_lot_revision() # ---------------------------------------------------- @@ -885,6 +895,7 @@ class stock_move(osv.osv): return (res and res[0]) or False _name = "stock.move" _description = "Stock Move" + def name_get(self, cr, uid, ids, context={}): res = [] for line in self.browse(cr, uid, ids, context): @@ -892,27 +903,27 @@ class stock_move(osv.osv): return res def _check_tracking(self, cr, uid, ids): - for move in self.browse(cr, uid, ids): - if not move.prodlot_id and \ - (move.state == 'done' and \ - ( \ - (move.product_id.track_production and move.location_id.usage=='production') or \ - (move.product_id.track_production and move.location_dest_id.usage=='production') or \ - (move.product_id.track_incoming and move.location_id.usage=='supplier') or \ - (move.product_id.track_outgoing and move.location_dest_id.usage=='customer') \ - )): - return False - return True + for move in self.browse(cr, uid, ids): + if not move.prodlot_id and \ + (move.state == 'done' and \ + ( \ + (move.product_id.track_production and move.location_id.usage=='production') or \ + (move.product_id.track_production and move.location_dest_id.usage=='production') or \ + (move.product_id.track_incoming and move.location_id.usage=='supplier') or \ + (move.product_id.track_outgoing and move.location_dest_id.usage=='customer') \ + )): + return False + return True def _check_product_lot(self, cr, uid, ids): - for move in self.browse(cr, uid, ids): - if move.prodlot_id and (move.prodlot_id.product_id.id != move.product_id.id): + for move in self.browse(cr, uid, ids): + if move.prodlot_id and (move.prodlot_id.product_id.id != move.product_id.id): return False - return True + return True _columns = { 'name': fields.char('Name', size=64, required=True, select=True), - 'priority': fields.selection([('0','Not urgent'),('1','Urgent')], 'Priority'), + 'priority': fields.selection([('0', 'Not urgent'), ('1', 'Urgent')], 'Priority'), 'date': fields.datetime('Date Created'), 'date_planned': fields.datetime('Date', required=True, help="Scheduled date for the movement of the products or real date if the move is done."), @@ -923,13 +934,13 @@ class stock_move(osv.osv): 'product_uom': fields.many2one('product.uom', 'Product UOM', required=True), 'product_uos_qty': fields.float('Quantity (UOS)'), 'product_uos': fields.many2one('product.uom', 'Product UOS'), - 'product_packaging' : fields.many2one('product.packaging', 'Packaging'), + 'product_packaging': fields.many2one('product.packaging', 'Packaging'), 'location_id': fields.many2one('stock.location', 'Source Location', required=True, select=True), 'location_dest_id': fields.many2one('stock.location', 'Dest. Location', required=True, select=True), - 'address_id' : fields.many2one('res.partner.address', 'Dest. Address'), + 'address_id': fields.many2one('res.partner.address', 'Dest. Address'), - 'prodlot_id' : fields.many2one('stock.production.lot', 'Production Lot', help="Production lot is used to put a serial number on the production"), + 'prodlot_id': fields.many2one('stock.production.lot', 'Production Lot', help="Production lot is used to put a serial number on the production"), 'tracking_id': fields.many2one('stock.tracking', 'Tracking Lot', select=True, help="Tracking lot is the code that will be put on the logistical unit/pallet"), # 'lot_id': fields.many2one('stock.lot', 'Consumer lot', select=True, readonly=True), @@ -942,7 +953,7 @@ class stock_move(osv.osv): 'note': fields.text('Notes'), - 'state': fields.selection([('draft','Draft'),('waiting','Waiting'),('confirmed','Confirmed'),('assigned','Available'),('done','Done'),('cancel','Canceled')], 'Status', readonly=True, select=True), + 'state': fields.selection([('draft', 'Draft'), ('waiting', 'Waiting'), ('confirmed', 'Confirmed'), ('assigned', 'Available'), ('done', 'Done'), ('cancel', 'Canceled')], 'Status', readonly=True, select=True), 'price_unit': fields.float('Unit Price', digits=(16, int(config['price_accuracy']))), } @@ -953,13 +964,14 @@ class stock_move(osv.osv): (_check_product_lot, 'You try to assign a lot which is not from the same product', ['prodlot_id'])] + def _default_location_destination(self, cr, uid, context={}): if context.get('move_line', []): if context['move_line'][0]: - if isinstance(context['move_line'][0],(tuple,list)): + if isinstance(context['move_line'][0], (tuple, list)): return context['move_line'][0][2] and context['move_line'][0][2]['location_dest_id'] or False else: - move_list = self.pool.get('stock.move').read(cr, uid, context['move_line'][0],['location_dest_id']) + move_list = self.pool.get('stock.move').read(cr, uid, context['move_line'][0], ['location_dest_id']) return move_list and move_list['location_dest_id'][0] or False if context.get('address_out_id', False): return self.pool.get('res.partner.address').browse(cr, uid, context['address_out_id'], context).partner_id.property_stock_customer.id @@ -1002,14 +1014,14 @@ class stock_move(osv.osv): ctx = context and context.copy() or {} ctx['location_id'] = loc_id prodlot = self.pool.get('stock.production.lot').browse(cr, uid, prodlot_id, ctx) - location=self.pool.get('stock.location').browse(cr,uid,loc_id) - warning={} + location = self.pool.get('stock.location').browse(cr, uid, loc_id) + warning = {} if (location.usage == 'internal') and (product_qty > (prodlot.stock_available or 0.0)): - warning={ - 'title':'Bad Lot Assignation !', - 'message':'You are moving %.2f products but only %.2f available in this lot.' % (product_qty,prodlot.stock_available or 0.0) + warning = { + 'title': 'Bad Lot Assignation !', + 'message': 'You are moving %.2f products but only %.2f available in this lot.' % (product_qty, prodlot.stock_available or 0.0) } - return {'warning':warning} + return {'warning': warning} def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False, loc_dest_id=False): if not prod_id: @@ -1023,7 +1035,7 @@ class stock_move(osv.osv): result['location_id'] = loc_id if loc_dest_id: result['location_dest_id'] = loc_dest_id - return {'value':result} + return {'value': result} def _chain_compute(self, cr, uid, moves, context={}): result = {} @@ -1037,7 +1049,7 @@ class stock_move(osv.osv): context ) if dest: - if dest[1]=='transparent': + if dest[1] == 'transparent': self.write(cr, uid, [m.id], { 'date_planned': (DateTime.strptime(m.date_planned, '%Y-%m-%d %H:%M:%S') + \ DateTime.RelativeDateTime(days=dest[2] or 0)).strftime('%Y-%m-%d'), @@ -1050,10 +1062,11 @@ class stock_move(osv.osv): def action_confirm(self, cr, uid, ids, context={}): # ids = map(lambda m: m.id, moves) moves = self.browse(cr, uid, ids) - self.write(cr, uid, ids, {'state':'confirmed'}) - i=0 - def create_chained_picking(self,cr,uid,moves,context): - new_moves=[] + self.write(cr, uid, ids, {'state': 'confirmed'}) + i = 0 + + def create_chained_picking(self, cr, uid, moves, context): + new_moves = [] for picking, todo in self._chain_compute(cr, uid, moves, context).items(): ptype = self.pool.get('stock.location').picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0]) pickid = self.pool.get('stock.picking').create(cr, uid, { @@ -1062,21 +1075,21 @@ class stock_move(osv.osv): 'type': ptype, 'note': picking.note, 'move_type': picking.move_type, - 'auto_picking': todo[0][1][1]=='auto', + 'auto_picking': todo[0][1][1] == 'auto', 'address_id': picking.address_id.id, 'invoice_state': 'none' }) - for move,(loc,auto,delay) in todo: + for move, (loc, auto, delay) in todo: # Is it smart to copy ? May be it's better to recreate ? new_id = self.pool.get('stock.move').copy(cr, uid, move.id, { 'location_id': move.location_dest_id.id, 'location_dest_id': loc.id, 'date_moved': time.strftime('%Y-%m-%d'), 'picking_id': pickid, - 'state':'waiting', - 'move_history_ids':[], + 'state': 'waiting', + 'move_history_ids': [], 'date_planned': (DateTime.strptime(move.date_planned, '%Y-%m-%d %H:%M:%S') + DateTime.RelativeDateTime(days=delay or 0)).strftime('%Y-%m-%d'), - 'move_history_ids2':[]} + 'move_history_ids2': []} ) self.pool.get('stock.move').write(cr, uid, [move.id], { 'move_dest_id': new_id, @@ -1093,13 +1106,13 @@ class stock_move(osv.osv): def action_assign(self, cr, uid, ids, *args): todo = [] for move in self.browse(cr, uid, ids): - if move.state in ('confirmed','waiting'): + if move.state in ('confirmed', 'waiting'): todo.append(move.id) res = self.check_assign(cr, uid, todo) return res def force_assign(self, cr, uid, ids, context={}): - self.write(cr, uid, ids, {'state' : 'assigned'}) + self.write(cr, uid, ids, {'state': 'assigned'}) return True def cancel_assign(self, cr, uid, ids, context={}): @@ -1111,7 +1124,7 @@ class stock_move(osv.osv): # def check_assign(self, cr, uid, ids, context={}): done = [] - count=0 + count = 0 pickings = {} for move in self.browse(cr, uid, ids): if move.product_id.type == 'consu': @@ -1119,22 +1132,22 @@ class stock_move(osv.osv): done.append(move.id) pickings[move.picking_id.id] = 1 continue - if move.state in ('confirmed','waiting'): + if move.state in ('confirmed', 'waiting'): res = self.pool.get('stock.location')._product_reserve(cr, uid, [move.location_id.id], move.product_id.id, move.product_qty, {'uom': move.product_uom.id}) if res: done.append(move.id) pickings[move.picking_id.id] = 1 r = res.pop(0) - cr.execute('update stock_move set location_id=%s, product_qty=%s where id=%s', (r[1],r[0], move.id)) + cr.execute('update stock_move set location_id=%s, product_qty=%s where id=%s', (r[1], r[0], move.id)) while res: r = res.pop(0) - move_id = self.copy(cr, uid, move.id, {'product_qty':r[0], 'location_id':r[1]}) + move_id = self.copy(cr, uid, move.id, {'product_qty': r[0], 'location_id': r[1]}) done.append(move_id) #cr.execute('insert into stock_move_history_ids values (%s,%s)', (move.id,move_id)) if done: count += len(done) - self.write(cr, uid, done, {'state':'assigned'}) + self.write(cr, uid, done, {'state': 'assigned'}) if count: for pick_id in pickings: @@ -1150,19 +1163,19 @@ class stock_move(osv.osv): return True pickings = {} for move in self.browse(cr, uid, ids): - if move.state in ('confirmed','waiting','assigned','draft'): + if move.state in ('confirmed', 'waiting', 'assigned', 'draft'): if move.picking_id: pickings[move.picking_id.id] = True - if move.move_dest_id and move.move_dest_id.state=='waiting': - self.write(cr, uid, [move.move_dest_id.id], {'state':'assigned'}) + if move.move_dest_id and move.move_dest_id.state == 'waiting': + self.write(cr, uid, [move.move_dest_id.id], {'state': 'assigned'}) if move.move_dest_id.picking_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr) - self.write(cr, uid, ids, {'state':'cancel', 'move_dest_id': False}) + self.write(cr, uid, ids, {'state': 'cancel', 'move_dest_id': False}) - for pick in self.pool.get('stock.picking').browse(cr,uid,pickings.keys()): + for pick in self.pool.get('stock.picking').browse(cr, uid, pickings.keys()): if all(move.state == 'cancel' for move in pick.move_lines): - self.pool.get('stock.picking').write(cr,uid,[pick.id],{'state':'cancel'}) + self.pool.get('stock.picking').write(cr, uid, [pick.id], {'state': 'cancel'}) wf_service = netsvc.LocalService("workflow") for id in ids: @@ -1171,12 +1184,12 @@ class stock_move(osv.osv): return True def action_done(self, cr, uid, ids, context=None): - track_flag=False + track_flag = False for move in self.browse(cr, uid, ids): if move.move_dest_id.id and (move.state != 'done'): cr.execute('insert into stock_move_history_ids (parent_id,child_id) values (%s,%s)', (move.id, move.move_dest_id.id)) - if move.move_dest_id.state in ('waiting','confirmed'): - self.write(cr, uid, [move.move_dest_id.id], {'state':'assigned'}) + if move.move_dest_id.state in ('waiting', 'confirmed'): + self.write(cr, uid, [move.move_dest_id.id], {'state': 'assigned'}) if move.move_dest_id.picking_id: wf_service = netsvc.LocalService("workflow") wf_service.trg_write(uid, 'stock.picking', move.move_dest_id.picking_id.id, cr) @@ -1192,9 +1205,9 @@ class stock_move(osv.osv): acc_src = None acc_dest = None if move.location_id.account_id: - acc_src = move.location_id.account_id.id + acc_src = move.location_id.account_id.id if move.location_dest_id.account_id: - acc_dest = move.location_dest_id.account_id.id + acc_dest = move.location_dest_id.account_id.id if acc_src or acc_dest: test = [('product.product', move.product_id.id)] if move.product_id.categ_id: @@ -1231,7 +1244,7 @@ class stock_move(osv.osv): move.product_id.categ_id.id,)) journal_id = move.product_id.categ_id.property_stock_journal.id if acc_src != acc_dest: - ref = move.picking_id and move.picking_id.name or False + ref = move.picking_id and move.picking_id.name or False product_uom_obj = self.pool.get('product.uom') default_uom = move.product_id.uom_id.id q = product_uom_obj._compute_qty(cr, uid, move.product_uom.id, move.product_qty, default_uom) @@ -1268,7 +1281,7 @@ class stock_move(osv.osv): 'line_id': lines, 'ref': ref, }) - self.write(cr, uid, ids, {'state':'done','date_planned':time.strftime('%Y-%m-%d %H:%M:%S')}) + self.write(cr, uid, ids, {'state': 'done', 'date_planned': time.strftime('%Y-%m-%d %H:%M:%S')}) wf_service = netsvc.LocalService("workflow") for id in ids: wf_service.trg_trigger(uid, 'stock.move', id, cr) @@ -1284,44 +1297,46 @@ class stock_move(osv.osv): stock_move() + class stock_inventory(osv.osv): _name = "stock.inventory" _description = "Inventory" _columns = { - 'name': fields.char('Inventory', size=64, required=True, readonly=True, states={'draft':[('readonly',False)]}), - 'date': fields.datetime('Date create', required=True, readonly=True, states={'draft':[('readonly',False)]}), + 'name': fields.char('Inventory', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}), + 'date': fields.datetime('Date create', required=True, readonly=True, states={'draft': [('readonly', False)]}), 'date_done': fields.datetime('Date done'), - 'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventories', readonly=True, states={'draft':[('readonly',False)]}), + 'inventory_line_id': fields.one2many('stock.inventory.line', 'inventory_id', 'Inventories', readonly=True, states={'draft': [('readonly', False)]}), 'move_ids': fields.many2many('stock.move', 'stock_inventory_move_rel', 'inventory_id', 'move_id', 'Created Moves'), - 'state': fields.selection( (('draft','Draft'),('done','Done')), 'Status', readonly=True), + 'state': fields.selection( (('draft', 'Draft'), ('done', 'Done')), 'Status', readonly=True), } _defaults = { 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'state': lambda *a: 'draft', } + # # Update to support tracking # def action_done(self, cr, uid, ids, context=None): - for inv in self.browse(cr,uid,ids): + for inv in self.browse(cr, uid, ids): move_ids = [] - move_line=[] + move_line = [] for line in inv.inventory_line_id: - pid=line.product_id.id - price=line.product_id.standard_price or 0.0 - amount=self.pool.get('stock.location')._product_get(cr, uid, line.location_id.id, [pid], {'uom': line.product_uom.id})[pid] - change=line.product_qty-amount + pid = line.product_id.id + price = line.product_id.standard_price or 0.0 + amount = self.pool.get('stock.location')._product_get(cr, uid, line.location_id.id, [pid], {'uom': line.product_uom.id})[pid] + change = line.product_qty - amount if change: location_id = line.product_id.product_tmpl_id.property_stock_inventory.id value = { - 'name': 'INV:'+str(line.inventory_id.id)+':'+line.inventory_id.name, + 'name': 'INV:' + str(line.inventory_id.id) + ':' + line.inventory_id.name, 'product_id': line.product_id.id, 'product_uom': line.product_uom.id, 'date': inv.date, 'date_planned': inv.date, 'state': 'assigned' } - if change>0: + if change > 0: value.update( { 'product_qty': change, 'location_id': location_id, @@ -1337,14 +1352,15 @@ class stock_inventory(osv.osv): if len(move_ids): self.pool.get('stock.move').action_done(cr, uid, move_ids, context=context) - self.write(cr, uid, [inv.id], {'state':'done', 'date_done': time.strftime('%Y-%m-%d %H:%M:%S'), 'move_ids': [(6,0,move_ids)]}) + self.write(cr, uid, [inv.id], {'state': 'done', 'date_done': time.strftime('%Y-%m-%d %H:%M:%S'), 'move_ids': [(6, 0, move_ids)]}) return True def action_cancel(self, cr, uid, ids, context={}): - for inv in self.browse(cr,uid,ids): + for inv in self.browse(cr, uid, ids): self.pool.get('stock.move').action_cancel(cr, uid, [x.id for x in inv.move_ids], context) - self.write(cr, uid, [inv.id], {'state':'draft'}) + self.write(cr, uid, [inv.id], {'state': 'draft'}) return True + stock_inventory() @@ -1352,21 +1368,23 @@ class stock_inventory_line(osv.osv): _name = "stock.inventory.line" _description = "Inventory line" _columns = { - 'inventory_id': fields.many2one('stock.inventory','Inventory', ondelete='cascade', select=True), - 'location_id': fields.many2one('stock.location','Location', required=True), - 'product_id': fields.many2one('product.product', 'Product', required=True ), - 'product_uom': fields.many2one('product.uom', 'Product UOM', required=True ), + 'inventory_id': fields.many2one('stock.inventory', 'Inventory', ondelete='cascade', select=True), + 'location_id': fields.many2one('stock.location', 'Location', required=True), + 'product_id': fields.many2one('product.product', 'Product', required=True), + 'product_uom': fields.many2one('product.uom', 'Product UOM', required=True), 'product_qty': fields.float('Quantity') } + def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False): 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 - amount=self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom})[product] - result = {'product_qty':amount, 'product_uom':uom} - return {'value':result} + amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom})[product] + result = {'product_qty': amount, 'product_uom': uom} + return {'value': result} + stock_inventory_line() @@ -1380,57 +1398,60 @@ class stock_warehouse(osv.osv): 'name': fields.char('Name', size=60, required=True), # 'partner_id': fields.many2one('res.partner', 'Owner'), 'partner_address_id': fields.many2one('res.partner.address', 'Owner Address'), - 'lot_input_id': fields.many2one('stock.location', 'Location Input', required=True ), - 'lot_stock_id': fields.many2one('stock.location', 'Location Stock', required=True ), - 'lot_output_id': fields.many2one('stock.location', 'Location Output', required=True ), + 'lot_input_id': fields.many2one('stock.location', 'Location Input', required=True), + 'lot_stock_id': fields.many2one('stock.location', 'Location Stock', required=True), + 'lot_output_id': fields.many2one('stock.location', 'Location Output', required=True), } + stock_warehouse() # Move wizard : # get confirm or assign stock move lines of partner and put in current picking. class stock_picking_move_wizard(osv.osv_memory): - _name='stock.picking.move.wizard' - def _get_picking(self,cr, uid, ctx): - if ctx.get('action_id',False): + _name = 'stock.picking.move.wizard' + + def _get_picking(self, cr, uid, ctx): + if ctx.get('action_id', False): return ctx['action_id'] return False - def _get_picking_address(self,cr,uid,ctx): - picking_obj=self.pool.get('stock.picking') - if ctx.get('action_id',False): - picking=picking_obj.browse(cr,uid,[ctx['action_id']])[0] + + def _get_picking_address(self, cr, uid, ctx): + picking_obj = self.pool.get('stock.picking') + if ctx.get('action_id', False): + picking = picking_obj.browse(cr, uid, [ctx['action_id']])[0] return picking.address_id and picking.address_id.id or False return False - - _columns={ - 'name':fields.char('Name',size=64,invisible=True), + _columns = { + 'name': fields.char('Name', size=64, invisible=True), #'move_lines': fields.one2many('stock.move', 'picking_id', 'Move lines',readonly=True), - 'move_ids': fields.many2many('stock.move', 'picking_move_wizard_rel', 'picking_move_wizard_id', 'move_id', 'Move lines',required=True), - 'address_id' : fields.many2one('res.partner.address', 'Dest. Address',invisible=True), - 'picking_id': fields.many2one('stock.picking', 'Packing list', select=True,invisible=True), + 'move_ids': fields.many2many('stock.move', 'picking_move_wizard_rel', 'picking_move_wizard_id', 'move_id', 'Move lines', required=True), + 'address_id': fields.many2one('res.partner.address', 'Dest. Address', invisible=True), + 'picking_id': fields.many2one('stock.picking', 'Packing list', select=True, invisible=True), } - _defaults={ - 'picking_id':_get_picking, - 'address_id':_get_picking_address, + _defaults = { + 'picking_id': _get_picking, + 'address_id': _get_picking_address, } - def action_move(self,cr,uid,ids,context=None): - move_obj=self.pool.get('stock.move') - picking_obj=self.pool.get('stock.picking') - for act in self.read(cr,uid,ids): - move_lines=move_obj.browse(cr,uid,act['move_ids']) + + def action_move(self, cr, uid, ids, context=None): + move_obj = self.pool.get('stock.move') + picking_obj = self.pool.get('stock.picking') + for act in self.read(cr, uid, ids): + move_lines = move_obj.browse(cr, uid, act['move_ids']) for line in move_lines: if line.picking_id: - picking_obj.write(cr,uid,[line.picking_id.id],{'move_lines':[(1,line.id,{'picking_id':act['picking_id']})]}) - picking_obj.write(cr,uid,[act['picking_id']],{'move_lines':[(1,line.id,{'picking_id':act['picking_id']})]}) + picking_obj.write(cr, uid, [line.picking_id.id], {'move_lines': [(1, line.id, {'picking_id': act['picking_id']})]}) + picking_obj.write(cr, uid, [act['picking_id']], {'move_lines': [(1, line.id, {'picking_id': act['picking_id']})]}) cr.commit() - old_picking=picking_obj.read(cr,uid,[line.picking_id.id])[0] + old_picking = picking_obj.read(cr, uid, [line.picking_id.id])[0] if not len(old_picking['move_lines']): - picking_obj.write(cr,uid,[old_picking['id']],{'state':'done'}) + picking_obj.write(cr, uid, [old_picking['id']], {'state': 'done'}) else: raise osv.except_osv(_('UserError'), _('You can not create new moves.')) - return {'type':'ir.actions.act_window_close' } + return {'type': 'ir.actions.act_window_close'} stock_picking_move_wizard() @@ -1441,9 +1462,10 @@ class report_stock_lines_date(osv.osv): _auto = False _columns = { 'id': fields.integer('Inventory Line Id', readonly=True), - 'product_id':fields.integer('Product Id', readonly=True), + 'product_id': fields.integer('Product Id', readonly=True), 'create_date': fields.datetime('Latest Date of Inventory'), } + def init(self, cr): cr.execute(""" create or replace view report_stock_lines_date as ( @@ -1458,5 +1480,6 @@ class report_stock_lines_date(osv.osv): where l.create_date is not null group by p.id,l.id )""") + report_stock_lines_date() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +