bugfixstockproduct
bzr revid: fp@tinyerp.com-20080923142403-k5fhi08mj9abjh50
This commit is contained in:
commit
de8973b153
|
@ -21,15 +21,20 @@
|
|||
<field name="code">liability</field>
|
||||
<field name="close_method">balance</field>
|
||||
</record>
|
||||
<record id="account_type_cash_equity" model="account.account.type">
|
||||
<field name="name">Equity</field>
|
||||
<field name="code">equity</field>
|
||||
<field name="close_method">balance</field>
|
||||
</record>
|
||||
<record id="account_type_income" model="account.account.type">
|
||||
<field name="name">Income</field>
|
||||
<field name="code">income</field>
|
||||
<field name="close_method">none</field>
|
||||
<field name="close_method">unreconciled</field>
|
||||
</record>
|
||||
<record id="account_type_expense" model="account.account.type">
|
||||
<field name="name">Expense</field>
|
||||
<field name="code">expense</field>
|
||||
<field name="close_method">none</field>
|
||||
<field name="close_method">unreconciled</field>
|
||||
</record>
|
||||
<record id="account_type_cash_moves" model="account.account.type">
|
||||
<field name="name">Cash</field>
|
||||
|
|
|
@ -142,10 +142,12 @@ class account_invoice_line(osv.osv):
|
|||
'sequence': fields.integer('Sequence Number'),
|
||||
'functional_field': fields.function(_fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='char', fnct_search=None, obj=None, method=True, store=False, string="Source Account"),
|
||||
}
|
||||
|
||||
def _default_account(self, cr, uid, context=None):
|
||||
cr.execute("select id from account_account where code = 0 LIMIT 1")
|
||||
cr.execute("select id from account_account where parent_id IS NULL LIMIT 1")
|
||||
res=cr.fetchone()
|
||||
return res[0]
|
||||
|
||||
_defaults = {
|
||||
'state': lambda *a: 'article',
|
||||
# 'account_id': _default_account
|
||||
|
|
|
@ -331,8 +331,6 @@ class product_product(osv.osv):
|
|||
res = super(product_product, self).view_header_get(cr, uid, view_id, view_type, context)
|
||||
if (context.get('categ_id', False)):
|
||||
return _('Products: ')+self.pool.get('product.category').browse(cr, uid, context['categ_id'], context).name
|
||||
if (context.get('location', False)):
|
||||
return _('Products: ')+self.pool.get('stock.location').browse(cr, uid, context['location'], context).name
|
||||
return res
|
||||
|
||||
def _product_price(self, cr, uid, ids, name, arg, context={}):
|
||||
|
|
|
@ -32,63 +32,174 @@ from osv import fields, osv
|
|||
|
||||
class product_product(osv.osv):
|
||||
_inherit = "product.product"
|
||||
# def view_header_get(self, cr, user, view_id, view_type, context):
|
||||
# print self, cr, user
|
||||
# res = super(product_product, self).view_header_get(cr, user, view_id, view_type, context)
|
||||
# if res: return res
|
||||
# if (not context.get('location', False)):
|
||||
# return False
|
||||
# cr.execute('select name from stock_location where id=%d', (context['location'],))
|
||||
# j = cr.fetchone()[0]
|
||||
# if j:
|
||||
# return 'Products: '+j
|
||||
# return False
|
||||
#
|
||||
def _get_product_available_func(states, what):
|
||||
def _product_available(self, cr, uid, ids, name, arg, context={}):
|
||||
if context.get('shop', False):
|
||||
cr.execute('select warehouse_id from sale_shop where id=%d', (int(context['shop']),))
|
||||
res2 = cr.fetchone()
|
||||
if res2:
|
||||
context['warehouse'] = res2[0]
|
||||
def view_header_get(self, cr, user, view_id, view_type, context):
|
||||
res = super(product_product, self).view_header_get(cr, user, view_id, view_type, context)
|
||||
if res: return res
|
||||
if (context.get('location', False)):
|
||||
return _('Products: ')+self.pool.get('stock.location').browse(cr, uid, context['location'], context).name
|
||||
return res
|
||||
|
||||
if context.get('warehouse', False):
|
||||
cr.execute('select lot_stock_id from stock_warehouse where id=%d', (int(context['warehouse']),))
|
||||
res2 = cr.fetchone()
|
||||
if res2:
|
||||
context['location'] = res2[0]
|
||||
|
||||
if context.get('location', False):
|
||||
location_ids = [context['location']]
|
||||
else:
|
||||
cr.execute("select lot_stock_id from stock_warehouse")
|
||||
location_ids = [id for (id,) in cr.fetchall()]
|
||||
|
||||
# build the list of ids of children of the location given by id
|
||||
location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids)])
|
||||
res = self.pool.get('stock.location')._product_get_multi_location(cr, uid, location_ids, ids, context, states, what)
|
||||
for id in ids:
|
||||
res.setdefault(id, 0.0)
|
||||
def get_product_available(self,cr,uid,ids,context={}):
|
||||
states=context.get('states',[])
|
||||
what=context.get('what',())
|
||||
if not ids:
|
||||
ids = self.search(cr, uid, [])
|
||||
res = {}.fromkeys(ids, 0.0)
|
||||
if not ids:
|
||||
return res
|
||||
|
||||
if context.get('shop', False):
|
||||
cr.execute('select warehouse_id from sale_shop where id=%d', (int(context['shop']),))
|
||||
res2 = cr.fetchone()
|
||||
if res2:
|
||||
context['warehouse'] = res2[0]
|
||||
|
||||
if context.get('warehouse', False):
|
||||
cr.execute('select lot_stock_id from stock_warehouse where id=%d', (int(context['warehouse']),))
|
||||
res2 = cr.fetchone()
|
||||
if res2:
|
||||
context['location'] = res2[0]
|
||||
|
||||
if context.get('location', False):
|
||||
location_ids = [context['location']]
|
||||
else:
|
||||
cr.execute("select lot_stock_id from stock_warehouse")
|
||||
location_ids = [id for (id,) in cr.fetchall()]
|
||||
|
||||
# build the list of ids of children of the location given by id
|
||||
location_ids = self.pool.get('stock.location').search(cr, uid, [('location_id', 'child_of', location_ids)])
|
||||
|
||||
states_str = ','.join(map(lambda s: "'%s'" % s, states))
|
||||
|
||||
product2uom = {}
|
||||
for product in self.browse(cr, uid, ids, context=context):
|
||||
product2uom[product.id] = product.uom_id.id
|
||||
|
||||
prod_ids_str = ','.join(map(str, ids))
|
||||
location_ids_str = ','.join(map(str, location_ids))
|
||||
results = []
|
||||
results2 = []
|
||||
|
||||
from_date=context.get('from_date',False)
|
||||
to_date=context.get('to_date',False)
|
||||
date_str=False
|
||||
if from_date and to_date:
|
||||
date_str="date>='%s' and date<=%s"%(from_date,to_date)
|
||||
elif from_date:
|
||||
date_str="date>='%s'"%(from_date)
|
||||
elif to_date:
|
||||
date_str="date<='%s'"%(to_date)
|
||||
|
||||
if 'in' in what:
|
||||
# all moves from a location out of the set to a location in the set
|
||||
cr.execute(
|
||||
'select sum(product_qty), product_id, product_uom '\
|
||||
'from stock_move '\
|
||||
'where location_id not in ('+location_ids_str+') '\
|
||||
'and location_dest_id in ('+location_ids_str+') '\
|
||||
'and product_id in ('+prod_ids_str+') '\
|
||||
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\
|
||||
'group by product_id,product_uom'
|
||||
)
|
||||
results = cr.fetchall()
|
||||
if 'out' in what:
|
||||
# all moves from a location in the set to a location out of the set
|
||||
cr.execute(
|
||||
'select sum(product_qty), product_id, product_uom '\
|
||||
'from stock_move '\
|
||||
'where location_id in ('+location_ids_str+') '\
|
||||
'and location_dest_id not in ('+location_ids_str+') '\
|
||||
'and product_id in ('+prod_ids_str+') '\
|
||||
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\
|
||||
'group by product_id,product_uom'
|
||||
)
|
||||
results2 = cr.fetchall()
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
for amount, prod_id, prod_uom in results:
|
||||
amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
|
||||
context.get('uom', False) or product2uom[prod_id])
|
||||
res[prod_id] += amount
|
||||
for amount, prod_id, prod_uom in results2:
|
||||
amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
|
||||
context.get('uom', False) or product2uom[prod_id])
|
||||
res[prod_id] -= amount
|
||||
return res
|
||||
|
||||
def _get_product_available_func(states, what):
|
||||
def _product_available(self, cr, uid, ids, field_names=False, arg=False, context={}):
|
||||
context.update({
|
||||
'states':states,
|
||||
'what':what
|
||||
})
|
||||
stock=self.get_product_available(cr,uid,ids,context=context)
|
||||
res = {}
|
||||
for id in ids:
|
||||
res[id] = {}.fromkeys(field_names, 0.0)
|
||||
for a in field_names:
|
||||
res[id][a] = stock.get(id, 0.0)
|
||||
return res
|
||||
|
||||
return _product_available
|
||||
|
||||
_product_qty_available = _get_product_available_func(('done',), ('in', 'out'))
|
||||
_product_virtual_available = _get_product_available_func(('confirmed','waiting','assigned','done'), ('in', 'out'))
|
||||
_product_outgoing_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('out',))
|
||||
_product_incoming_qty = _get_product_available_func(('confirmed','waiting','assigned'), ('in',))
|
||||
|
||||
|
||||
_columns = {
|
||||
'qty_available': fields.function(_product_qty_available, method=True, type='float', string='Real Stock', help="Current quantities of products in selected locations or all internal if none have been selected."),
|
||||
'virtual_available': fields.function(_product_virtual_available, method=True, type='float', string='Virtual Stock', help="Futur stock for this product according to the selected location or all internal if none have been selected. Computed as: Real Stock - Outgoing + Incoming."),
|
||||
'incoming_qty': fields.function(_product_incoming_qty, method=True, type='float', string='Incoming', help="Quantities of products that are planned to arrive in selected locations or all internal if none have been selected."),
|
||||
'outgoing_qty': fields.function(_product_outgoing_qty, method=True, type='float', string='Outgoing', help="Quantities of products that are planned to leave in selected locations or all internal if none have been selected."),
|
||||
'qty_available': fields.function(_product_qty_available, method=True, type='float', string='Real Stock',multi='qty_available', help="Current quantities of products in selected locations or all internal if none have been selected."),
|
||||
'virtual_available': fields.function(_product_virtual_available, method=True, type='float', string='Virtual Stock',multi='qty_available', help="Futur stock for this product according to the selected location or all internal if none have been selected. Computed as: Real Stock - Outgoing + Incoming."),
|
||||
'incoming_qty': fields.function(_product_incoming_qty, method=True, type='float', string='Incoming',multi='qty_available', help="Quantities of products that are planned to arrive in selected locations or all internal if none have been selected."),
|
||||
'outgoing_qty': fields.function(_product_outgoing_qty, method=True, type='float', string='Outgoing',multi='qty_available', help="Quantities of products that are planned to leave in selected locations or all internal if none have been selected."),
|
||||
'track_production' : fields.boolean('Track Production Lots' , help="Force to use a Production Lot during production order"),
|
||||
'track_incoming' : fields.boolean('Track Incomming Lots', help="Force to use a Production Lot during receptions"),
|
||||
'track_outgoing' : fields.boolean('Track Outging Lots', help="Force to use a Production Lot during deliveries"),
|
||||
}
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False):
|
||||
res = super(product_product,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar)
|
||||
if ('location' in context) and context['location']:
|
||||
location_info = self.pool.get('stock.location').browse(cr, uid, context['location'])
|
||||
fields=res.get('fields',{})
|
||||
if fields:
|
||||
if location_info.usage == 'supplier':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur Receptions'
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = 'Received Qty'
|
||||
|
||||
if location_info.usage == 'internal':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur Stock'
|
||||
|
||||
if location_info.usage == 'customer':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur Deliveries'
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = 'Delivered Qty'
|
||||
|
||||
if location_info.usage == 'inventory':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur P&L'
|
||||
res['fields']['qty_available']['string'] = 'P&L Qty'
|
||||
|
||||
if location_info.usage == 'procurement':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur Qty'
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = 'Unplanned Qty'
|
||||
|
||||
if location_info.usage == 'production':
|
||||
if fields.get('virtual_available'):
|
||||
res['fields']['virtual_available']['string'] = 'Futur Productions'
|
||||
if fields.get('qty_available'):
|
||||
res['fields']['qty_available']['string'] = 'Produced Qty'
|
||||
|
||||
return res
|
||||
product_product()
|
||||
|
||||
|
||||
class product_product(osv.osv):
|
||||
class product_template(osv.osv):
|
||||
_name = 'product.template'
|
||||
_inherit = 'product.template'
|
||||
_columns = {
|
||||
|
@ -126,7 +237,7 @@ class product_product(osv.osv):
|
|||
help='This account will be used, instead of the default one, to value output stock'),
|
||||
}
|
||||
|
||||
product_product()
|
||||
product_template()
|
||||
|
||||
|
||||
class product_category(osv.osv):
|
||||
|
|
|
@ -201,69 +201,14 @@ class stock_location(osv.osv):
|
|||
})
|
||||
return result
|
||||
|
||||
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')
|
||||
states_str = ','.join(map(lambda s: "'%s'" % s, states))
|
||||
if not product_ids:
|
||||
product_ids = product_obj.search(cr, uid, [])
|
||||
res = {}.fromkeys(product_ids, 0.0)
|
||||
if not ids:
|
||||
return res
|
||||
|
||||
product2uom = {}
|
||||
for product in product_obj.browse(cr, uid, product_ids, context=context):
|
||||
product2uom[product.id] = product.uom_id.id
|
||||
|
||||
prod_ids_str = ','.join(map(str, product_ids))
|
||||
location_ids_str = ','.join(map(str, ids))
|
||||
results = []
|
||||
results2 = []
|
||||
|
||||
from_date=context.get('from_date',False)
|
||||
to_date=context.get('to_date',False)
|
||||
date_str=False
|
||||
if from_date and to_date:
|
||||
date_str="date>='%s' and date<=%s"%(from_date,to_date)
|
||||
elif from_date:
|
||||
date_str="date>='%s'"%(from_date)
|
||||
elif to_date:
|
||||
date_str="date<='%s'"%(to_date)
|
||||
|
||||
if 'in' in what:
|
||||
# all moves from a location out of the set to a location in the set
|
||||
cr.execute(
|
||||
'select sum(product_qty), product_id, product_uom '\
|
||||
'from stock_move '\
|
||||
'where location_id not in ('+location_ids_str+') '\
|
||||
'and location_dest_id in ('+location_ids_str+') '\
|
||||
'and product_id in ('+prod_ids_str+') '\
|
||||
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\
|
||||
'group by product_id,product_uom'
|
||||
)
|
||||
results = cr.fetchall()
|
||||
if 'out' in what:
|
||||
# all moves from a location in the set to a location out of the set
|
||||
cr.execute(
|
||||
'select sum(product_qty), product_id, product_uom '\
|
||||
'from stock_move '\
|
||||
'where location_id in ('+location_ids_str+') '\
|
||||
'and location_dest_id not in ('+location_ids_str+') '\
|
||||
'and product_id in ('+prod_ids_str+') '\
|
||||
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\
|
||||
'group by product_id,product_uom'
|
||||
)
|
||||
results2 = cr.fetchall()
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
for amount, prod_id, prod_uom in results:
|
||||
amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
|
||||
context.get('uom', False) or product2uom[prod_id])
|
||||
res[prod_id] += amount
|
||||
for amount, prod_id, prod_uom in results2:
|
||||
amount = uom_obj._compute_qty(cr, uid, prod_uom, amount,
|
||||
context.get('uom', False) or product2uom[prod_id])
|
||||
res[prod_id] -= amount
|
||||
return res
|
||||
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
|
||||
})
|
||||
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 []
|
||||
|
@ -1383,39 +1328,4 @@ class stock_picking_move_wizard(osv.osv_memory):
|
|||
return {'type':'ir.actions.act_window_close' }
|
||||
|
||||
stock_picking_move_wizard()
|
||||
|
||||
class product_product(osv.osv):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False):
|
||||
res = super(product_product,self).fields_view_get(cr, uid, view_id, view_type, context, toolbar)
|
||||
if ('location' in context) and context['location']:
|
||||
location_info = self.pool.get('stock.location').browse(cr, uid, context['location'])
|
||||
|
||||
if location_info.usage == 'supplier':
|
||||
res['fields']['virtual_available']['string'] = 'Futur Receptions'
|
||||
res['fields']['qty_available']['string'] = 'Received Qty'
|
||||
|
||||
if location_info.usage == 'internal':
|
||||
res['fields']['virtual_available']['string'] = 'Futur Stock'
|
||||
|
||||
if location_info.usage == 'customer':
|
||||
res['fields']['virtual_available']['string'] = 'Futur Deliveries'
|
||||
res['fields']['qty_available']['string'] = 'Delivered Qty'
|
||||
|
||||
if location_info.usage == 'inventory':
|
||||
res['fields']['virtual_available']['string'] = 'Futur P&L'
|
||||
res['fields']['qty_available']['string'] = 'P&L Qty'
|
||||
|
||||
if location_info.usage == 'procurement':
|
||||
res['fields']['virtual_available']['string'] = 'Futur Qty'
|
||||
res['fields']['qty_available']['string'] = 'Unplanned Qty'
|
||||
|
||||
if location_info.usage == 'production':
|
||||
res['fields']['virtual_available']['string'] = 'Futur Productions'
|
||||
res['fields']['qty_available']['string'] = 'Produced Qty'
|
||||
|
||||
return res
|
||||
|
||||
product_product()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue