[IMP] improving stock operations

bzr revid: fp@tinyerp.com-20100408231041-9r7eg9k48reka8zx
This commit is contained in:
Fabien Pinckaers 2010-04-09 01:10:41 +02:00
parent f4cdf72ea3
commit 7b8ec4c46d
5 changed files with 55 additions and 165 deletions

View File

@ -808,7 +808,7 @@
<page string="Procurement Details">
<separator colspan="4" string="Product &amp; Location"/>
<field name="product_id" select="1" on_change="onchange_product_id(product_id)"/>
<field name="location_id" select="2"/>
<field name="location_id" select="2" domain="[('usage','=','internal')]"/>
<field name="product_qty"/>
<field name="product_uom"/>
@ -896,7 +896,7 @@
</record>
<menuitem action="mrp_procurement_action3" id="menu_procurement_requisitions" parent="purchase.menu_procurement_management"
name="Requisitions" sequence="5" />
sequence="5" />
<record id="mrp_procurement_action5" model="ir.actions.act_window">
<field name="name">Procurement Exceptions</field>

View File

@ -36,8 +36,6 @@
"access_stock_invoice_onshipping","stock.invoice.onshipping","model_stock_invoice_onshipping","stock.group_stock_user",1,0,0,0
"access_stock_location_product","stock.location.product","model_stock_location_product","stock.group_stock_user",1,0,0,0
"access_report_stock_picking","report.stock.picking","model_report_stock_picking","stock.group_stock_user",1,0,0,0
"access_stock_delivery","stock.delivery","model_stock_delivery","stock.group_stock_user",1,0,0,0
"access_stock_traceability_upstream","stock.traceability.upstream","model_stock_traceability_upstream","stock.group_stock_user",1,0,0,0
"access_stock_traceability_downstream","stock.traceability.downstream","model_stock_traceability_downstream","stock.group_stock_user",1,0,0,0
"access_stock_traceability_lot_upstream","stock.traceability.lot.upstream","model_stock_traceability_lot_upstream","stock.group_stock_user",1,0,0,0
@ -46,4 +44,4 @@
"access_stock_partial_move","stock.partial.move","model_stock_partial_move","stock.group_stock_user",1,0,0,0
"access_stock_picking_make","stock.picking.make","model_stock_picking_make","stock.group_stock_user",1,0,0,0
"access_stock_inventory_merge","stock.inventory.merge","model_stock_inventory_merge","stock.group_stock_user",1,0,0,0
"access_stock_change_standard_price","stock.change.standard.price","model_stock_change_standard_price","stock.group_stock_user",1,0,0,0
"access_stock_change_standard_price","stock.change.standard.price","model_stock_change_standard_price","stock.group_stock_user",1,0,0,0

Can't render this file because it contains an unexpected character in line 43 and column 53.

View File

