From d1e137d387bd0a447e56f9e3ce62b3480567332b Mon Sep 17 00:00:00 2001 From: Mono Mono Date: Sun, 27 Jul 2025 23:22:58 -0500 Subject: [PATCH] #9 feat(Tryton): untouched products on sync from tryton. --- tienda_ilusion/don_confiao/api_views.py | 2 +- .../tests/test_products_from_tryton.py | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tienda_ilusion/don_confiao/api_views.py b/tienda_ilusion/don_confiao/api_views.py index 54f4295..3de6f63 100644 --- a/tienda_ilusion/don_confiao/api_views.py +++ b/tienda_ilusion/don_confiao/api_views.py @@ -310,7 +310,7 @@ class ProductsFromTrytonView(APIView): def __need_update(self, product, tryton_product): if not product.name == tryton_product.get('name'): return True - if not product.price == tryton_product.get('price'): + if not product.price == tryton_product.get('list_price'): return True unit = tryton_product.get('default_uom.') if not product.measuring_unit == unit.get('rec_name'): diff --git a/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py b/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py index 518bfbf..37f8419 100644 --- a/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_products_from_tryton.py @@ -17,6 +17,15 @@ class TestProductsFromTryton(TestCase): ) self.product.save() + self.product2 = Product.objects.create( + name='Papa', + price=4500, + measuring_unit='Kilogram', + unit_external_id=2, + external_id=192 + ) + self.product2.save() + @patch('sabatron_tryton_rpc_client.client.Client.call') @patch('sabatron_tryton_rpc_client.client.Client.connect') def test_create_import_products(self, mock_connect, mock_call): @@ -26,10 +35,10 @@ class TestProductsFromTryton(TestCase): product_search = 'model.product.product.search' search_args = [[], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}] if (args == (product_search, search_args)): - return [190, 191] + return [190, 191, 192] product_read = 'model.product.product.read' - product_args = ([190, 191], + product_args = ([190, 191, 192], ['id', 'name', 'default_uom.id', 'default_uom.rec_name', 'list_price'], {'company': 1} @@ -42,6 +51,9 @@ class TestProductsFromTryton(TestCase): {'id': 191, 'list_price': Decimal('6000'), 'name': 'Panela2', 'default_uom.': {'id': 1, 'rec_name': 'Unit'}}, + {'id': 192, 'list_price': Decimal('4500'), + 'name': 'Papa', + 'default_uom.': {'id': 2, 'rec_name': 'Kilogram'}}, ] raise Exception(f"Sorry, args non expected on this test: {args}") @@ -54,15 +66,15 @@ class TestProductsFromTryton(TestCase): content = json.loads(response.content.decode('utf-8')) expected_response = { - 'checked_tryton_products': [190, 191], - 'created_products': [2], - 'untouched_products': [], + 'checked_tryton_products': [190, 191, 192], + 'created_products': [3], + 'untouched_products': [2], 'failed_products': [], 'updated_products': [1] } self.assertEqual(content, expected_response) - created_product = Product.objects.get(id=2) + created_product = Product.objects.get(id=3) self.assertEqual(created_product.external_id, str(190)) self.assertEqual(created_product.name, 'Producto 1') self.assertEqual(created_product.price, Decimal('25000'))