diff --git a/inventory.py b/inventory.py
index 073f8be28a..6a1e4519ea 100644
--- a/inventory.py
+++ b/inventory.py
@@ -20,7 +20,7 @@ class Inventory(OSV):
date = fields.DateTime('Date', readonly=True)
lost_found = fields.Many2One(
'stock.location', 'Lost and Found', required=True,
- domain="[('type', '=', 'inventory')]", states=STATES,)
+ domain="[('type', '=', 'lost_found')]", states=STATES,)
lines = fields.One2Many(
'stock.inventory.line', 'inventory', 'Inventory Lines', states=STATES,)
moves = fields.Many2Many(
@@ -36,8 +36,10 @@ class Inventory(OSV):
super(Inventory, self).__init__()
self._order.insert(0, ('date', 'DESC'))
self._rpc_allowed += [
- 'set_state_done',
- ]
+ 'set_state_cancel',
+ 'set_state_open',
+ 'set_state_done',
+ ]
def default_state(self, cursor, user, context=None):
return 'open'
@@ -46,14 +48,29 @@ class Inventory(OSV):
return datetime.datetime.today()
def set_state_cancel(self, cursor, user, ids, context=None):
+ self.write(cursor, user, ids, {
+ 'state': 'cancel',
+ }, context=context)
+
+ def set_state_open(self, cursor, user, ids, context=None):
+ self.write(cursor, user, ids, {
+ 'state': 'open',
+ }, context=context)
+
+
+ def set_state_done(self, cursor, user, ids, context=None):
+ self.write(cursor, user, ids, {
+ 'state': 'done',
+ }, context=context)
+
+ def _cancel(self, cursor, user, ids, context=None):
move_obj = self.pool.get("stock.move")
inventories = self.browse(cursor, user, ids, context=context)
move_ids = \
[move.id for inventory in inventories for move in inventory.moves]
- move_obj.set_state_cancel(cursor, user, move_ids, context=context)
- self.write(cursor, user, ids, {'state':'cancel'})
+ return move_obj.set_state_cancel(cursor, user, move_ids, context=context)
- def set_state_done(self, cursor, user, ids, context=None):
+ def _done(self, cursor, user, ids, context=None):
product_obj = self.pool.get('product.product')
move_obj = self.pool.get('stock.move')
inventories = self.browse(cursor, user, ids, context=context)
@@ -63,14 +80,16 @@ class Inventory(OSV):
for inventory in inventories:
location_ids.append(inventory.location.id)
inv_by_loc[inventory.location.id] = inventory.id
- raw_data = product_obj.raw_products_by_location(
- cursor, user, location_ids, context=context)
+ raw_data = product_obj.raw_products_by_location(cursor, user,
+ location_ids, context=context)
indexed_data = {}
for location, product, uom, qty in raw_data:
- indexed_data.setdefault(location,{})[(product,uom)] = qty
+ indexed_data.setdefault(location,{})[(product, uom)] = qty
for inventory in inventories:
+ if inventory.state != 'open':
+ continue
moves = []
location_data = indexed_data.get(inventory.location.id, {})
for line in inventory.lines:
@@ -85,17 +104,14 @@ class Inventory(OSV):
(from_location, to_location, delta_qty) = \
(to_location, from_location, -delta_qty)
- move_id = move_obj.create(
- cursor, user,
- {'from_location': from_location,
- 'to_location': to_location,
- 'quantity': delta_qty,
- 'product': line.product.id,
- 'uom': line.uom.id,
- 'state': 'done'
- },
- context=context,
- )
+ move_id = move_obj.create(cursor, user, {
+ 'from_location': from_location,
+ 'to_location': to_location,
+ 'quantity': delta_qty,
+ 'product': line.product.id,
+ 'uom': line.uom.id,
+ 'state': 'done',
+ }, context=context)
moves.append(move_id)
# Create move for all missing products
for (product, uom), qty in location_data.iteritems():
@@ -107,23 +123,29 @@ class Inventory(OSV):
(from_location, to_location, qty) = \
(to_location, from_location, -qty)
- move_id = move_obj.create(
- cursor, user,
- {'from_location': from_location,
- 'to_location': to_location,
- 'quantity': qty,
- 'product': product,
- 'uom': uom,
- 'state': 'done'
- },
- context=context,
- )
+ move_id = move_obj.create(cursor, user, {
+ 'from_location': from_location,
+ 'to_location': to_location,
+ 'quantity': qty,
+ 'product': product,
+ 'uom': uom,
+ 'state': 'done',
+ }, context=context)
moves.append(move_id)
- self.write(cursor, user, ids,
- {'state':'done',
- 'date': datetime.datetime.today(),
- 'moves': [('set',moves)]})
+ return self.write(cursor, user, ids, {
+ 'date': datetime.datetime.today(),
+ 'moves': [('add', x) for x in moves],
+ }, context=context)
+
+ def write(self, cursor, user, ids, vals, context=None):
+ if 'state' in vals:
+ if vals['state'] == 'done':
+ self._done(cursor, user, ids, context=context)
+ elif vals['state'] == 'cancel':
+ self._cancel(cursor, user, ids, context=context)
+ return super(Inventory, self).write(cursor, user, ids, vals,
+ context=context)
Inventory()
@@ -145,6 +167,8 @@ class InventoryLine(OSV):
self._sql_constraints += [
('check_line_qty_pos',
'CHECK(quantity >= 0.0)', 'Move quantity must be positive'),
+ ('inventory_product_uniq', 'UNIQUE(inventory, product)',
+ 'Product must be unique by inventory!'),
]
def on_change_product(self, cursor, user, ids, value, context=None):
@@ -175,7 +199,7 @@ class CompleteInventory(Wizard):
inventory_obj = self.pool.get('stock.inventory')
product_obj = self.pool.get('product.product')
inventories = inventory_obj.browse(cursor, user, data['ids'],
- context=context)
+ context=context)
location_ids = []
inv_by_loc = {}
for inventory in inventories:
@@ -204,40 +228,3 @@ class CompleteInventory(Wizard):
return {}
CompleteInventory()
-
-
-class CancelInventoryInit(WizardOSV):
- _name = 'stock.inventory.cancel.init'
-CancelInventoryInit()
-
-
-class CancelInventory(Wizard):
- 'Cancel Inventory'
- _name = 'stock.inventory.cancel'
- states = {
- 'init': {
- 'result': {
- 'type': 'form',
- 'object': 'stock.inventory.cancel.init',
- 'state': [
- ('end', 'Cancel', 'gtk-cancel'),
- ('cancel', 'Ok', 'gtk-ok', True),
- ],
- },
- },
- 'cancel': {
- 'result': {
- 'type': 'action',
- 'action': '_action_cancel',
- 'state': 'end',
- },
- },
- }
-
- def _action_cancel(self, cursor, user, data, context=None):
- inventory_obj = self.pool.get('stock.inventory')
- inventory_obj.set_state_cancel(
- cursor, user, data['ids'], context=context)
- return {}
-
-CancelInventory()
diff --git a/inventory.xml b/inventory.xml
index ab78a9de94..0442bbd430 100644
--- a/inventory.xml
+++ b/inventory.xml
@@ -1,22 +1,9 @@
-
-
- stock.inventory.cancel.init
- form
-
-
-
-
-
- ]]>
-
-
-
- Cancel Inventory
- stock.inventory.cancel
+
+ Complete Inventory
+ stock.inventory.complete
@@ -31,17 +18,27 @@
+
+
-
+
+
+
-
@@ -112,16 +109,5 @@
]]>
-
-
- Complete Inventory
- stock.inventory.complete
-
-
- form_action
- stock.inventory,0
-
-
-
diff --git a/location.py b/location.py
index d4f9a204ae..a4530b96d5 100644
--- a/location.py
+++ b/location.py
@@ -22,7 +22,7 @@ class Location(OSV):
type = fields.Selection([
('supplier', 'Supplier'),
('customer', 'Customer'),
- ('inventory', 'Inventory'),
+ ('lost_found', 'Lost and Found'),
('warehouse', 'Warehouse'),
('storage', 'Storage'),
('production', 'Production'),
diff --git a/location.xml b/location.xml
index 0d417c38dd..f3d27afaa5 100644
--- a/location.xml
+++ b/location.xml
@@ -171,6 +171,10 @@
CUS
customer
+
+ Lost and Found
+ lost_found
+
supplier_location
diff --git a/move.py b/move.py
index daffe89c33..fb365bb10c 100644
--- a/move.py
+++ b/move.py
@@ -235,7 +235,7 @@ class Move(OSV):
def set_state_assigned(self, cursor, user, ids, context=None):
return self.write(cursor, user, ids, {
- 'state': 'waiting',
+ 'state': 'assigned',
}, context=context)
def write(self, cursor, user, ids, vals, context=None):
diff --git a/packing.py b/packing.py
index 9e2e4498e1..2a26a56822 100644
--- a/packing.py
+++ b/packing.py
@@ -273,15 +273,8 @@ class PackingOut(OSV):
def __init__(self):
super(PackingOut, self).__init__()
self._rpc_allowed += [
- 'set_state_done',
- 'set_state_waiting',
- 'set_state_draft',
- 'set_state_cancel',
- 'set_state_assigned',
- 'set_state_ready',
- 'assign_try',
- 'assign_force',
- ]
+ 'button_draft',
+ ]
self._order[0] = ('id', 'DESC')
def default_state(self, cursor, user, context=None):
@@ -493,6 +486,12 @@ class PackingOut(OSV):
move_obj = self.pool.get('stock.move')
product_obj = self.pool.get('product.product')
uom_obj = self.pool.get('product.uom')
+
+ if context is None:
+ context = {}
+
+ cursor.execute('LOCK TABLE stock_move')
+
packing = self.browse(cursor, user, id, context=context)
parent_to_locations = {}
inventory_moves = []
@@ -514,7 +513,7 @@ class PackingOut(OSV):
parent_to_locations[move.from_location.id] = childs
# Collect all raw quantities
- context = context or {}
+ context = context.copy()
context.update({'in_states': ['done', 'assigned'],
'out_states': ['done', 'assigned']})
raw_data = product_obj.raw_products_by_location(
@@ -580,6 +579,11 @@ class PackingOut(OSV):
{'state':'assigned'})
return True
+ def button_draft(self, cursor, user, ids, context=None):
+ workflow_service = LocalService('workflow')
+ for packing in self.browse(cursor, user, ids, context=context):
+ workflow_service.trg_create(user, self._name, packing.id, cursor)
+
PackingOut()
diff --git a/packing.xml b/packing.xml
index 62b98c8325..77d4700eb7 100644
--- a/packing.xml
+++ b/packing.xml
@@ -175,7 +175,7 @@
form
+
@@ -445,57 +448,57 @@
id="packingout_trans_waiting_assigned">
- signal_assign
+ assign
assign_try()
- signal_force_assign
+ force_assign
assign_force()
- signal_waiting
+ waiting
- signal_cancel
+ cancel
- signal_cancel
+ cancel
- signal_ready
+ ready
- signal_done
+ done
- signal_cancel
+ cancel
- signal_cancel
+ cancel