@ -492,7 +492,6 @@ class stock_picking(osv.osv):
'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. Expected Date', select=2),
'move_lines': fields.one2many('stock.move', 'picking_id', 'Entry lines', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),
'delivery_line':fields.one2many('stock.delivery', 'picking_id', 'Delivery lines', readonly=True),
'auto_picking': fields.boolean('Auto-Picking'),
'address_id': fields.many2one('res.partner.address', 'Partner', help="Address of partner"),
'invoice_state': fields.selection([
@ -877,7 +876,6 @@ class stock_picking(osv.osv):
"""
res = {}
move_obj = self.pool.get('stock.move')
delivery_obj = self.pool.get('stock.delivery')
product_obj = self.pool.get('product.product')
currency_obj = self.pool.get('res.currency')
users_obj = self.pool.get('res.users')
@ -1003,14 +1001,6 @@ class stock_picking(osv.osv):
delivered_pack_id = pick.id
delivered_pack = self.browse(cr, uid, delivered_pack_id, context=context)
delivery_id = delivery_obj.create(cr, uid, {
'name': delivered_pack.name,
'partner_id': partner_id,
'address_id': address_id,
'date': delivery_date,
'picking_id' : pick.id,
'move_delivered' : [(6,0, map(lambda x:x.id, delivered_pack.move_lines))]
}, context=context)
res[pick.id] = {'delivered_picking': delivered_pack.id or False}
return res
@ -1112,26 +1102,6 @@ class stock_production_lot_revision(osv.osv):
stock_production_lot_revision()
class stock_delivery(osv.osv):
""" Tracability of partialdeliveries """
_name = "stock.delivery"
_description = "Delivery"
_columns = {
'name': fields.char('Name', size=60, required=True),
'date': fields.datetime('Date', required=True),
'partner_id': fields.many2one('res.partner', 'Partner', required=True),
'address_id': fields.many2one('res.partner.address', 'Address', required=True),
'move_delivered':fields.one2many('stock.move', 'delivered_id', 'Move Delivered'),
'picking_id': fields.many2one('stock.picking', 'Picking list'),
}
stock_delivery()
# ----------------------------------------------------
# Move
# ----------------------------------------------------
#
# Fields:
# location_dest_id is only used for predicting futur stocks
@ -1211,7 +1181,6 @@ class stock_move(osv.osv):
'backorder_id': fields.related('picking_id','backorder_id',type='many2one', relation="stock.picking", string="Back Orders"),
'origin': fields.related('picking_id','origin',type='char', size=64, relation="stock.picking", string="Origin"),
'move_stock_return_history': fields.many2many('stock.move', 'stock_move_return_history', 'move_id', 'return_move_id', 'Move Return History',readonly=True),
'delivered_id': fields.many2one('stock.delivery', 'Product delivered'),
'scraped': fields.boolean('Scraped'),
}
_constraints = [
@ -1803,7 +1772,6 @@ class stock_move(osv.osv):
"""
res = {}
picking_obj = self.pool.get('stock.picking')
delivery_obj = self.pool.get('stock.delivery')
product_obj = self.pool.get('product.product')
currency_obj = self.pool.get('res.currency')
users_obj = self.pool.get('res.users')
@ -1909,18 +1877,6 @@ class stock_move(osv.osv):
done_move_ids = []
for move in complete:
done_move_ids.append(move.id)
if move.picking_id.id not in ref:
delivery_id = delivery_obj.create(cr, uid, {
'partner_id': partner_id,
'address_id': address_id,
'date': delivery_date,
'name' : move.picking_id.name,
'picking_id': move.picking_id.id
}, context=context)
ref[move.picking_id.id] = delivery_id
delivery_obj.write(cr, uid, ref[move.picking_id.id], {
'move_delivered' : [(4,move.id)]
})
return done_move_ids
stock_move()

View File

@ -1034,9 +1034,6 @@
<button name="button_cancel" states="assigned,confirmed,draft" string="Cancel" icon="gtk-cancel"/>
</group>
</page>
<page string="Delivery Info">
<field colspan="4" name="delivery_line" nolabel="1"/>
</page>
<page string="Notes">
<field colspan="4" name="note" nolabel="1"/>
</page>
@ -1227,9 +1224,6 @@
<button name="button_cancel" states="assigned,confirmed,draft" string="Cancel" icon="gtk-cancel"/>
</group>
</page>
<page string="Delivery Info">
<field colspan="4" name="delivery_line" nolabel="1"/>
</page>
<page string="Notes">
<field colspan="4" name="note" nolabel="1"/>
</page>
@ -1265,7 +1259,7 @@
<record id="action_picking_tree4" model="ir.actions.act_window">
<field name="name">Incoming shipments</field>
<field name="name">Incoming Shipments</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
@ -1754,56 +1748,6 @@
<field name="view_mode">graph,tree</field>
<field name="view_id" ref="view_move_delivery_products_planned_graph"/>
</record>
<!-- Product Delivered -->
<record id="view_stock_delivery_form" model="ir.ui.view">
<field name="name">stock.delivery.from</field>
<field name="model">stock.delivery</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Product">
<field name="name"/>
<field name="date"/>
<field name="partner_id"/>
<field name="address_id"/>
<field name="picking_id"/>
<separator string="Product Delivered Information" colspan="4" />
<field name="move_delivered" colspan="4" nolabel="1" widget="one2many" mode="tree,form">
<tree string="Stock Moves" editable="top">
<field name="picking_id" string="Reference"/>
<field name="origin" string="Latest Requisition"/>
<field name="partner_id" string="Supplier"/>
<field name="product_id"/>
<field name="product_qty" />
<field name="product_uom" string="UOM"/>
<field name="prodlot_id" string="Lot"/>
</tree>
</field>
</form>
</field>
</record>
<record id="view_stock_delivery_tree" model="ir.ui.view">
<field name="name">stock.delivery.tree</field>
<field name="model">stock.delivery</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Delivered Product">
<field name="name"/>
<field name="date"/>
<field name="partner_id"/>
<field name="address_id"/>
</tree>
</field>
</record>
<record id="action_stock_delivery" model="ir.actions.act_window">
<field name="name">Delivered Products</field>
<field name="res_model">stock.delivery</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="view_stock_delivery_tree"/>
</record>
<menuitem action="action_stock_delivery" id="menu_action_picking_all" parent="menu_traceability" sequence="4"/>
</data>
</openerp>

View File

@ -27,22 +27,19 @@ import pooler
import time
class stock_partial_move(osv.osv_memory):
_name = "stock.partial.move"
_description = "Partial Move"
_name = "stock.partial.move"
_description = "Partial Move"
_columns = {
'date': fields.datetime('Date', required=True),
'partner_id': fields.many2one('res.partner',string="Partner", required=True),
'address_id': fields.many2one('res.partner.address', 'Delivery Address', help="Address where goods are to be delivered", required=True),
}
'date': fields.datetime('Date', required=True),
}
def view_init(self, cr, uid, fields_list, context=None):
res = super(stock_partial_move, self).view_init(cr, uid, fields_list, context=context)
move_obj = self.pool.get('stock.move')
move_obj = self.pool.get('stock.move')
if not context:
context={}
moveids = []
for m in move_obj.browse(cr, uid, context.get('active_ids', [])):
for m in move_obj.browse(cr, uid, context.get('active_ids', [])):
if m.state in ('done', 'cancel'):
continue
if 'move%s_product_id'%(m.id) not in self._columns:
@ -57,55 +54,53 @@ class stock_partial_move(osv.osv_memory):
self._columns['move%s_product_price'%(m.id)] = fields.float("Price")
if 'move%s_product_currency'%(m.id) not in self._columns:
self._columns['move%s_product_currency'%(m.id)] = fields.many2one('res.currency',string="Currency")
return res
return res
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False,submenu=False):
result = super(stock_partial_move, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
result = super(stock_partial_move, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
move_obj = self.pool.get('stock.move')
move_ids = context.get('active_ids', False)
move_ids = context.get('active_ids', False)
move_ids = move_obj.search(cr, uid, [('id','in',move_ids)])
_moves_arch_lst = """<form string="Deliver Products">
<separator colspan="4" string="Delivery Information"/>
<separator colspan="4" string="Information"/>
<field name="date" colspan="4" />
<field name="partner_id"/>
<field name="address_id"/>
<newline/>
<separator colspan="4" string="Move Detail"/>
"""
_moves_fields = result['fields']
if move_ids and view_type in ['form']:
for m in move_obj.browse(cr, uid, move_ids, context):
if move_ids and view_type in ['form']:
for m in move_obj.browse(cr, uid, move_ids, context):
if m.state in ('done', 'cancel'):
continue
_moves_fields.update({
'move%s_product_id'%(m.id) : {
'string': _('Product'),
'type' : 'many2one',
'relation': 'product.product',
'required' : True,
'readonly' : True,
'type' : 'many2one',
'relation': 'product.product',
'required' : True,
'readonly' : True,
},
'move%s_product_qty'%(m.id) : {
'string': _('Quantity'),
'type' : 'float',
'required': True,
'required': True,
},
'move%s_product_uom'%(m.id) : {
'string': _('Product UOM'),
'type' : 'many2one',
'relation': 'product.uom',
'required' : True,
'readonly' : True,
'type' : 'many2one',
'relation': 'product.uom',
'required' : True,
'readonly' : True,
}
})
})
_moves_arch_lst += """
<group colspan="4" col="10">
<field name="move%s_product_id" nolabel="1"/>
<field name="move%s_product_qty" string="Qty" />
<field name="move%s_product_uom" nolabel="1" />
"""%(m.id, m.id, m.id)
if (m.picking_id.type == 'in') and (m.product_id.cost_method == 'average'):
if (m.picking_id.type == 'in') and (m.product_id.cost_method == 'average'):
_moves_fields.update({
'move%s_product_price'%(m.id) : {
'string': _('Price'),
@ -113,9 +108,9 @@ class stock_partial_move(osv.osv_memory):
},
'move%s_product_currency'%(m.id): {
'string': _('Currency'),
'type' : 'float',
'type' : 'many2one',
'relation': 'res.currency',
'type' : 'float',
'type' : 'many2one',
'relation': 'res.currency',
}
})
_moves_arch_lst += """
@ -136,31 +131,31 @@ class stock_partial_move(osv.osv_memory):
</group>
</form>"""
result['arch'] = _moves_arch_lst
result['fields'] = _moves_fields
result['fields'] = _moves_fields
return result
def default_get(self, cr, uid, fields, context=None):
"""
"""
To get default values for the object.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
@param fields: List of fields for which we want default values
@param context: A standard dictionary
@return: A dictionary which of fields with values.
"""
res = super(stock_partial_move, self).default_get(cr, uid, fields, context=context)
move_obj = self.pool.get('stock.move')
move_obj = self.pool.get('stock.move')
if not context:
context={}
moveids = []
if 'date' in fields:
res.update({'date': time.strftime('%Y-%m-%d %H:%M:%S')})
for m in move_obj.browse(cr, uid, context.get('active_ids', [])):
for m in move_obj.browse(cr, uid, context.get('active_ids', [])):
if m.state in ('done', 'cancel'):
continue
if 'move%s_product_id'%(m.id) in fields:
@ -178,23 +173,21 @@ class stock_partial_move(osv.osv_memory):
currency = False
if hasattr(m.picking_id, 'purchase_id') and m.picking_id.purchase_id:
currency = m.picking_id.purchase_id.pricelist_id.currency_id.id
if 'move%s_product_price'%(m.id) in fields:
res['move%s_product_price'%(m.id)] = price
if 'move%s_product_currency'%(m.id) in fields:
res['move%s_product_currency'%(m.id)] = currency
return res
return res
def do_partial(self, cr, uid, ids, context):
move_obj = self.pool.get('stock.move')
def do_partial(self, cr, uid, ids, context):
move_obj = self.pool.get('stock.move')
move_ids = context.get('active_ids', False)
partial = self.browse(cr, uid, ids[0], context)
partial_datas = {
'partner_id' : partial.partner_id and partial.partner_id.id or False,
'address_id' : partial.address_id and partial.address_id.id or False,
'delivery_date' : partial.date
'delivery_date' : partial.date
}
for m in move_obj.browse(cr, uid, move_ids):
for m in move_obj.browse(cr, uid, move_ids):
if m.state in ('done', 'cancel'):
continue
partial_datas['move%s'%(m.id)] = {
@ -203,15 +196,14 @@ class stock_partial_move(osv.osv_memory):
'product_uom' : getattr(partial, 'move%s_product_uom'%(m.id)).id
}
if (m.picking_id.type == 'in') and (m.product_id.cost_method == 'average'):
partial_datas['move%s'%(m.id)].update({
if (m.picking_id.type == 'in') and (m.product_id.cost_method == 'average'):
partial_datas['move%s'%(m.id)].update({
'product_price' : getattr(partial, 'move%s_product_price'%(m.id)),
'product_currency': getattr(partial, 'move%s_product_currency'%(m.id)).id
})
})
res = move_obj.do_partial(cr, uid, move_ids, partial_datas, context=context)
return {}
stock_partial_move()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
stock_partial_move()