2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 13:35:40 +00:00

Int migration fix (#3323)

* Add fix for stock migration

- Ensure the serial number is not too large when performing migration
- Add unit test for data migration

(cherry picked from commit 661fbf0e3d)

* Add similar fixes for PO and SO migrations

(cherry picked from commit bde23c130c)

* And similar fix for BuildOrder reference field

(cherry picked from commit ca0f4e0031)

* Update unit tests for API plugin mixin class

- API at previous target URL has changed
- Simplier to use the github API as a test case

(cherry picked from commit dfe3172b7d)

* Revert test database name

(cherry picked from commit 53333c29c3)

* Override default URL behaviour for unit test

(cherry picked from commit 2c12a69529)
This commit is contained in:
Oliver
2022-07-15 11:57:27 +10:00
committed by GitHub
parent 2635327c51
commit 2afd39356a
5 changed files with 106 additions and 0 deletions

View File

@ -23,6 +23,10 @@ def build_refs(apps, schema_editor):
except Exception: # pragma: no cover
ref = 0
# Clip integer value to ensure it does not overflow database field
if ref > 0x7fffffff:
ref = 0x7fffffff
order.reference_int = ref
order.save()
@ -40,6 +44,10 @@ def build_refs(apps, schema_editor):
except Exception: # pragma: no cover
ref = 0
# Clip integer value to ensure it does not overflow database field
if ref > 0x7fffffff:
ref = 0x7fffffff
order.reference_int = ref
order.save()

View File

@ -49,6 +49,19 @@ class TestRefIntMigrations(MigratorTestCase):
with self.assertRaises(AttributeError):
print(sales_order.reference_int)
# Create orders with very large reference values
self.po_pk = PurchaseOrder.objects.create(
supplier=supplier,
reference='999999999999999999999999999999999',
description='Big reference field',
).pk
self.so_pk = SalesOrder.objects.create(
customer=supplier,
reference='999999999999999999999999999999999',
description='Big reference field',
).pk
def test_ref_field(self):
"""Test that the 'reference_int' field has been created and is filled out correctly."""
PurchaseOrder = self.new_state.apps.get_model('order', 'purchaseorder')
@ -63,6 +76,15 @@ class TestRefIntMigrations(MigratorTestCase):
self.assertEqual(po.reference_int, ii)
self.assertEqual(so.reference_int, ii)
# Tests for orders with overly large reference values
po = PurchaseOrder.objects.get(pk=self.po_pk)
self.assertEqual(po.reference, '999999999999999999999999999999999')
self.assertEqual(po.reference_int, 0x7fffffff)
so = SalesOrder.objects.get(pk=self.so_pk)
self.assertEqual(so.reference, '999999999999999999999999999999999')
self.assertEqual(so.reference_int, 0x7fffffff)
class TestShipmentMigration(MigratorTestCase):
"""Test data migration for the "SalesOrderShipment" model."""