Allow to filter on category and product to complete inventory

This commit is contained in:
Cédric Krier committed 2009-01-08 20:07:40 +01:00
1 parent 0875b97e04
commit 382e0f18b1
2 files changed
+88 -6

No files matched your search

+63 -6
View File
@@ -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 {}
+25
View File
@@ -196,5 +196,30 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="inventory_complete_init_view_form">
<field name="model">stock.inventory.complete.init</field>
<field name="type">form</field>
<field name="arch" type="xml">
<![CDATA[
<form string="Complete Inventory">
<separator name="categories" colspan="2"/>
<separator name="products" colspan="2"/>
<field name="categories" colspan="2">
<tree string="Categories" fill="1">
<field name="complete_name"/>
<field name="name" select="1" tree_invisible="1"/>
</tree>
</field>
<field name="products" colspan="2">
<tree string="Products" fill="1">
<field name="name" select="1"/>
<field name="code" select="1"/>
</tree>
</field>
</form>
]]>
</field>
</record>
</data>
</tryton>