[MERGE] lp: 751222

bzr revid: qdp-launchpad@openerp.com-20111229163807-3hh4imvilp8v3y65
This commit is contained in:
Quentin (OpenERP) 2011-12-29 17:38:07 +01:00
commit 3a2c1833c7
3 changed files with 93 additions and 29 deletions

View File

@ -1178,9 +1178,7 @@ class stock_picking(osv.osv):
for pick in self.browse(cr, uid, ids, context=context):
new_picking = None
complete, too_many, too_few = [], [], []
move_product_qty = {}
prodlot_ids = {}
product_avail = {}
move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms = {}, {}, {}, {}, {}
for move in pick.move_lines:
if move.state in ('done', 'cancel'):
continue
@ -1192,9 +1190,11 @@ class stock_picking(osv.osv):
product_currency = partial_data.get('product_currency',False)
prodlot_id = partial_data.get('prodlot_id')
prodlot_ids[move.id] = prodlot_id
if move.product_qty == product_qty:
product_uoms[move.id] = product_uom
partial_qty[move.id] = uom_obj._compute_qty(cr, uid, product_uoms[move.id], product_qty, move.product_uom.id)
if move.product_qty == partial_qty[move.id]:
complete.append(move)
elif move.product_qty > product_qty:
elif move.product_qty > partial_qty[move.id]:
too_few.append(move)
else:
too_many.append(move)
@ -1235,7 +1235,6 @@ class stock_picking(osv.osv):
for move in too_few:
product_qty = move_product_qty[move.id]
if not new_picking:
new_picking = self.copy(cr, uid, pick.id,
{
@ -1251,28 +1250,32 @@ class stock_picking(osv.osv):
'state': 'assigned',
'move_dest_id': False,
'price_unit': move.price_unit,
'product_uom': product_uoms[move.id]
}
prodlot_id = prodlot_ids[move.id]
if prodlot_id:
defaults.update(prodlot_id=prodlot_id)
move_obj.copy(cr, uid, move.id, defaults)
move_obj.write(cr, uid, [move.id],
{
'product_qty' : move.product_qty - product_qty,
'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty
'product_qty' : move.product_qty - partial_qty[move.id],
'product_uos_qty': move.product_qty - partial_qty[move.id], #TODO: put correct uos_qty
})
if new_picking:
move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
for move in complete:
defaults = {'product_uom': product_uoms[move.id], 'product_qty': move_product_qty[move.id]}
if prodlot_ids.get(move.id):
move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]})
defaults.update({'prodlot_id': prodlot_ids[move.id]})
move_obj.write(cr, uid, [move.id], defaults)
for move in too_many:
product_qty = move_product_qty[move.id]
defaults = {
'product_qty' : product_qty,
'product_uos_qty': product_qty, #TODO: put correct uos_qty
'product_uom': product_uoms[move.id]
}
prodlot_id = prodlot_ids.get(move.id)
if prodlot_ids.get(move.id):
@ -1281,7 +1284,6 @@ class stock_picking(osv.osv):
defaults.update(picking_id=new_picking)
move_obj.write(cr, uid, [move.id], defaults)
# At first we confirm the new picking (if necessary)
if new_picking:
wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)

View File

