diff --git a/modules/stock_lot/setup.py b/modules/stock_lot/setup.py index 654f6f9c10..583af7850a 100755 --- a/modules/stock_lot/setup.py +++ b/modules/stock_lot/setup.py @@ -47,7 +47,10 @@ for dep in info.get('depends', []): requires.append(get_require_version('trytond_%s' % dep)) requires.append(get_require_version('trytond')) -tests_require = [get_require_version('proteus')] +tests_require = [ + get_require_version('proteus'), + get_require_version('trytond_stock_split'), + ] setup(name=name, version=version, diff --git a/modules/stock_lot/stock.py b/modules/stock_lot/stock.py index 2de1cb7c37..0398014bb7 100644 --- a/modules/stock_lot/stock.py +++ b/modules/stock_lot/stock.py @@ -541,20 +541,32 @@ class MoveAddLots(Wizard): lot = line.get_lot(self.record) lots.append(lot) Lot.save(lots) - if quantity_remaining: - self.record.quantity = quantity_remaining - self.record.save() - for i, (line, lot) in enumerate(zip(self.start.lots, lots)): - if not i and not quantity_remaining: - self.record.quantity = line.quantity - self.record.lot = lot + if hasattr(self.model, 'split'): + move = self.record + for line, lot in zip(self.start.lots, lots): + splits = move.split(line.quantity, self.record.unit, count=1) + splits.remove(move) + move.lot = lot + move.save() + if splits: + move, = splits + else: + break + else: + if quantity_remaining: + self.record.quantity = quantity_remaining self.record.save() - else: - with Transaction().set_context(_stock_move_split=True): - self.model.copy([self.record], { - 'quantity': line.quantity, - 'lot': lot.id, - }) + for i, (line, lot) in enumerate(zip(self.start.lots, lots)): + if not i and not quantity_remaining: + self.record.quantity = line.quantity + self.record.lot = lot + self.record.save() + else: + with Transaction().set_context(_stock_move_split=True): + self.model.copy([self.record], { + 'quantity': line.quantity, + 'lot': lot.id, + }) return 'end' diff --git a/modules/stock_lot/tests/scenario_stock_lot_move_add.json b/modules/stock_lot/tests/scenario_stock_lot_move_add.json new file mode 100644 index 0000000000..fd03b4616c --- /dev/null +++ b/modules/stock_lot/tests/scenario_stock_lot_move_add.json @@ -0,0 +1,4 @@ +[ + {"stock_split": false} + ,{"stock_split": true} +] diff --git a/modules/stock_lot/tests/scenario_stock_lot_move_add.rst b/modules/stock_lot/tests/scenario_stock_lot_move_add.rst index 6c6fb0c2ed..be5741687d 100644 --- a/modules/stock_lot/tests/scenario_stock_lot_move_add.rst +++ b/modules/stock_lot/tests/scenario_stock_lot_move_add.rst @@ -12,7 +12,10 @@ Imports:: Activate modules:: - >>> config = activate_modules('stock_lot') + >>> modules = ['stock_lot'] + >>> if globals().get('stock_split', False): + ... modules.append('stock_split') + >>> config = activate_modules(modules) Create company:: diff --git a/modules/stock_lot/tests/test_module.py b/modules/stock_lot/tests/test_module.py index 0f5e93b360..2f35628bcb 100644 --- a/modules/stock_lot/tests/test_module.py +++ b/modules/stock_lot/tests/test_module.py @@ -14,6 +14,7 @@ from trytond.transaction import Transaction class StockLotTestCase(CompanyTestMixin, ModuleTestCase): 'Test Stock Lot module' module = 'stock_lot' + extras = ['stock_split'] @with_transaction() def test_products_by_location(self): diff --git a/modules/stock_lot/tryton.cfg b/modules/stock_lot/tryton.cfg index b00ed820a4..25f5f3888d 100644 --- a/modules/stock_lot/tryton.cfg +++ b/modules/stock_lot/tryton.cfg @@ -6,6 +6,7 @@ depends: stock extras_depend: sale_supply_drop_shipment + stock_split xml: ir.xml stock.xml