fix: catalog sale lines not being created due to wrong field name and missing read_only config

- Changed test payload from 'saleline_set' to 'catalogsaleline_set'
- Removed extraneous fields 'payment_method' and 'catalog_sale' from test data
- Made 'catalog_sale' read_only in CatalogSaleLineSerializer to allow nested creation
This commit is contained in:
2026-05-28 18:56:40 -05:00
parent e658901165
commit dde6f7329f
2 changed files with 7 additions and 15 deletions

View File

@@ -17,9 +17,7 @@ class TestAPI(APITestCase, LoginMixin):
self.product = Product.objects.create(
name="Panela", price=5000, measuring_unit="UNIT"
)
self.customer = Customer.objects.create(
name="Camilo", external_id="18"
)
self.customer = Customer.objects.create(name="Camilo", external_id="18")
def test_create_sale(self):
response = self._create_sale()
@@ -42,6 +40,7 @@ class TestAPI(APITestCase, LoginMixin):
sale = CatalogSale.objects.all()[0]
self.assertEqual(sale.customer.name, self.customer.name)
self.assertEqual(sale.id, content["id"])
self.assertEqual(sale.catalogsaleline_set.count(), 2)
def test_create_sale_with_decimal(self):
response = self._create_sale_with_decimal()
@@ -66,9 +65,7 @@ class TestAPI(APITestCase, LoginMixin):
json_response = json.loads(response.content.decode("utf-8"))
self.assertEqual(response.status_code, 200)
self.assertEqual(self.customer.name, json_response[0]["name"])
self.assertEqual(
self.customer.external_id, json_response[0]["external_id"]
)
self.assertEqual(self.customer.external_id, json_response[0]["external_id"])
def test_get_sales(self):
url = "/don_confiao/api/sales/"
@@ -190,8 +187,7 @@ class TestAPI(APITestCase, LoginMixin):
data = {
"customer": self.customer.id,
"date": "2024-09-02",
"payment_method": "CASH",
"saleline_set": [
"catalogsaleline_set": [
{
"product": self.product.id,
"quantity": 2,
@@ -203,7 +199,6 @@ class TestAPI(APITestCase, LoginMixin):
"unit_price": 5000,
},
],
"catalog_sale": True,
}
return self.client.post(url, data, format="json")