Add quantity/forecast_quantity fields fields on Lot

Add these searchable fields using the StockMixin class of stock/move.py

issue3279
review963003
This commit is contained in:
Guillem Barba committed 2013-09-09 14:20:57 +02:00
1 parent 476488c2de
commit e67a26adf1
3 files changed
+23 -1

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add quantity and forecast_quantity fields on Lot
* Add lot in inventory
* Add Period Cache per lot
+19 -1
View File
@@ -6,6 +6,7 @@ from trytond.model import ModelView, ModelSQL, Workflow, fields
from trytond.pyson import Eval
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.modules.stock import StockMixin
__all__ = ['Lot', 'LotType', 'Move', 'ShipmentIn', 'ShipmentOut',
'ShipmentOutReturn',
@@ -14,12 +15,29 @@ __all__ = ['Lot', 'LotType', 'Move', 'ShipmentIn', 'ShipmentOut',
__metaclass__ = PoolMeta
class Lot(ModelSQL, ModelView):
class Lot(ModelSQL, ModelView, StockMixin):
"Stock Lot"
__name__ = 'stock.lot'
_rec_name = 'number'
number = fields.Char('Number', required=True, select=True)
product = fields.Many2One('product.product', 'Product', required=True)
quantity = fields.Function(fields.Float('Quantity'), 'get_quantity',
searcher='search_quantity')
forecast_quantity = fields.Function(fields.Float('Forecast Quantity'),
'get_quantity', searcher='search_quantity')
@classmethod
def get_quantity(cls, lots, name):
location_ids = Transaction().context.get('locations')
products = list(set(l.product for l in lots))
return cls._get_quantity(lots, name, location_ids, products,
grouping=('product', 'lot'))
@classmethod
def search_quantity(cls, name, domain=None):
location_ids = Transaction().context.get('locations')
return cls._search_quantity(name, location_ids, domain,
grouping=('product', 'lot'))
class LotType(ModelSQL, ModelView):
+3
View File
@@ -141,6 +141,9 @@ class StockLotTestCase(unittest.TestCase):
(storage.id, product.id, lot2.id): 8,
(storage.id, product.id, None): 3,
})
with Transaction().set_context(locations=[storage.id]):
self.assertEqual(lot1.quantity, 5)
self.assertEqual(lot2.quantity, 8)
def test0020period(self):
'''