@ -23,8 +23,21 @@ import time
from osv import fields, osv
from tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
import decimal_precision as dp
from tools.translate import _
class stock_partial_picking_line(osv.TransientModel):
def _tracking(self, cursor, user, ids, name, arg, context=None):
res = {}
for tracklot in self.browse(cursor, user, ids, context=context):
tracking = False
if (tracklot.move_id.picking_id.type == 'in' and tracklot.product_id.track_incoming == True) or \
(tracklot.move_id.picking_id.type == 'out' and tracklot.product_id.track_outgoing == True):
tracking = True
res[tracklot.id] = tracking
return res
_name = "stock.partial.picking.line"
_rec_name = 'product_id'
_columns = {
@ -39,15 +52,24 @@ class stock_partial_picking_line(osv.TransientModel):
'update_cost': fields.boolean('Need cost update'),
'cost' : fields.float("Cost", help="Unit Cost for this product line"),
'currency' : fields.many2one('res.currency', string="Currency", help="Currency in which Unit cost is expressed", ondelete='CASCADE'),
'tracking': fields.function(_tracking, string='Tracking', type='boolean'),
}
class stock_partial_picking(osv.osv_memory):
_name = "stock.partial.picking"
_description = "Partial Picking Processing Wizard"
def _hide_tracking(self, cursor, user, ids, name, arg, context=None):
res = {}
for wizard in self.browse(cursor, user, ids, context=context):
res[wizard.id] = any([not(x.tracking) for x in wizard.move_ids])
return res
_columns = {
'date': fields.datetime('Date', required=True),
'move_ids' : fields.one2many('stock.partial.picking.line', 'wizard_id', 'Product Moves'),
'picking_id': fields.many2one('stock.picking', 'Picking', required=True, ondelete='CASCADE'),
'hide_tracking': fields.function(_hide_tracking, string='Tracking', type='boolean', help='This field is for internal purpose. It is used to decide if the column prodlot has to be shown on the move_ids field or not'),
}
def default_get(self, cr, uid, fields, context=None):
@ -72,7 +94,7 @@ class stock_partial_picking(osv.osv_memory):
def _product_cost_for_average_update(self, cr, uid, move):
"""Returns product cost and currency ID for the given move, suited for re-computing
the average product cost.
:return: map of the form::
{'cost': 123.34,
@ -104,34 +126,58 @@ class stock_partial_picking(osv.osv_memory):
assert len(ids) == 1, 'Partial picking processing may only be done one at a time'
stock_picking = self.pool.get('stock.picking')
stock_move = self.pool.get('stock.move')
uom_obj = self.pool.get('product.uom')
partial = self.browse(cr, uid, ids[0], context=context)
partial_data = {
'delivery_date' : partial.date
}
picking_type = partial.picking_id.type
for move in partial.move_ids:
move_id = move.move_id.id
if not move_id:
for wizard_line in partial.move_ids:
line_uom = wizard_line.product_uom
move_id = wizard_line.move_id.id
#Quantiny must be Positive
if wizard_line.quantity < 0:
raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
#Compute the quantity for respective wizard_line in the line uom (this jsut do the rounding if necessary)
qty_in_line_uom = uom_obj._compute_qty(cr, uid, line_uom.id, wizard_line.quantity, line_uom.id)
if line_uom.factor and line_uom.factor <> 0:
if qty_in_line_uom <> wizard_line.quantity:
raise osv.except_osv(_('Warning'), _('The uom rounding does not allow you to ship "%s %s", only roundings of "%s %s" is accepted by the uom.') % (wizard_line.quantity, line_uom.name, line_uom.rounding, line_uom.name))
if move_id:
#Check rounding Quantity.ex.
#picking: 1kg, uom kg rounding = 0.01 (rounding to 10g),
#partial delivery: 253g
#=> result= refused, as the qty left on picking would be 0.747kg and only 0.75 is accepted by the uom.
initial_uom = wizard_line.move_id.product_uom
#Compute the quantity for respective wizard_line in the initial uom
qty_in_initial_uom = uom_obj._compute_qty(cr, uid, line_uom.id, wizard_line.quantity, initial_uom.id)
without_rounding_qty = (wizard_line.quantity / line_uom.factor) * initial_uom.factor
if qty_in_initial_uom <> without_rounding_qty:
raise osv.except_osv(_('Warning'), _('The rounding of the initial uom does not allow you to ship "%s %s", as it would let a quantity of "%s %s" to ship and only roundings of "%s %s" is accepted by the uom.') % (wizard_line.quantity, line_uom.name, wizard_line.move_id.product_qty - without_rounding_qty, initial_uom.name, initial_uom.rounding, initial_uom.name))
else:
seq_obj_name = 'stock.picking.' + picking_type
move_id = stock_move.create(cr,uid,{'name' : self.pool.get('ir.sequence').get(cr, uid, seq_obj_name),
'product_id': move.product_id.id,
'product_qty': move.quantity,
'product_uom': move.product_uom.id,
'prodlot_id': move.prodlot_id.id,
'location_id' : move.location_id.id,
'location_dest_id' : move.location_dest_id.id,
'product_id': wizard_line.product_id.id,
'product_qty': wizard_line.quantity,
'product_uom': wizard_line.product_uom.id,
'prodlot_id': wizard_line.prodlot_id.id,
'location_id' : wizard_line.location_id.id,
'location_dest_id' : wizard_line.location_dest_id.id,
'picking_id': partial.picking_id.id
},context=context)
stock_move.action_confirm(cr, uid, [move_id], context)
partial_data['move%s' % (move_id)] = {
'product_id': move.product_id.id,
'product_qty': move.quantity,
'product_uom': move.product_uom.id,
'prodlot_id': move.prodlot_id.id,
'product_id': wizard_line.product_id.id,
'product_qty': wizard_line.quantity,
'product_uom': wizard_line.product_uom.id,
'prodlot_id': wizard_line.prodlot_id.id,
}
if (picking_type == 'in') and (move.product_id.cost_method == 'average'):
partial_data['move%s' % (move.move_id.id)].update(product_price=move.cost,
product_currency=move.currency.id)
if (picking_type == 'in') and (wizard_line.product_id.cost_method == 'average'):
partial_data['move%s' % (wizard_line.move_id.id)].update(product_price=wizard_line.cost,
product_currency=wizard_line.currency.id)
stock_picking.do_partial(cr, uid, [partial.picking_id.id], partial_data, context=context)
return {'type': 'ir.actions.act_window_close'}

View File

@ -15,8 +15,20 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<field name="hide_tracking" invisible="1"/>
<separator colspan="4" string="Products"/>
<field name="move_ids" colspan="4" nolabel="1" mode="tree,form" width="550" height="200"/>
<field name="move_ids" colspan="4" nolabel="1" mode="tree,form" width="550" height="200" context="{'hide_tracking': hide_tracking}">
<tree editable="bottom" string="Product Moves">
<field name="product_id" />
<field name="quantity" />
<field name="product_uom" />
<field name="tracking" invisible="1"/>
<field name="prodlot_id" domain="[('product_id', '=', product_id)]" invisible="context.get('hide_tracking',False)" attrs="{'required':[('tracking','=',True)]}"/>
<field name="update_cost" invisible="1"/>
<field name="cost" attrs="{'invisible': [('update_cost','=', False)]}"/>
<field name="currency" attrs="{'invisible': [('update_cost','=', False)]}"/>
</tree>
</field>
<separator string="" colspan="4" />
<label string="" colspan="2"/>
<group col="2" colspan="2">
@ -36,6 +48,8 @@
<field name="product_id" />
<field name="quantity" />
<field name="product_uom" />
<field name="tracking" invisible="1"/>
<field name="prodlot_id" domain="[('product_id', '=', product_id)]" attrs="{'required':[('tracking','=',True)]}" groups="base.group_extended" />
<field name="update_cost" invisible="1"/>
<field name="cost" attrs="{'invisible': [('update_cost','=', False)]}"/>
<field name="currency" attrs="{'invisible': [('update_cost','=', False)]}"/>
@ -53,6 +67,8 @@
<field name="product_uom" />
<field name="location_id" />
<field name="location_dest_id" />
<field name="tracking" invisible="1"/>
<field name="prodlot_id" domain="[('product_id', '=', product_id)]" attrs="{'required':[('tracking','=',True)]}" groups="base.group_extended" />
<field name="update_cost" invisible="1"/>
<field name="cost" attrs="{'invisible': [('update_cost','=', False)]}"/>
<field name="currency" attrs="{'invisible': [('update_cost','=', False)]}"/>