[ADD]: * For production lot: Button on stock.move (picking lines) to split/assign in production lots. It opens an osv_memory wizard.

bzr revid: uco@tinyerp.co.in-20091231053319-jxs82bzh1lrrodgr
This commit is contained in:
uco (OpenERP)
2009-12-31 11:03:19 +05:30
parent 02faf6331d
commit 1844b2d05c
2 changed files with 106 additions and 3 deletions
+65
View File
@@ -901,6 +901,71 @@ class stock_production_lot(osv.osv):
stock_production_lot()
class stock_split_production_lots(osv.osv_memory):
_name = "stock.split.production.lots"
_description = "Split Production Lots"
def _quantity_default_get(self, cr, uid, object=False, field=False, context=None):
cr.execute("select %s from %s where id=%s" %(field,object,context.get('active_id')))
res = cr.fetchone()[0]
return res
_columns = {
'name': fields.char('Lot Number/Prefix', size=64, required=True),
'qty': fields.float('Total Quantity'),
'action': fields.selection([('split','Split'),('keepinone','Keep in one lot')],'Action'),
}
_defaults = {
'qty': lambda self,cr,uid,c: self.pool.get('stock.split.production.lots')._quantity_default_get(cr, uid, 'stock_move', 'product_qty',context=c) or 1,
}
def split_lines(self, cr, uid, ids, context={}):
data = self.read(cr, uid, ids[0])
prodlot_obj = self.pool.get('stock.production.lot')
move_obj = self.pool.get('stock.move')
move_browse = move_obj.browse(cr, uid, context['active_id'])
quantity = data['qty']
if quantity <= 0 or move_browse.product_qty == 0:
return {}
uos_qty = quantity/move_browse.product_qty*move_browse.product_uos_qty
quantity_rest = move_browse.product_qty%quantity
uos_qty_rest = quantity_rest/move_browse.product_qty*move_browse.product_uos_qty
update_val = {
'product_qty': quantity,
'product_uos_qty': uos_qty,
}
new_move = []
for idx in range(int(move_browse.product_qty//quantity)):
if idx:
current_move = move_obj.copy(cr, uid, move_browse.id, {'state': move_browse.state})
new_move.append(current_move)
else:
current_move = move_browse.id
new_prodlot = prodlot_obj.create(cr, uid, {'name': data['name'], 'ref': '%d'%idx}, {'product_id': move_browse.product_id.id})
update_val['prodlot_id'] = new_prodlot
move_obj.write(cr, uid, [current_move], update_val)
if quantity_rest > 0:
idx = int(move_browse.product_qty//quantity)
update_val['product_qty'] = quantity_rest
update_val['product_uos_qty'] = uos_qty_rest
if idx:
current_move = move_obj.copy(cr, uid, move_browse.id, {'state': move_browse.state})
new_move.append(current_move)
else:
current_move = move_browse.id
new_prodlot = prodlot_obj.create(cr, uid, {'name': data['name'], 'ref': '%d'%idx}, {'product_id': move_browse.product_id.id})
update_val['prodlot_id'] = new_prodlot
move_obj.write(cr, uid, [current_move], update_val)
return {}
stock_split_production_lots()
class stock_production_lot_revision(osv.osv):
_name = 'stock.production.lot.revision'
+41 -3
View File
@@ -481,6 +481,32 @@
=============================
Picking
=============================
<record id="view_stock_split_production_lots" model="ir.ui.view">
<field name="name">Split Production Lots</field>
<field name="model">stock.split.production.lots</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Split Production Lots">
<group col="4" colspan="4">
<field name="name"/>
<field name="qty" attrs="{'readonly':[('action','!=','split')]}"/>
<field name="action" colspan="4"/>
</group>
<newline/>
<button name="split_lines" string="Ok" type="object" icon="gtk-go-forward"/>
</form>
</field>
</record>
<record id="action_view_stock_split_production_lots" model="ir.actions.act_window">
<field name="name">Split Production Lots</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.split.production.lots</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.ui.view" id="stock_picking_calendar">
<field name="name">stock.picking.calendar</field>
<field name="model">stock.picking</field>
@@ -549,7 +575,11 @@
<field groups="base.group_extended" name="tracking_id" select="2"/>
<newline/>
<label/>
<button name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/>
<!--button name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/-->
<button
string="Split in Production Lots"
name="%(stock.action_view_stock_split_production_lots)d"
icon="gtk-stock" type="action"/>
<separator colspan="4" string="Move State"/>
<field name="state" select="1"/>
<group>
@@ -824,7 +854,11 @@
on_change="onchange_lot_id(prodlot_id,product_qty, location_id, product_id)"/>
<field groups="base.group_extended" name="tracking_id" select="1"/>
<label/>
<button name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/>
<!--button name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/-->
<button
string="Split in Production Lots"
name="%(stock.action_view_stock_split_production_lots)d"
icon="gtk-stock" type="action"/>
<separator colspan="4" string="Move State"/>
<field name="state" select="1"/>
<group>
@@ -980,7 +1014,11 @@
<field groups="base.group_extended" name="tracking_id" select="1"/>
<newline/>
<label/>
<button groups="base.group_extended" name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/>
<!--button groups="base.group_extended" name="%(track_line)d" string="Split in production lots" type="action" icon="gtk-justify-fill"/-->
<button
string="Split in Production Lots"
name="%(stock.action_view_stock_split_production_lots)d"
icon="gtk-stock" type="action"/>
<separator colspan="4" string="Move State"/>
<field name="state" select="1"/>
<group>