Merge
This commit is contained in:
commit
4e88be8507
7 files changed
+117
-133
No files matched your search
+60
-73
@@ -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()
|
||||
+17
-31
@@ -1,22 +1,9 @@
|
||||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="inventory_select_init_view_form">
|
||||
<field name="model">stock.inventory.cancel.init</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Cancel Inventory" col="1">
|
||||
<separator string="Warning"/>
|
||||
<label string="All generated moves will be cancelled."/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_inventory_cancel">
|
||||
<field name="name">Cancel Inventory</field>
|
||||
<field name="wiz_name">stock.inventory.cancel</field>
|
||||
<record model="ir.action.wizard" id="wizard_complete_inventory">
|
||||
<field name="name">Complete Inventory</field>
|
||||
<field name="wiz_name">stock.inventory.complete</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="inventory_view_form">
|
||||
@@ -31,17 +18,27 @@
|
||||
<field name="lost_found"/>
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
<label colspan="4"/>
|
||||
<button string="Complete Inventory" type="action"
|
||||
name="%(wizard_complete_inventory)d"
|
||||
states="{'readonly': '''state != 'open' '''}"
|
||||
colspan="2"
|
||||
help="Add an inventory line for each missing products"/>
|
||||
<field name="lines" colspan="6"/>
|
||||
<group col="4" colspan="6">
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
<group colspan="2" col="2">
|
||||
<group colspan="2" col="3">
|
||||
<button string="Cancel"
|
||||
name="set_state_cancel" type="object"
|
||||
states="{'invisible': '''state == 'cancel' '''}"
|
||||
confirm="All generated moves will be cancelled!"/>
|
||||
<button string="Re-Open"
|
||||
name="set_state_open" type="object"
|
||||
states="{'invisible': '''state != 'cancel' '''}"/>
|
||||
<button string="Confirm"
|
||||
name="set_state_done" type="object"
|
||||
states="{'invisible': '''state in ('done','cancel') '''}"/>
|
||||
<button string="Cancel"
|
||||
name="%(wizard_inventory_cancel)d" type="action"
|
||||
states="{'invisible': '''state in ('open','cancel') '''}"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
@@ -112,16 +109,5 @@
|
||||
]]>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="act_complete_inventory">
|
||||
<field name="name">Complete Inventory</field>
|
||||
<field name="wiz_name">stock.inventory.complete</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="act_complete_inventory_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">stock.inventory,0</field>
|
||||
<field name="action" ref="act_complete_inventory"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</tryton>
|
||||
+1
-1
@@ -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'),
|
||||
|
||||
@@ -171,6 +171,10 @@
|
||||
<field name="code">CUS</field>
|
||||
<field name="type">customer</field>
|
||||
</record>
|
||||
<record model="stock.location" id="location_lost_found">
|
||||
<field name="name">Lost and Found</field>
|
||||
<field name="type">lost_found</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.property" id="property_supplier_location">
|
||||
<field name="name">supplier_location</field>
|
||||
|
||||
@@ -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):
|
||||
|
||||
+14
-10
@@ -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()
|
||||
|
||||
|
||||
|
||||
+20
-17
@@ -175,7 +175,7 @@
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<![CDATA[
|
||||
<form string="Supplier Packing" col="4">
|
||||
<form string="Customer Packing" col="4">
|
||||
<label name="code"/>
|
||||
<field name="code"/>
|
||||
<label name="customer_address"/>
|
||||
@@ -199,26 +199,29 @@
|
||||
<group col="4" colspan="4">
|
||||
<label name="state"/>
|
||||
<field name="state"/>
|
||||
<group col="6" colspan="2">
|
||||
<button string="Cancel" name="signal_cancel"
|
||||
<group col="7" colspan="2">
|
||||
<button string="Cancel" name="cancel"
|
||||
states="{'invisible': '''state in
|
||||
('cancel','done') '''}"/>
|
||||
<button string="Set Done" name="signal_done"
|
||||
<button string="Set Done" name="done"
|
||||
states="{'invisible': '''state !=
|
||||
'ready' '''}"/>
|
||||
<button string="Set Waiting" name="signal_waiting"
|
||||
<button string="Set Waiting" name="waiting"
|
||||
states="{'invisible': '''state !=
|
||||
'draft' '''}"/>
|
||||
<button string="Force Assign"
|
||||
name="signal_force_assign"
|
||||
name="force_assign"
|
||||
states="{'invisible': '''state !=
|
||||
'waiting' '''}"/>
|
||||
<button string="Assign" name="signal_assign"
|
||||
<button string="Assign" name="assign"
|
||||
states="{'invisible': '''state !=
|
||||
'waiting' '''}"/>
|
||||
<button string="Set ready" name="signal_ready"
|
||||
<button string="Set ready" name="ready"
|
||||
states="{'invisible': '''state !=
|
||||
'assigned' '''}"/>
|
||||
<button string="Reset to Draft" name="button_draft"
|
||||
type="object"
|
||||
states="{'invisible': '''state != 'cancel' '''}"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
@@ -445,57 +448,57 @@
|
||||
id="packingout_trans_waiting_assigned">
|
||||
<field name="act_from" ref="packingout_act_waiting"/>
|
||||
<field name="act_to" ref="packingout_act_assigned"/>
|
||||
<field name="signal">signal_assign</field>
|
||||
<field name="signal">assign</field>
|
||||
<field name="condition">assign_try()</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_waiting_assigned_force">
|
||||
<field name="act_from" ref="packingout_act_waiting"/>
|
||||
<field name="act_to" ref="packingout_act_assigned"/>
|
||||
<field name="signal">signal_force_assign</field>
|
||||
<field name="signal">force_assign</field>
|
||||
<field name="condition">assign_force()</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_draft_waiting">
|
||||
<field name="act_from" ref="packingout_act_draft"/>
|
||||
<field name="act_to" ref="packingout_act_waiting"/>
|
||||
<field name="signal">signal_waiting</field>
|
||||
<field name="signal">waiting</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_waiting_cancel">
|
||||
<field name="act_from" ref="packingout_act_waiting"/>
|
||||
<field name="act_to" ref="packingout_act_cancel"/>
|
||||
<field name="signal">signal_cancel</field>
|
||||
<field name="signal">cancel</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_draft_cancel">
|
||||
<field name="act_from" ref="packingout_act_draft"/>
|
||||
<field name="act_to" ref="packingout_act_cancel"/>
|
||||
<field name="signal">signal_cancel</field>
|
||||
<field name="signal">cancel</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_assigned_ready">
|
||||
<field name="act_from" ref="packingout_act_assigned"/>
|
||||
<field name="act_to" ref="packingout_act_ready"/>
|
||||
<field name="signal">signal_ready</field>
|
||||
<field name="signal">ready</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_ready_done">
|
||||
<field name="act_from" ref="packingout_act_ready"/>
|
||||
<field name="act_to" ref="packingout_act_done"/>
|
||||
<field name="signal">signal_done</field>
|
||||
<field name="signal">done</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_assigned_cancel">
|
||||
<field name="act_from" ref="packingout_act_assigned"/>
|
||||
<field name="act_to" ref="packingout_act_cancel"/>
|
||||
<field name="signal">signal_cancel</field>
|
||||
<field name="signal">cancel</field>
|
||||
</record>
|
||||
<record model="workflow.transition"
|
||||
id="packingout_trans_ready_cancel">
|
||||
<field name="act_from" ref="packingout_act_ready"/>
|
||||
<field name="act_to" ref="packingout_act_cancel"/>
|
||||
<field name="signal">signal_cancel</field>
|
||||
<field name="signal">cancel</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user