forked from erp-dev/erp
feat: big
This commit is contained in:
@@ -142,4 +142,54 @@ class CostEntryModelTests(TestCase):
|
||||
occurred_at=date(2026, 6, 1),
|
||||
)
|
||||
self.assertFalse(bool(entry.image1))
|
||||
self.assertFalse(bool(entry.image2))
|
||||
self.assertFalse(bool(entry.image2))
|
||||
|
||||
def test_formula_amount_calculated_on_create(self):
|
||||
entry = cost_models.CostEntry.objects.create(
|
||||
merchant=self.merchant,
|
||||
category=self.category,
|
||||
amount=None,
|
||||
unit_amount=Decimal('120.00'),
|
||||
quantity=Decimal('2.5'),
|
||||
unit_name='人天',
|
||||
occurred_at=date(2026, 6, 1),
|
||||
)
|
||||
self.assertEqual(entry.amount, Decimal('300.00'))
|
||||
self.assertEqual(entry.unit_name, '人天')
|
||||
|
||||
def test_formula_amount_recalculated_on_update(self):
|
||||
entry = cost_models.CostEntry.objects.create(
|
||||
merchant=self.merchant,
|
||||
category=self.category,
|
||||
amount=Decimal('300.00'),
|
||||
unit_amount=Decimal('100.00'),
|
||||
quantity=Decimal('3'),
|
||||
occurred_at=date(2026, 6, 1),
|
||||
)
|
||||
entry.quantity = Decimal('4')
|
||||
entry.amount = Decimal('999.00')
|
||||
entry.save()
|
||||
entry.refresh_from_db()
|
||||
self.assertEqual(entry.amount, Decimal('400.00'))
|
||||
|
||||
def test_formula_partial_fields_raise_validation_error(self):
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
cost_models.CostEntry.objects.create(
|
||||
merchant=self.merchant,
|
||||
category=self.category,
|
||||
amount=None,
|
||||
unit_amount=Decimal('100.00'),
|
||||
quantity=None,
|
||||
occurred_at=date(2026, 6, 1),
|
||||
)
|
||||
self.assertIn('quantity', ctx.exception.message_dict)
|
||||
|
||||
def test_manual_amount_required_without_formula(self):
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
cost_models.CostEntry.objects.create(
|
||||
merchant=self.merchant,
|
||||
category=self.category,
|
||||
amount=None,
|
||||
occurred_at=date(2026, 6, 1),
|
||||
)
|
||||
self.assertIn('amount', ctx.exception.message_dict)
|
||||
|
||||
Reference in New Issue
Block a user