Merge branch 'handle_duplicate_product_name_from_tryton_#11'
This commit is contained in:
commit
7ac28154eb
4
.env_example
Normal file
4
.env_example
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
TRYTON_HOST=localhost
|
||||||
|
TRYTON_DATABASE=tryton
|
||||||
|
TRYTON_USERNAME=admin
|
||||||
|
TRYTON_PASSWORD=admin
|
@ -279,9 +279,16 @@ class ProductsFromTrytonView(APIView):
|
|||||||
external_id=tryton_product.get('id')
|
external_id=tryton_product.get('id')
|
||||||
)
|
)
|
||||||
except Product.DoesNotExist:
|
except Product.DoesNotExist:
|
||||||
product = self.__create_product(tryton_product)
|
try:
|
||||||
created_products.append(product.id)
|
product = self.__create_product(tryton_product)
|
||||||
continue
|
created_products.append(product.id)
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error al importar productos: {e}"
|
||||||
|
f"El producto: {tryton_product}")
|
||||||
|
failed_products.append(tryton_product.get('id'))
|
||||||
|
continue
|
||||||
|
|
||||||
if self.__need_update(product, tryton_product):
|
if self.__need_update(product, tryton_product):
|
||||||
self.__update_product(product, tryton_product)
|
self.__update_product(product, tryton_product)
|
||||||
updated_products.append(product.id)
|
updated_products.append(product.id)
|
||||||
@ -358,8 +365,6 @@ class CustomersFromTrytonView(APIView):
|
|||||||
updated_customers = []
|
updated_customers = []
|
||||||
created_customers = []
|
created_customers = []
|
||||||
untouched_customers = []
|
untouched_customers = []
|
||||||
print('aqui')
|
|
||||||
print(tryton_parties)
|
|
||||||
|
|
||||||
for tryton_party in tryton_parties:
|
for tryton_party in tryton_parties:
|
||||||
try:
|
try:
|
||||||
|
@ -85,3 +85,44 @@ class TestProductsFromTryton(TestCase):
|
|||||||
self.assertEqual(updated_product.name, 'Panela2')
|
self.assertEqual(updated_product.name, 'Panela2')
|
||||||
self.assertEqual(updated_product.price, Decimal('6000'))
|
self.assertEqual(updated_product.price, Decimal('6000'))
|
||||||
self.assertEqual(updated_product.measuring_unit, 'Unit')
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user