1
0
forked from erp-dev/erp

feat: big

This commit is contained in:
2026-07-01 11:51:13 +08:00
parent 7c9b77afb0
commit 5170700234
28 changed files with 933 additions and 37 deletions

View File

@@ -206,6 +206,32 @@ class CostAPITest(TestCase):
self.assertEqual(resp.data['category_name'], '电费')
self.assertEqual(resp.data['operator_id'], self.employee.id)
def test_create_formula_entry(self):
cat = self._create_category('temp_worker', '临时工工资')
resp = self.client.post('/api/v2/cost-entries/', {
'category_id': cat.id,
'unit_amount': '200.00',
'quantity': '3',
'unit_name': '人天',
'occurred_at': '2026-06-01',
'remarks': '临时工 3 人天',
}, format='json')
self.assertEqual(resp.status_code, 201)
self.assertEqual(resp.data['amount'], '600.00')
self.assertEqual(resp.data['unit_amount'], '200.0000')
self.assertEqual(resp.data['quantity'], '3.0000')
self.assertEqual(resp.data['unit_name'], '人天')
def test_create_formula_entry_partial_fields_returns_400(self):
cat = self._create_category('temp_worker', '临时工工资')
resp = self.client.post('/api/v2/cost-entries/', {
'category_id': cat.id,
'unit_amount': '200.00',
'occurred_at': '2026-06-01',
}, format='json')
self.assertEqual(resp.status_code, 400)
def test_create_entry_category_not_found(self):
resp = self.client.post('/api/v2/cost-entries/', {
'category_id': 99999,
@@ -275,6 +301,41 @@ class CostAPITest(TestCase):
self.assertEqual(resp.data['amount'], '999.00')
self.assertEqual(resp.data['remarks'], '已修改')
def test_update_formula_entry_recalculates_amount(self):
cat = self._create_category('temp_worker', '临时工工资')
entry = cost_models.CostEntry.objects.create(
merchant=self.merchant, category=cat,
amount=None, unit_amount=Decimal('200.00'), quantity=Decimal('3'),
unit_name='人天', occurred_at=date(2026, 6, 1),
)
resp = self.client.put(f'/api/v2/cost-entries/{entry.id}/', {
'quantity': '4',
}, format='json')
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data['amount'], '800.00')
self.assertEqual(resp.data['quantity'], '4.0000')
entry.refresh_from_db()
self.assertEqual(entry.amount, Decimal('800.00'))
def test_update_formula_entry_to_manual_amount(self):
cat = self._create_category('temp_worker', '临时工工资')
entry = cost_models.CostEntry.objects.create(
merchant=self.merchant, category=cat,
amount=None, unit_amount=Decimal('200.00'), quantity=Decimal('3'),
unit_name='人天', occurred_at=date(2026, 6, 1),
)
resp = self.client.put(f'/api/v2/cost-entries/{entry.id}/', {
'amount': '550.00',
'unit_amount': None,
'quantity': None,
'unit_name': '',
}, format='json')
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data['amount'], '550.00')
self.assertIsNone(resp.data['unit_amount'])
self.assertIsNone(resp.data['quantity'])
def test_update_entry_change_category(self):
cat1 = self._create_category('elec', '电费')
cat2 = self._create_category('water', '水费')