mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_reserve: views, keep the stock reservation after release
This commit is contained in:
@@ -59,21 +59,15 @@ class stock_reservation(orm.Model):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
reservations = self.browse(cr, uid, ids, context=context)
|
||||
move_ids = [reserv.move_id.id for reserv in reservations]
|
||||
move_obj.write(cr, uid, move_ids,
|
||||
{'date_expected': fields.datetime.now()},
|
||||
context=context)
|
||||
move_obj.action_confirm(cr, uid, move_ids, context=context)
|
||||
move_obj.force_assign(cr, uid, move_ids, context=context)
|
||||
move_obj.action_done(cr, uid, move_ids, context=context)
|
||||
return True
|
||||
|
||||
def release(self, cr, uid, ids, context=None):
|
||||
return self.unlink(cr, uid, ids, context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
# TODO
|
||||
return super(stock_reservation, self).create(cr, uid, vals,
|
||||
context=context)
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
""" Release the reservation """
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
reservations = self.read(cr, uid, ids, ['move_id'],
|
||||
@@ -81,17 +75,23 @@ class stock_reservation(orm.Model):
|
||||
move_obj = self.pool.get('stock.move')
|
||||
move_ids = [reserv['move_id'] for reserv in reservations]
|
||||
move_obj.action_cancel(cr, uid, move_ids, context=context)
|
||||
return True
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
""" Release the reservation before the unlink """
|
||||
self.release(cr, uid, ids, context=context)
|
||||
return super(stock_reservation, self).unlink(cr, uid, ids,
|
||||
context=context)
|
||||
|
||||
def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
|
||||
loc_dest_id=False, partner_id=False):
|
||||
loc_dest_id=False, partner_id=False, context=None):
|
||||
""" On change of product id, if finds UoM, UoS,
|
||||
quantity and UoS quantity.
|
||||
"""
|
||||
move_obj = self.pool.get('stock.move')
|
||||
if ids:
|
||||
reserv = self.read(cr, uid, ids, ['move_id'], load='_classic_write')
|
||||
reserv = self.read(cr, uid, ids, ['move_id'], context=context,
|
||||
load='_classic_write')
|
||||
move_ids = [rv['move_id'] for rv in reserv]
|
||||
else:
|
||||
move_ids = []
|
||||
@@ -99,14 +99,9 @@ class stock_reservation(orm.Model):
|
||||
cr, uid, move_ids, prod_id=prod_id, loc_id=loc_id,
|
||||
loc_dest_id=loc_dest_id, partner_id=partner_id)
|
||||
|
||||
def onchange_move_type(self, cr, uid, ids, type, context=None):
|
||||
""" On change of move type gives source and destination location.
|
||||
"""
|
||||
move_obj = self.pool.get('stock.move')
|
||||
def _get_reservation_location(self, cr, uid, context=None):
|
||||
location_obj = self.pool.get('stock.location')
|
||||
data_obj = self.pool.get('ir.model.data')
|
||||
result = move_obj.onchange_move_type(cr, uid, ids, type,
|
||||
context=context)
|
||||
get_ref = data_obj.get_object_reference
|
||||
try:
|
||||
__, dest_location_id = get_ref(cr, uid, 'stock_reserve',
|
||||
@@ -115,5 +110,20 @@ class stock_reservation(orm.Model):
|
||||
'read', context=context)
|
||||
except (orm.except_orm, ValueError):
|
||||
dest_location_id = False
|
||||
return dest_location_id
|
||||
|
||||
def onchange_move_type(self, cr, uid, ids, type, context=None):
|
||||
""" On change of move type gives source and destination location.
|
||||
"""
|
||||
move_obj = self.pool.get('stock.move')
|
||||
result = move_obj.onchange_move_type(cr, uid, ids, type,
|
||||
context=context)
|
||||
dest_location_id = self._get_reservation_location(cr, uid, context=context)
|
||||
result['value']['location_dest_id'] = dest_location_id
|
||||
return result
|
||||
|
||||
def onchange_quantity(self, cr, uid, ids, product_id, product_qty, context=None):
|
||||
""" On change of product quantity avoid negative quantities """
|
||||
if not product_id or product_qty <= 0.0:
|
||||
return {'value': {'product_qty': 0.0}}
|
||||
return {}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
class="oe_highlight"
|
||||
states="assigned,confirmed,done"/>
|
||||
<field name="state" widget="statusbar"
|
||||
statusbar_visible="draft,confirm"/>
|
||||
statusbar_visible="draft,done"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<group>
|
||||
@@ -27,28 +27,24 @@
|
||||
<label for="product_qty" />
|
||||
<div>
|
||||
<field name="product_qty"
|
||||
on_change="onchange_quantity(product_id, product_qty)"
|
||||
class="oe_inline"/>
|
||||
<field name="product_uom"
|
||||
groups="product.group_uom" class="oe_inline"/>
|
||||
</div>
|
||||
<field name="date_validity" />
|
||||
<field name="name"/>
|
||||
<field name="date_validity" />
|
||||
<field name="create_date" groups="base.group_no_one"/>
|
||||
<field name="company_id"
|
||||
groups="base.group_multi_company"
|
||||
widget="selection"/>
|
||||
</group>
|
||||
<group name="origin_grp" string="Origin">
|
||||
<group name="location" string="Locations">
|
||||
<field name="type" readonly="1" invisible="1"
|
||||
on_change="onchange_move_type(type)"/>
|
||||
<field name="location_id" groups="stock.group_locations"/>
|
||||
<field name="create_date" groups="base.group_no_one"/>
|
||||
</group>
|
||||
<group name="destination_grp" string="Destination">
|
||||
<field name="location_dest_id"
|
||||
groups="stock.group_locations"/>
|
||||
<field name="date_expected"
|
||||
attrs="{'invisible': [('state', '=', 'done')]}"/>
|
||||
<field name="date" attrs="{'invisible': [('state', '!=', 'done')]}"/>
|
||||
</group>
|
||||
<group name="note" string="Notes">
|
||||
<field name="note" nolabel="1"/>
|
||||
@@ -64,17 +60,21 @@
|
||||
<field name="model">stock.reservation</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Stock Reservations" version="7.0"
|
||||
colors="blue:state == 'draft'" >
|
||||
colors="blue:state == 'draft';grey:state == 'cancel'" >
|
||||
<field name="move_id" />
|
||||
<field name="product_id" />
|
||||
<field name="product_qty" />
|
||||
<field name="product_qty" total="sum" />
|
||||
<field name="product_uom" />
|
||||
<field name="date_validity" />
|
||||
<field name="state"/>
|
||||
<button name="reserve" type="object"
|
||||
string="Reserve"
|
||||
icon="terp-gtk-jump-to-ltr"
|
||||
icon="terp-locked"
|
||||
states="draft"/>
|
||||
<button name="release" type="object"
|
||||
string="Release"
|
||||
icon="gtk-undo"
|
||||
states="assigned,confirmed,done"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -84,9 +84,25 @@
|
||||
<field name="model">stock.reservation</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Stock Reservations" version="7.0">
|
||||
<field name="move_id" />
|
||||
<filter name="draft" string="Draft"
|
||||
domain="[('state', '=', 'draft')]"
|
||||
help="Not already reserved"/>
|
||||
<filter name="reserved" string="Reserved"
|
||||
domain="[('state', '=', 'done')]"
|
||||
help="Moves are reserved."/>
|
||||
<filter name="cancel" string="Released"
|
||||
domain="[('state', '=', 'cancel')]"
|
||||
help="Reservations have been released."/>
|
||||
<field name="product_id" />
|
||||
<field name="state"/>
|
||||
<field name="move_id" />
|
||||
<group expand="0" string="Group By...">
|
||||
<filter string="Status"
|
||||
domain="[]" context="{'group_by': 'state'}"/>
|
||||
<filter string="Product" domain="[]"
|
||||
context="{'group_by': 'product_id'}"/>
|
||||
<filter string="Product UoM" domain="[]"
|
||||
context="{'group_by': 'product_uom'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@@ -98,7 +114,8 @@
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="view_stock_reservation_tree"/>
|
||||
<field name="search_view_id" ref="view_stock_reservation_search"/>
|
||||
<field name="context">{}</field>
|
||||
<field name="context">{'search_default_draft': 1,
|
||||
'search_default_reserved': 1}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="oe_view_nocontent_create">
|
||||
Click to create a stock reservation.
|
||||
|
||||
Reference in New Issue
Block a user