Task 033887

This commit is contained in:
Sim? Albert i Beltran 2018-03-14 10:50:58 +01:00
parent 666fd5a7a5
commit 931ad2dc50
2 changed files with 50 additions and 0 deletions

1
series
View File

@ -134,3 +134,4 @@ issue6371.diff # stock Do not set effective date on assignation
filestore.diff
issue33209.diff # [account_invoice] Forbid to create credit notes from nonposted invoices
stock_lot_check_moves_without_lot_before_lot_required.diff

View File

@ -0,0 +1,49 @@
diff -r 04443e7121ac product.py
--- a/trytond/trytond/modules/stock_lot/product.py Sat Jun 10 01:36:54 2017 +0200
+++ b/trytond/trytond/modules/stock_lot/product.py Wed Mar 14 08:54:48 2018 +0100
@@ -2,7 +2,7 @@
#this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.pyson import Eval
-from trytond.pool import PoolMeta
+from trytond.pool import Pool, PoolMeta
__all__ = ['Template', 'Product', 'TemplateLotType']
__metaclass__ = PoolMeta
@@ -20,6 +20,36 @@
},
depends=['type'])
+ @classmethod
+ def __setup__(cls):
+ super(Template, cls).__setup__()
+ cls._error_messages.update({
+ 'move_without_lot': 'There is a move without lot: "%s"',
+ })
+
+ def check_moves_without_lot(self):
+ "Check if there are moves without lot"
+ pool = Pool()
+ StockMove = pool.get('stock.move')
+ lot_required_ubications = [t.code for t in self.lot_required]
+ stock_moves = StockMove.search([
+ ('product.template', '=', self),
+ ('lot', '=', None),
+ ('state', '=', 'done'),
+ ])
+ for stock_move in stock_moves:
+ for location in ['from_location', 'to_location']:
+ location_type = getattr(stock_move, location).type
+ if location_type in lot_required_ubications:
+ self.raise_user_error('move_without_lot',
+ stock_move.rec_name)
+
+ @classmethod
+ def validate(cls, templates):
+ super(Template, cls).validate(templates)
+ for template in templates:
+ template.check_moves_without_lot()
+
class Product:
__name__ = 'product.product'