Merge lp:~numerigraphe-team/ocb-addons/7.0-inventory-lines-sorted into lp:ocb-addons

Proposed by Lionel Sausin - Initiatives/Numérigraphe
Status: Merged
Approved by: Holger Brunn (Therp)
Approved revision: no longer in the source branch.
Merged at revision: 10178
Proposed branch: lp:~numerigraphe-team/ocb-addons/7.0-inventory-lines-sorted
Merge into: lp:ocb-addons
Diff against target: 40 lines (+23/-0)
1 file modified
stock/stock.py (+23/-0)
To merge this branch: bzr merge lp:~numerigraphe-team/ocb-addons/7.0-inventory-lines-sorted
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Needs Information
Loïc Bellier - Numérigraphe (community) code review Approve
Raphaël Valyi - http://www.akretion.com Approve
Holger Brunn (Therp) code review Approve
Review via email: mp+210467@code.launchpad.net

Description of the change

This branch makes the inventory lines sorted on location name, product name and serial number.
It greatly eases the work of inventory workers when counting big inventories.
This solution is backported from trunk-wms (future v8), with an additionnal improvement to sort on serial numbers' names instead of their IDs.

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

In this context, I would have written
self
instead of
self.pool.get('stock.inventory.line')
but given that it's the same in upstream, I'm fine with it as it is.

review: Approve (code review)
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

and thankfully, upstream is not me and did it right because self is not stock.inventory.line in this context. So please ignore the comment above...

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

rather new feature while this will likely be rewritten in v8. I would say if you need it merge it, but not sure that should be in what OCB is defining itself.

review: Abstain
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Oh, this is actually a backport of trunk-wms. Then I'm fine with it!

review: Approve
Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) :
review: Approve (code review)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Couldn't a composed index on the columns "inventory_id, location_name, product_code, product_name, prodlot_name" be useful?

review: Needs Information
Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) wrote :

Hi gbaconnier,

Yes it's useful to always order the lines on the same order.
Without this index, search for productions lot for a same product, or a same product on different locations can be painful on thousands of inventory lines.
This index is useful for having the same order on printing and screen without re-order.

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

While the index is a good thing to have, I merge this already as we can add the index afterwards

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Thanks for merging. I've begun work on adding the index here: lp:~numerigraphe-team/ocb-addons/7.0-line-order-index
I still need to make sure it's worth pushing it. I'll soon be able to test on a DB with lots of rows: I'll keep you posted.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

I've made a quick regarding the index, it seems not very useful - once the rows are filtered on inventory_id, PG prefers to simply do a table scan + sort rather than an index scan.
The only point I see in this index would be to let the DBA schedule a CLUSTER on it to speed up the table scan, but that's a bit overkill for most cases I suppose.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock/stock.py'
2--- stock/stock.py 2014-03-04 13:08:40 +0000
3+++ stock/stock.py 2014-03-11 18:17:12 +0000
4@@ -2954,6 +2954,17 @@
5 _name = "stock.inventory.line"
6 _description = "Inventory Line"
7 _rec_name = "inventory_id"
8+ _order = "inventory_id, location_name, product_code, product_name, prodlot_name"
9+
10+ def _get_product_name_change(self, cr, uid, ids, context=None):
11+ return self.pool.get('stock.inventory.line').search(cr, uid, [('product_id', 'in', ids)], context=context)
12+
13+ def _get_location_change(self, cr, uid, ids, context=None):
14+ return self.pool.get('stock.inventory.line').search(cr, uid, [('location_id', 'in', ids)], context=context)
15+
16+ def _get_prodlot_change(self, cr, uid, ids, context=None):
17+ return self.pool.get('stock.inventory.line').search(cr, uid, [('prod_lot_id', 'in', ids)], context=context)
18+
19 _columns = {
20 'inventory_id': fields.many2one('stock.inventory', 'Inventory', ondelete='cascade', select=True),
21 'location_id': fields.many2one('stock.location', 'Location', required=True),
22@@ -2963,6 +2974,18 @@
23 'company_id': fields.related('inventory_id','company_id',type='many2one',relation='res.company',string='Company',store=True, select=True, readonly=True),
24 'prod_lot_id': fields.many2one('stock.production.lot', 'Serial Number', domain="[('product_id','=',product_id)]"),
25 'state': fields.related('inventory_id','state',type='char',string='Status',readonly=True),
26+ 'product_name': fields.related('product_id', 'name', type='char', string='Product name', store={
27+ 'product.product': (_get_product_name_change, ['name', 'default_code'], 20),
28+ 'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['product_id'], 20),}),
29+ 'product_code': fields.related('product_id', 'default_code', type='char', string='Product code', store={
30+ 'product.product': (_get_product_name_change, ['name', 'default_code'], 20),
31+ 'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['product_id'], 20),}),
32+ 'location_name': fields.related('location_id', 'complete_name', type='char', string='Location name', store={
33+ 'stock.location': (_get_location_change, ['name', 'location_id', 'active'], 20),
34+ 'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['location_id'], 20),}),
35+ 'prodlot_name': fields.related('prod_lot_id', 'name', type='char', string='Serial Number name', store={
36+ 'stock.production.lot': (_get_prodlot_change, ['name'], 20),
37+ 'stock.inventory.line': (lambda self, cr, uid, ids, c={}: ids, ['prod_lot_id'], 20),}),
38 }
39
40 def _default_stock_location(self, cr, uid, context=None):