[FIX] stock: if scrapping from a done stock move, use the destination location as the source for the scrapping move + [FIX] stock, mrp: restrict scrapping from virtual locations

bzr revid: qdp-launchpad@openerp.com-20130319125216-pdfo2i9jx5mcea2l
This commit is contained in:
Quentin (OpenERP) 2013-03-19 13:52:16 +01:00
parent 748ebf0ab0
commit 31d83649d2
2 changed files with 8 additions and 10 deletions

View File

@ -701,11 +701,6 @@
<field name="prodlot_id" context="{'product_id': product_id}" groups="stock.group_production_lot"/>
<field name="state" invisible="1"/>
<field name="scrapped" invisible="1"/>
<button
name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="terp-gtk-jump-to-ltr"
states="done,cancel"/>
</tree>
</field>
</group>
@ -724,10 +719,6 @@
string="Partial"
type="action" states="confirmed,assigned"
icon="gtk-justify-fill"/>
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="terp-gtk-jump-to-ltr" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"/>
</tree>
</field>
</group>

View File

@ -2475,13 +2475,20 @@ class stock_move(osv.osv):
raise osv.except_osv(_('Warning!'), _('Please provide a positive quantity to scrap.'))
res = []
for move in self.browse(cr, uid, ids, context=context):
source_location = move.location_id
if move.state == 'done':
source_location = move.location_dest_id
if source_location.usage != 'internal':
#restrict to scrap from a virtual location because it's meaningless and it may introduce errors in stock ('creating' new products from nowhere)
raise osv.except_osv(_('Error!'), _('Forbidden operation: it is not allowed to scrap products from a virtual location.'))
move_qty = move.product_qty
uos_qty = quantity / move_qty * move.product_uos_qty
default_val = {
'location_id': source_location.id,
'product_qty': quantity,
'product_uos_qty': uos_qty,
'state': move.state,
'scrapped' : True,
'scrapped': True,
'location_dest_id': location_id,
'tracking_id': move.tracking_id.id,
'prodlot_id': move.prodlot_id.id,