#9 feat(Tryton): untouched products on sync from tryton.
This commit is contained in:
parent
c33c6f630a
commit
d1e137d387
@ -310,7 +310,7 @@ class ProductsFromTrytonView(APIView):
|
|||||||
def __need_update(self, product, tryton_product):
|
def __need_update(self, product, tryton_product):
|
||||||
if not product.name == tryton_product.get('name'):
|
if not product.name == tryton_product.get('name'):
|
||||||
return True
|
return True
|
||||||
if not product.price == tryton_product.get('price'):
|
if not product.price == tryton_product.get('list_price'):
|
||||||
return True
|
return True
|
||||||
unit = tryton_product.get('default_uom.')
|
unit = tryton_product.get('default_uom.')
|
||||||
if not product.measuring_unit == unit.get('rec_name'):
|
if not product.measuring_unit == unit.get('rec_name'):
|
||||||
|
@ -17,6 +17,15 @@ class TestProductsFromTryton(TestCase):
|
|||||||
)
|
)
|
||||||
self.product.save()
|
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.call')
|
||||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||||
def test_create_import_products(self, mock_connect, mock_call):
|
def test_create_import_products(self, mock_connect, mock_call):
|
||||||
@ -26,10 +35,10 @@ class TestProductsFromTryton(TestCase):
|
|||||||
product_search = 'model.product.product.search'
|
product_search = 'model.product.product.search'
|
||||||
search_args = [[], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}]
|
search_args = [[], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}]
|
||||||
if (args == (product_search, search_args)):
|
if (args == (product_search, search_args)):
|
||||||
return [190, 191]
|
return [190, 191, 192]
|
||||||
|
|
||||||
product_read = 'model.product.product.read'
|
product_read = 'model.product.product.read'
|
||||||
product_args = ([190, 191],
|
product_args = ([190, 191, 192],
|
||||||
['id', 'name', 'default_uom.id',
|
['id', 'name', 'default_uom.id',
|
||||||
'default_uom.rec_name', 'list_price'],
|
'default_uom.rec_name', 'list_price'],
|
||||||
{'company': 1}
|
{'company': 1}
|
||||||
@ -42,6 +51,9 @@ class TestProductsFromTryton(TestCase):
|
|||||||
{'id': 191, 'list_price': Decimal('6000'),
|
{'id': 191, 'list_price': Decimal('6000'),
|
||||||
'name': 'Panela2',
|
'name': 'Panela2',
|
||||||
'default_uom.': {'id': 1, 'rec_name': 'Unit'}},
|
'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}")
|
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'))
|
content = json.loads(response.content.decode('utf-8'))
|
||||||
expected_response = {
|
expected_response = {
|
||||||
'checked_tryton_products': [190, 191],
|
'checked_tryton_products': [190, 191, 192],
|
||||||
'created_products': [2],
|
'created_products': [3],
|
||||||
'untouched_products': [],
|
'untouched_products': [2],
|
||||||
'failed_products': [],
|
'failed_products': [],
|
||||||
'updated_products': [1]
|
'updated_products': [1]
|
||||||
}
|
}
|
||||||
self.assertEqual(content, expected_response)
|
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.external_id, str(190))
|
||||||
self.assertEqual(created_product.name, 'Producto 1')
|
self.assertEqual(created_product.name, 'Producto 1')
|
||||||
self.assertEqual(created_product.price, Decimal('25000'))
|
self.assertEqual(created_product.price, Decimal('25000'))
|
||||||
|
Loading…
Reference in New Issue
Block a user