changeset 74e127f01040 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=74e127f01040
description:
        Add test on assign_try with unsaved move

        We allow to pass unsaved move as parameters for the assignation search 
while
        keeping the original values on the possible remaining moves.

        issue9431
        review300001002
diffstat:

 tests/test_stock.py |  70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)

diffs (80 lines):

diff -r 86faddd12795 -r 74e127f01040 tests/test_stock.py
--- a/tests/test_stock.py       Thu Jul 09 10:21:07 2020 +0100
+++ b/tests/test_stock.py       Mon Jul 13 21:07:27 2020 +0200
@@ -1219,6 +1219,76 @@
         self.assertTrue(Move.assign_try([]))
 
     @with_transaction()
+    def test_assign_try_modified_move(self):
+        "Test Move assign_try with modified move"
+        pool = Pool()
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Uom = pool.get('product.uom')
+        Location = pool.get('stock.location')
+        Move = pool.get('stock.move')
+
+        uom, = Uom.search([('name', '=', 'Meter')])
+        template = Template(
+            name='Test Move.assign_try',
+            type='goods',
+            list_price=Decimal(1),
+            default_uom=uom,
+            )
+        template.save()
+        product = Product(template=template.id)
+        product.save()
+
+        supplier, = Location.search([('code', '=', 'SUP')])
+        storage, = Location.search([('code', '=', 'STO')])
+        storage2, = Location.copy([storage])
+        customer, = Location.search([('code', '=', 'CUS')])
+
+        company = create_company()
+        with set_company(company):
+            move, = Move.create([{
+                        'product': product.id,
+                        'uom': uom.id,
+                        'quantity': 1,
+                        'from_location': supplier.id,
+                        'to_location': storage.id,
+                        'company': company.id,
+                        'unit_price': Decimal(1),
+                        'currency': company.currency.id,
+                        }])
+            Move.do([move])
+
+            move, = Move.create([{
+                        'product': product.id,
+                        'uom': uom.id,
+                        'quantity': 2,
+                        'from_location': storage2.id,
+                        'to_location': customer.id,
+                        'company': company.id,
+                        'unit_price': Decimal(1),
+                        'currency': company.currency.id,
+                        }])
+
+            # Assign from a different location
+            move.from_location = storage
+            self.assertFalse(Move.assign_try([move]))
+
+            move, = Move.search([
+                    ('to_location', '=', customer.id),
+                    ('state', '=', 'assigned'),
+                    ])
+            self.assertEqual(move.from_location, storage)
+            self.assertEqual(move.quantity, 1)
+
+            move, = Move.search([
+                    ('to_location', '=', customer.id),
+                    ('state', '=', 'draft'),
+                    ])
+            # Remaining move has the original location
+            self.assertEqual(move.from_location, storage2)
+            self.assertEqual(move.quantity, 1)
+
+    @with_transaction()
     def test_products_by_location_assign(self):
         "Test products by location for assignation"
         pool = Pool()

Reply via email to