diff --git a/inventory.py b/inventory.py
index 96b4ba7cdf..ef720d7c93 100644
--- a/inventory.py
+++ b/inventory.py
@@ -2,7 +2,7 @@
#of this repository contains the full copyright notices and license terms.
'Inventory'
from trytond.osv import fields, OSV
-from trytond.wizard import Wizard
+from trytond.wizard import Wizard, WizardOSV
STATES = {
'readonly': "state != 'draft'",
@@ -120,17 +120,33 @@ class Inventory(OSV):
'inventory': new_id,
'move': False,
}, context=context)
+ self.complete_lines(cursor, user, new_id,
+ product_ids=[x.product.id for x in inventory.lines],
+ context=context)
new_ids.append(new_id)
- self.complete_lines(cursor, user, new_ids, context=context)
if int_id:
return new_ids[0]
return new_ids
- def complete_lines(self, cursor, user, ids, context=None):
+ def complete_lines(self, cursor, user, ids, product_ids=None, context=None):
+ '''
+ Complete or update the inventories
+
+ :param cursor: the database cursor
+ :param user: the user id
+ :param ids: the ids of stock.inventory
+ :param product_ids: the ids of product.product
+ if None all products are used
+ :param context: the context
+ '''
line_obj = self.pool.get('stock.inventory.line')
product_obj = self.pool.get('product.product')
uom_obj = self.pool.get('product.uom')
+
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+
inventories = self.browse(cursor, user, ids,
context=context)
context = context and context.copy() or {}
@@ -141,10 +157,11 @@ class Inventory(OSV):
context['stock_date_end'] = inventory.date
pbl = product_obj.products_by_location(
cursor, user, [inventory.location.id],
- context=context)
+ product_ids=product_ids, context=context)
else:
pbl = product_obj.products_by_location(
- cursor, user, [inventory.location.id], context=context)
+ cursor, user, [inventory.location.id],
+ product_ids=product_ids, context=context)
# Index some data
product2uom = {}
@@ -299,11 +316,34 @@ class InventoryLine(OSV):
InventoryLine()
+class CompleteInventoryInit(WizardOSV):
+ 'Complete Inventory Init'
+ _name = 'stock.inventory.complete.init'
+ _description = __doc__
+
+ products = fields.Many2Many('product.product', None, None, None,
+ 'Products', domain=[('type', '=', 'stockable')])
+ categories = fields.Many2Many('product.category', None, None, None,
+ 'Categories')
+
+CompleteInventoryInit()
+
+
class CompleteInventory(Wizard):
'Complete Inventory'
_name = 'stock.inventory.complete'
states = {
'init': {
+ 'result': {
+ 'type': 'form',
+ 'object': 'stock.inventory.complete.init',
+ 'state': [
+ ('end', 'Cancel', 'tryton-cancel'),
+ ('complete', 'Complete', 'tryton-ok', True),
+ ],
+ },
+ },
+ 'complete': {
'result': {
'type': 'action',
'action': '_complete',
@@ -313,8 +353,25 @@ class CompleteInventory(Wizard):
}
def _complete(self, cursor, user, data, context=None):
+ category_obj = self.pool.get('product.category')
+ product_obj = self.pool.get('product.product')
+
+ product_ids = data['form']['products'][0][1] or []
+ category_ids = data['form']['categories'][0][1] or []
+
+ if category_ids:
+ child_category_ids = category_obj.search(cursor, user,
+ [('parent', 'child_of', category_ids)], context=context)
+ cat_product_ids = product_obj.search(cursor, user, [
+ ('category', 'in', child_category_ids),
+ ('type', '=', 'stockable'),
+ ], context=context)
+ if cat_product_ids:
+ product_ids += cat_product_ids
+
inventory_obj = self.pool.get('stock.inventory')
- inventory_obj.complete_lines(cursor, user, data['ids'], context=context)
+ inventory_obj.complete_lines(cursor, user, data['ids'],
+ product_ids=product_ids, context=context)
return {}
diff --git a/inventory.xml b/inventory.xml
index e03cffb4f9..8ed912e1f1 100644
--- a/inventory.xml
+++ b/inventory.xml
@@ -196,5 +196,30 @@ this repository contains the full copyright notices and license terms. -->
+
+ stock.inventory.complete.init
+ form
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+
+