[IMP] clean stock

bzr revid: mra@mra-laptop-20100706112127-mhp249ctoxgg8oae
This commit is contained in:
Mustufa Rangwala 2010-07-06 16:51:27 +05:30
parent fa6cc4cc45
commit 9fbef5aa79
1 changed files with 117 additions and 95 deletions

View File

@ -37,12 +37,12 @@ class stock_incoterms(osv.osv):
_name = "stock.incoterms"
_description = "Incoterms"
_columns = {
'name': fields.char('Name', size=64, required=True,help="Incoterms are series of sales terms.They are used to divide transaction costs and responsibilities between buyer and seller and reflect state-of-the-art transportation practices."),
'code': fields.char('Code', size=3, required=True,help="Code for Incoterms"),
'name': fields.char('Name', size=64, required=True, help="Incoterms are series of sales terms.They are used to divide transaction costs and responsibilities between buyer and seller and reflect state-of-the-art transportation practices."),
'code': fields.char('Code', size=3, required=True, help="Code for Incoterms"),
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the incoterms without removing it."),
}
_defaults = {
'active': lambda *a: True,
'active': True,
}
stock_incoterms()
@ -52,11 +52,12 @@ class stock_journal(osv.osv):
_description = "Stock Journal"
_columns = {
'name': fields.char('Stock Journal', size=32, required=True),
'user_id': fields.many2one('res.users','Responsible'),
'user_id': fields.many2one('res.users', 'Responsible'),
}
_defaults = {
'user_id': lambda s,c,u,ctx: u
'user_id': lambda s, c, u, ctx: u
}
stock_journal()
#----------------------------------------------------------
@ -70,22 +71,24 @@ class stock_location(osv.osv):
_parent_order = 'id'
_order = 'parent_left'
def name_get(self, cr, uid, ids, context={}):
def name_get(self, cr, uid, ids, context=None):
res = []
if context is None:
context = {}
if not len(ids):
return []
reads = self.read(cr, uid, ids, ['name','location_id'], context)
res = []
reads = self.read(cr, uid, ids, ['name','location_id'], context=context)
for record in reads:
name = record['name']
if context.get('full',False):
if record['location_id']:
name = record['location_id'][1]+' / '+name
name = record['location_id'][1] + ' / ' + name
res.append((record['id'], name))
else:
res.append((record['id'], name))
return res
def _complete_name(self, cr, uid, ids, name, args, context):
def _complete_name(self, cr, uid, ids, name, args, context=None):
""" Forms complete name of location from parent location to child location.
@return: Dictionary of values
"""
@ -100,7 +103,7 @@ class stock_location(osv.osv):
res[m.id] = _get_one_full_name(m)
return res
def _product_qty_available(self, cr, uid, ids, field_names, arg, context={}):
def _product_qty_available(self, cr, uid, ids, field_names, arg, context=None):
""" Finds real and virtual quantity for product available at particular location.
@return: Dictionary of values
"""
@ -119,7 +122,7 @@ class stock_location(osv.osv):
res[loc]['stock_virtual'] = prod.virtual_available
return res
def product_detail(self, cr, uid, id, field, context={}):
def product_detail(self, cr, uid, id, field, context=None):
""" Finds detail of product like price type, currency and then calculates its price.
@param field: Field name
@return: Calculated price
@ -136,7 +139,7 @@ class stock_location(osv.osv):
# Choose the right filed standard_price to read
# Take the user company
price_type_id = self.pool.get('res.users').browse(cr,uid,uid).company_id.property_valuation_price_type.id
pricetype = self.pool.get('product.price.type').browse(cr, uid, price_type_id)
pricetype = self.pool.get('product.price.type').browse(cr, uid, price_type_id, context=context)
for r in result:
c = (context or {}).copy()
c['location'] = id
@ -145,11 +148,10 @@ class stock_location(osv.osv):
context['currency_id'] = self.pool.get('res.users').browse(cr,uid,uid).company_id.currency_id.id
amount_unit = self.pool.get('product.product').browse(cr,uid,r['product_id']).price_get(pricetype.field, context)[r['product_id']]
final_value += (product[field_to_read] * amount_unit)
return final_value
def _product_value(self, cr, uid, ids, field_names, arg, context={}):
def _product_value(self, cr, uid, ids, field_names, arg, context=None):
""" Calculates real and virtual stock value of a product.
@param field_names: Name of field
@return: Dictionary of values
@ -209,20 +211,20 @@ class stock_location(osv.osv):
'scrap_location': fields.boolean('Scrap Location', help='Check this box if the current location is a place for destroyed items'),
}
_defaults = {
'active': lambda *a: 1,
'usage': lambda *a: 'internal',
'allocation_method': lambda *a: 'fifo',
'chained_location_type': lambda *a: 'none',
'chained_auto_packing': lambda *a: 'manual',
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location', context=c),
'posx': lambda *a: 0,
'posy': lambda *a: 0,
'posz': lambda *a: 0,
'icon': lambda *a: False,
'scrap_location': lambda *a: False,
'active': 1,
'usage': 'internal',
'allocation_method': 'fifo',
'chained_location_type': 'none',
'chained_auto_packing': 'manual',
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.location', context=c),
'posx': 0,
'posy': 0,
'posz': 0,
'icon': False,
'scrap_location': False,
}
def chained_location_get(self, cr, uid, location, partner=None, product=None, context={}):
def chained_location_get(self, cr, uid, location, partner=None, product=None, context=None):
""" Finds chained location
@param location: Location id
@param partner: Partner id
@ -239,7 +241,7 @@ class stock_location(osv.osv):
return result, location.chained_auto_packing, location.chained_delay, location.chained_journal_id and location.chained_journal_id.id or False, location.chained_company_id and location.chained_company_id.id or False, location.chained_picking_type
return result
def picking_type_get(self, cr, uid, from_location, to_location, context={}):
def picking_type_get(self, cr, uid, from_location, to_location, context=None):
""" Gets type of picking.
@param from_location: Source location
@param to_location: Destination location
@ -248,14 +250,12 @@ class stock_location(osv.osv):
result = 'internal'
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
def _product_get_all_report(self, cr, uid, ids, product_ids=False,
context=None):
return self._product_get_report(cr, uid, ids, product_ids, context,
recursive=True)
def _product_get_all_report(self, cr, uid, ids, product_ids=False, context=None):
return self._product_get_report(cr, uid, ids, product_ids, context, recursive=True)
def _product_get_report(self, cr, uid, ids, product_ids=False,
context=None, recursive=False):
@ -416,7 +416,7 @@ class stock_tracking(osv.osv):
return (10 - (sum % 10)) % 10
checksum = staticmethod(checksum)
def make_sscc(self, cr, uid, context={}):
def make_sscc(self, cr, uid, context=None):
sequence = self.pool.get('ir.sequence').get(cr, uid, 'stock.lot.tracking')
return sequence + str(self.checksum(sequence))
@ -428,9 +428,9 @@ class stock_tracking(osv.osv):
'date': fields.datetime('Created Date', required=True),
}
_defaults = {
'active': lambda *a: 1,
'active': 1,
'name': make_sscc,
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
}
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
@ -442,7 +442,7 @@ class stock_tracking(osv.osv):
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={}):
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
res = [(r['id'], r['name']+' ['+(r['serial'] or '')+']') for r in self.read(cr, uid, ids, ['name', 'serial'], context)]
@ -461,7 +461,7 @@ class stock_picking(osv.osv):
_name = "stock.picking"
_description = "Picking List"
def _set_maximum_date(self, cr, uid, ids, name, value, arg, context):
def _set_maximum_date(self, cr, uid, ids, name, value, arg, context=None):
""" Calculates planned date if it is greater than 'value'.
@param name: Name of field
@param value: Value of field
@ -483,7 +483,7 @@ class stock_picking(osv.osv):
cr.execute(sql_str)
return True
def _set_minimum_date(self, cr, uid, ids, name, value, arg, context):
def _set_minimum_date(self, cr, uid, ids, name, value, arg, context=None):
""" Calculates planned date if it is less than 'value'.
@param name: Name of field
@param value: Value of field
@ -494,7 +494,7 @@ class stock_picking(osv.osv):
return False
if isinstance(ids, (int, long)):
ids = [ids]
for pick in self.browse(cr, uid, ids, context):
for pick in self.browse(cr, uid, ids, context=context):
sql_str = """update stock_move set
date_planned='%s'
where
@ -504,7 +504,7 @@ class stock_picking(osv.osv):
cr.execute(sql_str)
return True
def get_min_max_date(self, cr, uid, ids, field_name, arg, context={}):
def get_min_max_date(self, cr, uid, ids, field_name, arg, context=None):
""" Finds minimum and maximum dates for picking.
@return: Dictionary of values
"""
@ -587,16 +587,16 @@ class stock_picking(osv.osv):
}
_defaults = {
'name': lambda self, cr, uid, context: '/',
'active': lambda *a: 1,
'state': lambda *a: 'draft',
'move_type': lambda *a: 'direct',
'type': lambda *a: 'in',
'invoice_state': lambda *a: 'none',
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
'active': 1,
'state': 'draft',
'move_type': 'direct',
'type': 'in',
'invoice_state': 'none',
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.picking', context=c)
}
def copy(self, cr, uid, id, default=None, context={}):
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
default = default.copy()
@ -604,16 +604,15 @@ class stock_picking(osv.osv):
if ('name' not in default) or (picking_obj.name=='/'):
seq_obj_name = 'stock.picking.' + picking_obj.type
default['name'] = self.pool.get('ir.sequence').get(cr, uid, seq_obj_name)
return super(stock_picking, self).copy(cr, uid, id, default, context)
def onchange_partner_in(self, cr, uid, context, partner_id=None):
def onchange_partner_in(self, cr, uid, context=None, partner_id=None):
return {}
def action_explode(self, cr, uid, moves, context={}):
def action_explode(self, cr, uid, moves, context=None):
return moves
def action_confirm(self, cr, uid, ids, context={}):
def action_confirm(self, cr, uid, ids, context=None):
""" Confirms picking.
@return: True
"""
@ -625,7 +624,7 @@ class stock_picking(osv.osv):
todo.append(r.id)
todo = self.action_explode(cr, uid, todo, context)
if len(todo):
self.pool.get('stock.move').action_confirm(cr, uid, todo, context)
self.pool.get('stock.move').action_confirm(cr, uid, todo, context=context)
return True
def test_auto_picking(self, cr, uid, ids):
@ -1191,7 +1190,7 @@ stock_picking()
class stock_production_lot(osv.osv):
def name_get(self, cr, uid, ids, context={}):
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
reads = self.read(cr, uid, ids, ['name', 'prefix', 'ref'], context)
@ -1209,7 +1208,7 @@ class stock_production_lot(osv.osv):
_name = 'stock.production.lot'
_description = 'Production lot'
def _get_stock(self, cr, uid, ids, field_name, arg, context={}):
def _get_stock(self, cr, uid, ids, field_name, arg, context=None):
""" Gets stock of products for locations
@return: Dictionary of values
"""
@ -1233,7 +1232,7 @@ class stock_production_lot(osv.osv):
res.update(dict(cr.fetchall()))
return res
def _stock_search(self, cr, uid, obj, name, args, context):
def _stock_search(self, cr, uid, obj, name, args, context=None):
""" Searches Ids of products
@return: Ids of locations
"""
@ -1261,7 +1260,7 @@ class stock_production_lot(osv.osv):
'company_id': fields.many2one('res.company','Company',select=1),
}
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date': 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),
}
@ -1287,7 +1286,7 @@ class stock_production_lot_revision(osv.osv):
_defaults = {
'author_id': lambda x, y, z, c: z,
'date': lambda *a: time.strftime('%Y-%m-%d'),
'date': time.strftime('%Y-%m-%d'),
}
stock_production_lot_revision()
@ -1302,7 +1301,7 @@ stock_production_lot_revision()
#
class stock_move(osv.osv):
def _getSSCC(self, cr, uid, context={}):
def _getSSCC(self, cr, uid, context=None):
cr.execute('select id from stock_tracking where create_uid=%s order by id desc limit 1', (uid,))
res = cr.fetchone()
return (res and res[0]) or False
@ -1311,7 +1310,7 @@ class stock_move(osv.osv):
_order = 'date_expected desc, id'
_log_create = False
def name_get(self, cr, uid, ids, context={}):
def name_get(self, cr, uid, ids, context=None):
res = []
for line in self.browse(cr, uid, ids, context):
res.append((line.id, (line.product_id.code or '/')+': '+line.location_id.name+' > '+line.location_dest_id.name))
@ -1391,7 +1390,7 @@ class stock_move(osv.osv):
'You try to assign a lot which is not from the same product',
['prodlot_id'])]
def _default_location_destination(self, cr, uid, context={}):
def _default_location_destination(self, cr, uid, context=None):
""" Gets default address of partner for destination location
@return: Address id or False
"""
@ -1407,7 +1406,7 @@ class stock_move(osv.osv):
return property_out and property_out.id or False
return False
def _default_location_source(self, cr, uid, context={}):
def _default_location_source(self, cr, uid, context=None):
""" Gets default address of partner for source location
@return: Address id or False
"""
@ -1423,24 +1422,24 @@ class stock_move(osv.osv):
_defaults = {
'location_id': _default_location_source,
'location_dest_id': _default_location_destination,
'state': lambda *a: 'draft',
'priority': lambda *a: '1',
'product_qty': lambda *a: 1.0,
'scraped' : lambda *a: False,
'date_planned': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'state': 'draft',
'priority': '1',
'product_qty': 1.0,
'scraped' : False,
'date_planned': time.strftime('%Y-%m-%d %H:%M:%S'),
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.move', context=c),
'date_expected': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
'date_expected': time.strftime('%Y-%m-%d %H:%M:%S'),
}
def copy(self, cr, uid, id, default=None, context={}):
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
default = default.copy()
return super(stock_move, self).copy(cr, uid, id, default, context)
return super(stock_move, self).copy(cr, uid, id, default, context=context)
def _auto_init(self, cursor, context):
res = super(stock_move, self)._auto_init(cursor, context)
def _auto_init(self, cursor, context=None):
res = super(stock_move, self)._auto_init(cursor, context=contexts)
cursor.execute('SELECT indexname \
FROM pg_indexes \
WHERE indexname = \'stock_move_location_id_location_dest_id_product_id_state\'')
@ -1533,7 +1532,7 @@ class stock_move(osv.osv):
result['location_dest_id'] = loc_dest_id
return {'value': result}
def _chain_compute(self, cr, uid, moves, context={}):
def _chain_compute(self, cr, uid, moves, context=None):
""" Finds whether the location has chained location type or not.
@param moves: Stock moves
@return: Dictionary containing destination location with chained location type.
@ -1559,7 +1558,7 @@ class stock_move(osv.osv):
result[m.picking_id].append( (m, dest) )
return result
def action_confirm(self, cr, uid, ids, context={}):
def action_confirm(self, cr, uid, ids, context=None):
""" Confirms stock move.
@return: List of ids.
"""
@ -1568,10 +1567,12 @@ class stock_move(osv.osv):
self.write(cr, uid, ids, {'state': 'confirmed'})
i = 0
def create_chained_picking(self, cr, uid, moves, context):
def create_chained_picking(self, cr, uid, moves, context=None):
new_moves = []
res_obj = self.pool.get('res.company')
for picking, todo in self._chain_compute(cr, uid, moves, context).items():
if context is None:
context = {}
for picking, todo in self._chain_compute(cr, uid, moves, context=context).items():
ptype = todo[0][1][5] and todo[0][1][5] or self.pool.get('stock.location').picking_type_get(cr, uid, todo[0][0].location_dest_id, todo[0][1][0])
pick_name = ''
if ptype == 'delivery':
@ -1641,13 +1642,15 @@ class stock_move(osv.osv):
#
# Duplicate stock.move
#
def check_assign(self, cr, uid, ids, context={}):
def check_assign(self, cr, uid, ids, context=None):
""" Checks the product type and accordingly writes the state.
@return: No. of moves done
"""
done = []
count = 0
pickings = {}
if context is None:
context = {}
for move in self.browse(cr, uid, ids, context=context):
if move.product_id.type == 'consu':
if move.state in ('confirmed', 'waiting'):
@ -1697,12 +1700,14 @@ class stock_move(osv.osv):
#
# Cancel move => cancel others move and pickings
#
def action_cancel(self, cr, uid, ids, context={}):
def action_cancel(self, cr, uid, ids, context=None):
""" Cancels the moves and if all moves are cancelled it cancels the picking.
@return: True
"""
if not len(ids):
return True
if context is None:
context = {}
pickings = {}
for move in self.browse(cr, uid, ids):
if move.state in ('confirmed', 'waiting', 'assigned', 'draft'):
@ -1735,6 +1740,9 @@ class stock_move(osv.osv):
acc_variation = accounts['property_stock_variation']
journal_id = accounts['stock_journal']
if context is None:
context = {}
if not acc_src:
raise osv.except_osv(_('Error!'), _('There is no stock input account defined ' \
'for this product: "%s" (id: %d)') % \
@ -1767,7 +1775,7 @@ class stock_move(osv.osv):
return journal_id, acc_src, acc_dest, acc_variation, amount
def action_done(self, cr, uid, ids, context={}):
def action_done(self, cr, uid, ids, context=None):
""" Makes the move done and if all moves are done, it will finish the picking.
@return:
"""
@ -1775,8 +1783,10 @@ class stock_move(osv.osv):
picking_ids = []
product_uom_obj = self.pool.get('product.uom')
price_type_obj = self.pool.get('product.price.type')
product_obj=self.pool.get('product.product')
product_obj = self.pool.get('product.product')
move_obj = self.pool.get('account.move')
if context is None:
context = {}
for move in self.browse(cr, uid, ids):
if move.picking_id:
picking_ids.append(move.picking_id.id)
@ -1852,11 +1862,12 @@ class stock_move(osv.osv):
for (id,name) in picking_obj.name_get(cr, uid, picking_ids):
message = _('Document') + " '" + name + "' "+ _("is processed")
self.log(cr, uid, id, message)
return True
def create_account_move(self, cr, uid, move,account_id,account_variation,amount, context=None):
def create_account_move(self, cr, uid, move,account_id, account_variation, amount, context=None):
if context is None:
context = {}
partner_id = move.picking_id.address_id and (move.picking_id.address_id.partner_id and move.picking_id.address_id.partner_id.id or False) or False
lines=[(0, 0, {
'name': move.name,
@ -1939,6 +1950,8 @@ class stock_move(osv.osv):
@return: Splited move lines
"""
if context is None:
context = {}
if quantity <= 0:
raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
@ -2055,7 +2068,7 @@ class stock_move(osv.osv):
self.action_done(cr, uid, res)
return res
def do_partial(self, cr, uid, ids, partial_datas, context={}):
def do_partial(self, cr, uid, ids, partial_datas, context=None):
""" Makes partial pickings and moves done.
@param partial_datas: Dictionary containing details of partial picking
like partner_id, address_id, delivery_date, delivery
@ -2073,9 +2086,11 @@ class stock_move(osv.osv):
partner_id = partial_datas.get('partner_id', False)
address_id = partial_datas.get('address_id', False)
delivery_date = partial_datas.get('delivery_date', False)
new_moves = []
if context is None:
context = {}
complete, too_many, too_few = [], [], []
move_product_qty = {}
for move in self.browse(cr, uid, ids, context=context):
@ -2153,7 +2168,7 @@ class stock_move(osv.osv):
complete.append(move)
for move in complete:
self.action_done(cr, uid, [move.id], context)
self.action_done(cr, uid, [move.id], context=context)
if move.picking_id.id :
# TOCHECK : Done picking if all moves are done
cr.execute("""
@ -2248,7 +2263,7 @@ class stock_inventory(osv.osv):
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={}):
def action_cancel(self, cr, uid, ids, context=None):
""" Cancels the stock move and change inventory state to draft.
@return: True
"""
@ -2257,7 +2272,7 @@ class stock_inventory(osv.osv):
self.write(cr, uid, [inv.id], {'state': 'draft'})
return True
def action_cancel_inventary(self, cr, uid, ids, context={}):
def action_cancel_inventary(self, cr, uid, ids, context=None):
""" Cancels both stock move and inventory
@return: True
"""
@ -2268,7 +2283,6 @@ class stock_inventory(osv.osv):
stock_inventory()
class stock_inventory_line(osv.osv):
_name = "stock.inventory.line"
_description = "Inventory Line"
@ -2318,8 +2332,9 @@ class stock_warehouse(osv.osv):
'lot_output_id': fields.many2one('stock.location', 'Location Output', required=True, domain=[('usage','<>','view')]),
}
_defaults = {
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.inventory', context=c),
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.inventory', context=c),
}
stock_warehouse()
@ -2328,15 +2343,19 @@ stock_warehouse()
class stock_picking_move_wizard(osv.osv_memory):
_name = 'stock.picking.move.wizard'
def _get_picking(self, cr, uid, ctx):
def _get_picking(self, cr, uid, ctx=None):
if ctx is None:
ctx = {}
if ctx.get('action_id', False):
return ctx['action_id']
return False
def _get_picking_address(self, cr, uid, ctx):
def _get_picking_address(self, cr, uid, context=None):
picking_obj = self.pool.get('stock.picking')
if ctx.get('action_id', False):
picking = picking_obj.browse(cr, uid, [ctx['action_id']])[0]
if context is None:
context = {}
if context.get('action_id', False):
picking = picking_obj.browse(cr, uid, [context['action_id']])[0]
return picking.address_id and picking.address_id.id or False
return False
@ -2404,6 +2423,7 @@ class report_products_to_received_planned(osv.osv):
group by stock.date_planned
)
""")
report_products_to_received_planned()
class report_delivery_products_planned(osv.osv):
@ -2440,5 +2460,7 @@ class report_delivery_products_planned(osv.osv):
)
""")
report_delivery_products_planned()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: