openerp-wms-expert team mailing list archive
-
openerp-wms-expert team
-
Mailing list archive
-
Message #00158
lp:~numerigraphe/openobject-addons/trunk-stock-split-move-refactoring into lp:openobject-addons
You have been requested to review the proposed merge of lp:~numerigraphe/openobject-addons/trunk-stock-split-move-refactoring into lp:openobject-addons.
For more details, see:
https://code.launchpad.net/~numerigraphe/openobject-addons/trunk-stock-split-move-refactoring/+merge/105239
This proposal is a first step towards implementation of https://blueprints.launchpad.net/openobject-addons/+spec/new-partial-picking-wizard.
There are currently too many ways to split Stock Moves: scrap, split in prodlots, split in tracking lots, partial delivery. Each has its wizard and it's own API.
This branch adds a generic API and wizard to split Moves.
The API consists of the method stock.move.split(cr, uid, ids, split_qty, split_uos_qty, default).
In essence it copies the stock move and spreads the quantity.
The wizard is accessible from all Picking and Move views. It lets users enter both quantities, and decide what they want OpenERP to do with the quantity split from a list of actions.
Great care was taken to not let users enter inconsistent data. Units of measures and units of sale are supported, and an extended view is provided.
This proposal leaves the existing wizards untouched, so the list of actions is restricted to a dummy "no action".
Additional actions are supposed to be added when other wizards/APIs are refactored into this one.
I propose to bump the stock module's version to reflect the change in the API, as I expect several methods to be deprecated/removed when the refactoring is complete.
Lionel Sausin.
--
https://code.launchpad.net/~numerigraphe/openobject-addons/trunk-stock-split-move-refactoring/+merge/105239
Your team OpenERP WMS Expert is requested to review the proposed merge of lp:~numerigraphe/openobject-addons/trunk-stock-split-move-refactoring into lp:openobject-addons.
=== modified file 'stock/__openerp__.py'
--- stock/__openerp__.py 2012-05-03 10:29:10 +0000
+++ stock/__openerp__.py 2012-05-09 17:22:29 +0000
@@ -21,7 +21,7 @@
{
"name" : "Warehouse Management",
- "version" : "1.1",
+ "version" : "1.2",
"author" : "OpenERP SA",
'complexity': "easy",
"description" : """
=== modified file 'stock/stock.py'
--- stock/stock.py 2012-05-03 10:29:10 +0000
+++ stock/stock.py 2012-05-09 17:22:29 +0000
@@ -2529,6 +2529,48 @@
self.action_done(cr, uid, res, context=context)
return res
+
+ def split(self, cr, uid, ids, split_qty, split_uos_qty, default=None,
+ context=None):
+ """Split Moves in two and return the new Stock Move ids.
+
+ @param ids: List of ID of the original Stock Moves
+ @param split_qty: Quantity to dispatch to new Stock Moves
+ @param split_uos_qty: Quantity in UoS to dispatch to new Stock Moves
+ @param default: Map of default values for the new Stock Moves
+ @return: List of IDs of the new lines created
+
+ Splitting consists of making a new copy of the initial move and
+ adjusting the quantities.
+ The original move gets qty = initial qty - split_qty.
+ The copy gets qty = split_qty.
+ """
+ if default is None:
+ default = {}
+ if split_qty<=0 or split_uos_qty<=0:
+ return []
+ split_ids = []
+ original_moves = self.read(cr,uid, ids,
+ ['product_qty', 'product_uos_qty', 'state'])
+ for move in original_moves:
+ initial_qty = move['product_qty']
+ initial_uos_qty = move['product_uos_qty']
+ if initial_qty<=split_qty or initial_uos_qty<=split_uos_qty:
+ continue
+ # Adjust the quantity on the original move
+ self.write(cr, uid, ids,
+ {
+ 'product_qty' : initial_qty - split_qty,
+ 'product_uos_qty': initial_uos_qty - split_uos_qty,
+ })
+ # Prepare the default values for the new Moves
+ default.update({'product_qty' : split_qty,
+ 'product_uos_qty': split_uos_qty,
+ 'state': move['state']})
+ # XXX: copy() breaks traceability: is that OK?
+ split_ids.append(self.copy(cr, uid, move['id'], default,
+ context=context))
+ return split_ids
# FIXME: needs refactoring, this code is partially duplicated in stock_picking.do_partial()!
def do_partial(self, cr, uid, ids, partial_datas, context=None):
=== modified file 'stock/stock_view.xml'
--- stock/stock_view.xml 2012-05-03 10:29:10 +0000
+++ stock/stock_view.xml 2012-05-09 17:22:29 +0000
@@ -154,6 +154,7 @@
context="{'inventory_id':parent.id}"
groups="stock.group_production_lot"/>
<field groups="stock.group_tracking_lot" name="tracking_id"/>
+ <!-- FIXME refactor with new "split line" button -->
<button name="%(split_into)d" string="Put in a new pack" type="action"
groups="stock.group_tracking_lot"
icon="terp-stock_effects-object-colorize"
@@ -714,12 +715,17 @@
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="UoM" groups="product.group_uom"/>
<field name="product_uos" groups="product.group_uos"/>
+ <button name="%(split_move)d"
+ string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="gtk-convert" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"/>
<field name="scrapped" invisible="1"/>
<field name="prodlot_id" groups="stock.group_production_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button
name="%(stock.track_line)d"
string="Split in production lots"
@@ -732,6 +738,7 @@
icon="terp-stock_effects-object-colorize"
groups="stock.group_tracking_lot"
states="draft,assigned,confirmed"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="Put in a new pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -745,7 +752,11 @@
<separator colspan="4" string="Move Information"/>
<field name="name" invisible="1" colspan="4"/>
<field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, parent.partner_id)" colspan="4"/>
- <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)" colspan="3"/>
+ <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
+ <button name="%(split_move)d" string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap" type="action"
icon="gtk-convert" context="{'scrap': True}"
@@ -772,6 +783,7 @@
<group colspan="2" col="4" groups="stock.group_tracking_lot">
<separator string="Traceability" colspan="4" groups="stock.group_tracking_lot"/>
<field name="tracking_id" groups="stock.group_tracking_lot" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="New pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -780,6 +792,7 @@
context="{'location_id':location_id, 'product_id':product_id}"
domain="[('product_id','=?',product_id)]"
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id, product_uom)" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d"
groups="stock.group_tracking_lot"
states="draft,waiting,confirmed,assigned"
@@ -904,17 +917,24 @@
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="UoM" groups="product.group_uom"/>
<field name="product_uos" groups="product.group_uos"/>
+ <button name="%(split_move)d"
+ string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="gtk-convert" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned" />
<field name="scrapped" invisible="1"/>
<field name="prodlot_id" groups="stock.group_production_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d" string="Split in production lots" type="action"
icon="terp-stock_effects-object-colorize" attrs="{'invisible': [('prodlot_id','<>',False)]}"
states="draft,assigned,confirmed"
groups="stock.group_production_lot"/>
<field name="tracking_id" groups="stock.group_tracking_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="setlast_tracking" string="Put in current pack" type="object"
attrs="{'invisible': [('tracking_id','<>',False)]}"
groups="stock.group_tracking_lot"
@@ -924,6 +944,7 @@
icon="terp-stock_effects-object-colorize"
groups="product.group_stock_packaging"
states="draft,assigned,confirmed"/>
+ <!-- TODO: refactor with new "split line" button -->
<field name="location_id"/>
<field name="date"/>
<field name="state"/>
@@ -934,7 +955,11 @@
<separator colspan="4" string="Move Information"/>
<field name="name" invisible="1" colspan="4" />
<field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, parent.partner_id)" colspan="4" />
- <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)" colspan="3" />
+ <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
+ <button name="%(split_move)d" string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap" type="action"
icon="gtk-convert" context="{'scrap': True}"
@@ -961,6 +986,7 @@
<group colspan="2" col="4">
<separator string="Traceability" colspan="4" groups="stock.group_tracking_lot"/>
<field name="tracking_id" groups="stock.group_tracking_lot" colspan="3" />
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="New pack" type="action"
groups="stock.group_tracking_lot"
icon="terp-stock_effects-object-colorize"
@@ -969,6 +995,7 @@
context="{'location_id':location_id, 'product_id':product_id}"
domain="[('product_id','=?',product_id)]"
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id, product_uom)" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d"
groups="stock.group_tracking_lot"
states="draft,waiting,confirmed,assigned"
@@ -1122,12 +1149,18 @@
<field name="product_id" />
<field name="product_qty" />
<field name="product_uom" string="UoM" groups="product.group_uom"/>
+ <button name="%(split_move)d"
+ string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="gtk-convert" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"/>
<field name="scrapped" invisible="1"/>
<field name="prodlot_id" groups="stock.group_production_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button
name="%(stock.track_line)d"
string="Split in production lots"
@@ -1139,6 +1172,7 @@
groups="stock.group_tracking_lot"
icon="terp-stock_effects-object-colorize" attrs="{'invisible': [('tracking_id','<>',False)]}"
states="draft,assigned,confirmed"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="Put in a new pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1151,7 +1185,11 @@
<separator colspan="4" string="Move Information"/>
<field name="name" invisible="1" colspan="4"/>
<field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, parent.partner_id)" colspan="4"/>
- <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)" colspan="3"/>
+ <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
+ <button name="%(split_move)d" string="Split this line" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap" type="action"
icon="gtk-convert" context="{'scrap': True}"
@@ -1178,6 +1216,7 @@
<group colspan="2" col="4">
<separator string="Traceability" colspan="4" groups="stock.group_tracking_lot"/>
<field name="tracking_id" groups="stock.group_tracking_lot" colspan="3" />
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="New pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1186,6 +1225,7 @@
context="{'location_id':location_id, 'product_id':product_id}"
domain="[('product_id','=?',product_id)]"
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id, product_uom)" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d"
groups="stock.group_tracking_lot"
states="draft,waiting,confirmed,assigned"
@@ -1364,12 +1404,18 @@
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="UoM" groups="product.group_uom"/>
<field name="product_uos" groups="product.group_uos"/>
+ <button name="%(split_move)d"
+ string="Split this Move" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="gtk-convert" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"
/>
<field name="prodlot_id" groups="stock.group_production_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d" string="Split in production lots" type="action"
icon="terp-stock_effects-object-colorize" attrs="{'invisible': [('prodlot_id','<>',False)]}"
states="draft,waiting,confirmed,assigned,done"
@@ -1379,6 +1425,7 @@
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize" attrs="{'invisible': [('tracking_id','<>',False)]}"
states="draft,assigned,confirmed,done"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="Put in a new pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1406,6 +1453,10 @@
<field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, False)"/>
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="Unit Of Measure" groups="product.group_uom"/>
+ <button name="%(split_move)d" string="Split this Move" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap" type="action"
icon="gtk-convert" context="{'scrap': True}"
@@ -1439,6 +1490,7 @@
<group colspan="2" col="4">
<separator string="Traceability" colspan="4"/>
<field name="tracking_id" colspan="3" groups="stock.group_tracking_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="New pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1447,6 +1499,7 @@
context="{'location_id':location_id, 'product_id':product_id}"
domain="[('product_id','=?',product_id)]"
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id, product_uom)" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d"
groups="stock.group_tracking_lot"
states="draft,waiting,confirmed,assigned"
@@ -1536,11 +1589,17 @@
<field name="product_id"/>
<field name="product_qty" />
<field name="product_uom" string="UoM" groups="product.group_uom"/>
+ <button name="%(split_move)d"
+ string="Split this Move" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap Products" type="action"
icon="gtk-convert" context="{'scrap': True}"
states="draft,waiting,confirmed,assigned"/>
<field name="prodlot_id" groups="stock.group_production_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d" string="Split in production lots" type="action"
icon="terp-stock_effects-object-colorize" attrs="{'invisible': [('prodlot_id','<>',False)]}"
states="draft,waiting,confirmed,assigned,done"
@@ -1551,6 +1610,7 @@
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
states="draft,assigned,confirmed,done"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="Put in a new pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1592,6 +1652,11 @@
<field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, False)"/>
<field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
<field name="product_uom" string="Unit Of Measure" groups="product.group_uom"/>
+ <button name="%(split_move)d"
+ string="Split this Move" type="action"
+ icon="terp-stock_effects-object-colorize"
+ states="draft,waiting,confirmed,assigned"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(stock.move_scrap)d"
string="Scrap" type="action"
icon="gtk-convert" context="{'scrap': True}"
@@ -1625,6 +1690,7 @@
<group colspan="2" col="4">
<separator string="Traceability" colspan="4" groups="stock.group_tracking_lot"/>
<field name="tracking_id" colspan="3" groups="stock.group_tracking_lot"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(split_into)d" string="New pack" type="action"
groups="product.group_stock_packaging"
icon="terp-stock_effects-object-colorize"
@@ -1633,6 +1699,7 @@
context="{'location_id':location_id, 'product_id':product_id}"
domain="[('product_id','=?',product_id)]"
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id, product_uom)" colspan="3"/>
+ <!-- TODO: refactor with new "split line" button -->
<button name="%(track_line)d"
groups="stock.group_tracking_lot"
states="draft,waiting,confirmed,assigned,done"
=== modified file 'stock/wizard/stock_move.py'
--- stock/wizard/stock_move.py 2012-02-13 15:27:55 +0000
+++ stock/wizard/stock_move.py 2012-05-09 17:22:29 +0000
@@ -23,6 +23,139 @@
from tools.translate import _
import decimal_precision as dp
+
+class StockMoveSplitSimple(osv.osv_memory):
+ """This object lets users enter details to split a move line in two."""
+ _name = "stock.move.split.simple"
+ _description = "Stock move splitting details"
+
+ _columns = {
+ # Same names as in Stock Move object so we can use it's onchange...()
+ 'product_id': fields.many2one('product.product', 'Product',
+ required=True, readonly=True),
+ 'initial_qty': fields.float('Initial quantity', readonly=True,
+ digits_compute=dp.get_precision('Product UoM')),
+ 'product_qty': fields.float('Quantity', required=True,
+ digits_compute=dp.get_precision('Product UoM'),
+ help="The quantity the should be moved to another line, expressed "
+ "in the Unit of Measure of the original Stock Move."),
+ 'rest_qty': fields.float('Quantity', readonly=True,
+ digits_compute=dp.get_precision('Product UoM')),
+ 'product_uom': fields.many2one('product.uom', 'Unit of Measure',
+ readonly=True),
+ 'initial_uos_qty': fields.float('Initial quantity in UoS',
+ readonly=True, digits_compute=dp.get_precision('Product UoM')),
+ 'product_uos_qty': fields.float('Quantity in UoS', required=True,
+ digits_compute=dp.get_precision('Product UoM'),
+ help="The quantity that should be moved to another line, expressed "
+ "in the Unit of Sale of the original Stock Move."),
+ 'rest_uos_qty': fields.float('Quantity in UoS', readonly=True,
+ digits_compute=dp.get_precision('Product UoM')),
+ 'product_uos': fields.many2one('product.uom', 'Unit of Sale',
+ readonly=True),
+ 'action': fields.selection( [
+ ('none', 'No action'),
+ ],
+ "Action", required=True,
+ help="The action that must be taken for the remaining quantity "
+ "after the Move is split.\n"
+ "- 'No action': no additional action will be taken.")
+ }
+
+ def onchange_quantity(self, cr, uid, ids, product_id, product_qty,
+ product_uom, product_uos, initial_qty, initial_uos_qty):
+ """Call stock.move.onchange_quantity() and update remaining qty"""
+ # Cap the split qty to the initial qty
+ product_qty = max(min(product_qty, initial_qty), 0.0)
+ changes = self.pool.get('stock.move').onchange_quantity(cr, uid, ids,
+ product_id, product_qty, product_uom, product_uos)
+ # Update the remaining qty
+ vals = changes['value']
+ vals.update({
+ 'product_qty': product_qty,
+ 'rest_qty': max(initial_qty - product_qty, 0.0),
+ 'rest_uos_qty': max(initial_uos_qty
+ - vals.get('product_uos_qty', 0.0), 0.0) })
+ return changes
+
+ def onchange_uos_quantity(self, cr, uid, ids, product_id, product_uos_qty,
+ product_uos, product_uom, initial_qty, initial_uos_qty):
+ """Call stock.move.onchange_uos_quantity() and update remaining qty"""
+ # Cap the split qty to the initial qty
+ product_uos_qty = max(min(product_uos_qty, initial_uos_qty), 0.0)
+ changes = self.pool.get('stock.move').onchange_uos_quantity(cr, uid, ids,
+ product_id, product_uos_qty, product_uos, product_uom)
+ # Update the remaining qty
+ vals = changes['value']
+ vals.update({
+ 'product_uos_qty': product_uos_qty,
+ 'rest_qty': max(initial_qty - vals.get('product_qty', 0.0), 0.0),
+ 'rest_uos_qty': max(initial_uos_qty - product_uos_qty, 0.0) })
+ return changes
+
+ def split(self, cr, uid, ids, context=None):
+ """Call stock.move.split() in a loop, then take the selected action.
+
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param ids: list of ids of wizard objects
+ @param context: A standard dictionary
+ @return: Dictionary with directives to close the window
+ """
+ if context is None or 'active_ids' not in context:
+ return False
+ move_obj = self.pool.get('stock.move')
+ move_ids = context['active_ids']
+ for data in self.browse(cr, uid, ids):
+ new_move_ids = move_obj.split(cr, uid, move_ids, data.product_qty,
+ data.product_uos_qty, context=context)
+ # Process the various values of 'action here
+ if data.action=='none':
+ pass
+ return {'type': 'ir.actions.act_window_close'}
+
+ def default_get(self, cr, uid, fields, context=None):
+ """ Get default values from the active Move in the context
+ @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 default value
+ @param context: A standard dictionary
+ @return: default values of fields
+ """
+ defaults = super(StockMoveSplitSimple, self).default_get(cr, uid,
+ fields, context=context)
+ if 'action' not in defaults:
+ defaults['action'] = 'none'
+ if context is None or 'active_id' not in context:
+ return defaults
+ # Find the fields we need to read
+ move_fields = filter(lambda x:x in fields,
+ ['product_id', 'product_qty', 'product_uom',
+ 'product_uos_qty', 'product_uos'])
+ # Read the values
+ move = self.pool.get('stock.move').read(cr, uid, context['active_id'],
+ move_fields, context=context)
+ if move:
+ for field in [f for f in move_fields if move[f]] :
+ # Set the related ID as default
+ if type(move[field])==tuple:
+ defaults[field] = move[field][0]
+ else:
+ defaults[field] = move[field]
+ if 'initial_qty' in fields:
+ defaults['initial_qty'] = defaults.get('product_qty')
+ if 'rest_qty' in fields:
+ defaults['rest_qty'] = 0.0
+ if 'initial_uos_qty' in fields:
+ defaults['initial_uos_qty'] = defaults.get('product_uos_qty')
+ if 'rest_uos_qty' in fields:
+ defaults['rest_uos_qty'] = 0.0
+ return defaults
+
+StockMoveSplitSimple()
+
class stock_move_consume(osv.osv_memory):
_name = "stock.move.consume"
_description = "Consume Products"
=== modified file 'stock/wizard/stock_move_view.xml'
--- stock/wizard/stock_move_view.xml 2011-10-16 01:28:00 +0000
+++ stock/wizard/stock_move_view.xml 2012-05-09 17:22:29 +0000
@@ -1,6 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
+ <!-- Split Stock Moves -->
+ <record id="view_stock_move_split_simple" model="ir.ui.view">
+ <field name="name">Split Move</field>
+ <field name="model">stock.move.split.simple</field>
+ <field name="type">form</field>
+ <field name="arch" type="xml">
+ <form string="Split Move">
+ <group colspan="4" col="4" groups="base.group_extended">
+ <separator string="Dispatch Products to a new Stock Move" colspan="4"/>
+ <field name="product_id" colspan="4"/>
+ <field name="initial_qty"/>
+ <field name="product_uom"/>
+ <field name="initial_uos_qty" groups="product.group_uos"/>
+ <field name="product_uos" groups="product.group_uos"/>
+ </group>
+ <!-- this group lets the window shrink in simplified view -->
+ <group colspan="2" col="2">
+ <separator string="Quantity split" colspan="2" />
+ <field name="product_qty"
+ on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos, initial_qty, initial_uos_qty)"/>
+ <field name="product_uos_qty" groups="product.group_uos"
+ on_change="onchange_uos_quantity(product_id, product_uos_qty, product_uos, product_uom, initial_qty, initial_uos_qty)"/>
+ </group>
+ <group colspan="2" col="2">
+ <separator string="Quantity remaining" colspan="2" />
+ <field name="rest_qty"/>
+ <field name="rest_uos_qty" groups="product.group_uos"/>
+ <field name="action"/>
+ </group>
+ <separator string="" colspan="4" />
+ <label string="" colspan="2" />
+ <group col="2" colspan="1">
+ <button icon='gtk-cancel' special="cancel"
+ string="Cancel" />
+ <button name="split" string="Ok"
+ colspan="1" type="object" icon="gtk-ok" />
+ </group>
+ </form>
+ </field>
+ </record>
+ <record id="split_move" model="ir.actions.act_window">
+ <field name="name">Split Move</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">stock.move.split.simple</field>
+ <field name="view_type">form</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+
<!-- Consume, scrap move -->
<record id="view_stock_move_consume_wizard" model="ir.ui.view">