FIX not change lot required in case the move has not lot in other company

#037201
This commit is contained in:
Raimon Esteve 2019-03-19 11:20:13 +01:00
parent 61fabb459c
commit 3bbb69770f
1 changed files with 42 additions and 19 deletions

View File

@ -1,19 +1,22 @@
diff -r 04443e7121ac product.py
diff -r 04443e7121ac trytond/trytond/modules/stock_lot/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 @@
+++ b/trytond/trytond/modules/stock_lot/product.py Thu Mar 14 12:43:27 2019 +0100
@@ -1,8 +1,10 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
+from sql import Null
+from trytond.transaction import Transaction
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 @@
@@ -20,6 +22,56 @@
},
depends=['type'])
+ @classmethod
+ def __setup__(cls):
+ super(Template, cls).__setup__()
@ -24,19 +27,39 @@ diff -r 04443e7121ac product.py
+ def check_moves_without_lot(self):
+ "Check if there are moves without lot"
+ pool = Pool()
+ StockMove = pool.get('stock.move')
+ Move = pool.get('stock.move')
+ Product = pool.get('product.product')
+ Template = pool.get('product.template')
+ Location = pool.get('stock.location')
+
+ move = Move.__table__()
+ product = Product.__table__()
+ template = Template.__table__()
+ location = Location.__table__()
+ location2 = Location.__table__()
+ 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)
+ if not lot_required_ubications:
+ return
+
+ cursor = Transaction().cursor
+
+ sql_where = ((move.lot == Null) & (template.id == self.id))
+ query = move.join(
+ product, condition=product.id == move.product).join(
+ template, condition=template.id == product.template).join(
+ location, condition=location.id == move.from_location).join(
+ location2, condition=location2.id == move.to_location).select(
+ location.type, location2.type, where=sql_where)
+
+ cursor.execute(*query)
+ for type1, type2 in cursor.fetchall():
+ move_without_lot = None
+ if (type1 in lot_required_ubications):
+ move_without_lot = type1
+ if (type2 in lot_required_ubications):
+ move_without_lot = type2
+ if move_without_lot:
+ self.raise_user_error('move_without_lot', move_without_lot)
+
+ @classmethod
+ def validate(cls, templates):
@ -44,6 +67,6 @@ diff -r 04443e7121ac product.py
+ for template in templates:
+ template.check_moves_without_lot()
+
class Product:
__name__ = 'product.product'