feat(Tryton): handle duplicate named products from tryton.
This commit is contained in:
@@ -85,3 +85,44 @@ class TestProductsFromTryton(TestCase):
|
||||
self.assertEqual(updated_product.name, 'Panela2')
|
||||
self.assertEqual(updated_product.price, Decimal('6000'))
|
||||
self.assertEqual(updated_product.measuring_unit, 'Unit')
|
||||
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.call')
|
||||
@patch('sabatron_tryton_rpc_client.client.Client.connect')
|
||||
def test_import_duplicated_name_products(self, mock_connect, mock_call):
|
||||
mock_connect.return_value = None
|
||||
def fake_call(*args, **kwargs):
|
||||
product_search = 'model.product.product.search'
|
||||
search_args = [[["salable", "=", True]], 0, 1000, [['rec_name', 'ASC'], ['id', None]], {'company': 1}]
|
||||
if (args == (product_search, search_args)):
|
||||
return [200]
|
||||
|
||||
product_read = 'model.product.product.read'
|
||||
product_args = ([200],
|
||||
['id', 'name', 'default_uom.id',
|
||||
'default_uom.rec_name', 'list_price'],
|
||||
{'company': 1}
|
||||
)
|
||||
if (args == (product_read, product_args)):
|
||||
return [
|
||||
{'id': 200, 'list_price': Decimal('25000'),
|
||||
'name': self.product.name,
|
||||
'default_uom.': {'id': 1, 'rec_name': 'Unit'}},
|
||||
]
|
||||
|
||||
raise Exception(f"Sorry, args non expected on this test: {args}")
|
||||
|
||||
mock_call.side_effect = fake_call
|
||||
|
||||
url = '/don_confiao/api/importar_productos_de_tryton'
|
||||
response = self.client.post(url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
content = json.loads(response.content.decode('utf-8'))
|
||||
expected_response = {
|
||||
'checked_tryton_products': [200],
|
||||
'created_products': [],
|
||||
'untouched_products': [],
|
||||
'failed_products': [200],
|
||||
'updated_products': [],
|
||||
}
|
||||
self.assertEqual(content, expected_response)
|
||||
|
||||
Reference in New Issue
Block a user