#9 feat(Tryton): untouched products on sync from tryton.
This commit is contained in:
		| @@ -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'): | ||||
|   | ||||
| @@ -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')) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user