From 937fe06de43a7a09f8e8153a91fd7a0b9bf6f856 Mon Sep 17 00:00:00 2001 From: Mono Mono Date: Sat, 16 Aug 2025 16:09:20 -0500 Subject: [PATCH 1/2] #14 feat(Tryton): add address on update customers from tryton. --- tienda_ilusion/don_confiao/api_views.py | 7 ++++++- .../don_confiao/tests/test_customers_from_tryton.py | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tienda_ilusion/don_confiao/api_views.py b/tienda_ilusion/don_confiao/api_views.py index 616865d..d70c9f1 100644 --- a/tienda_ilusion/don_confiao/api_views.py +++ b/tienda_ilusion/don_confiao/api_views.py @@ -397,7 +397,7 @@ class CustomersFromTrytonView(APIView): ) def __get_party_datails(self, party_ids, tryton_client, context): - tryton_fields = ['id', 'name'] + tryton_fields = ['id', 'name', 'addresses'] method = 'model.party.party.read' params = (party_ids, tryton_fields, context) response = tryton_client.call(method, params) @@ -406,11 +406,16 @@ class CustomersFromTrytonView(APIView): def __need_update(self, customer, tryton_party): if not customer.name == tryton_party.get('name'): return True + if tryton_party.get('addresses') and tryton_party.get('addresses')[0]: + if not customer.address_external_id == str(tryton_party.get('addresses')[0]): + return True def __create_customer(self, tryton_party): customer = Customer() customer.name = tryton_party.get('name') customer.external_id = tryton_party.get('id') + if tryton_party.get('addresses') and tryton_party.get('addresses')[0]: + customer.address_external_id = tryton_party.get('addresses')[0] customer.save() return customer diff --git a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py index ce0e785..47b68a6 100644 --- a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py @@ -30,13 +30,13 @@ class TestCustomersFromTryton(TestCase): return [5, 6, 7, 8] party_read = 'model.party.party.read' - read_args = ([5, 6, 7, 8], ['id', 'name'], {'company': 1}) + read_args = ([5, 6, 7, 8], ['id', 'name', 'addresses'], {'company': 1}) if (args == (party_read, read_args)): return [ - {'id': 5, 'name': 'Carlos'}, - {'id': 6, 'name': 'Cristian'}, - {'id': 7, 'name': 'Ana'}, - {'id': 8, 'name': 'José'}, + {'id': 5, 'name': 'Carlos', 'addresses': []}, + {'id': 6, 'name': 'Cristian', 'addresses': []}, + {'id': 7, 'name': 'Ana', 'addresses': [302]}, + {'id': 8, 'name': 'José', 'addresses': []}, ] raise Exception(f"Sorry, args non expected on this test: {args}") @@ -60,7 +60,9 @@ class TestCustomersFromTryton(TestCase): created_customer = Customer.objects.get(id=3) self.assertEqual(created_customer.external_id, str(7)) self.assertEqual(created_customer.name, 'Ana') + self.assertEqual(created_customer.address_external_id, str(302)) updated_customer = Customer.objects.get(id=1) self.assertEqual(updated_customer.external_id, str(5)) self.assertEqual(updated_customer.name, 'Carlos') + self.assertIn(updated_customer.address_external_id, ['', None]) -- 2.45.2 From 4dae6693978ba3156d22ec34e859c6816111abab Mon Sep 17 00:00:00 2001 From: Mono Mono Date: Sat, 16 Aug 2025 16:36:06 -0500 Subject: [PATCH 2/2] #14 fix(Tryton): add address on updated customers from tryton. --- tienda_ilusion/don_confiao/api_views.py | 2 ++ .../don_confiao/tests/test_customers_from_tryton.py | 4 ++-- .../don_confiao/tests/test_exportar_ventas_para_tryton.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tienda_ilusion/don_confiao/api_views.py b/tienda_ilusion/don_confiao/api_views.py index d70c9f1..bfeddb6 100644 --- a/tienda_ilusion/don_confiao/api_views.py +++ b/tienda_ilusion/don_confiao/api_views.py @@ -422,4 +422,6 @@ class CustomersFromTrytonView(APIView): def __update_customer(self, customer, tryton_party): customer.name = tryton_party.get('name') customer.external_id = tryton_party.get('id') + if tryton_party.get('addresses') and tryton_party.get('addresses')[0]: + customer.address_external_id = tryton_party.get('addresses')[0] customer.save() diff --git a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py index 47b68a6..3924f4d 100644 --- a/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_customers_from_tryton.py @@ -33,7 +33,7 @@ class TestCustomersFromTryton(TestCase): read_args = ([5, 6, 7, 8], ['id', 'name', 'addresses'], {'company': 1}) if (args == (party_read, read_args)): return [ - {'id': 5, 'name': 'Carlos', 'addresses': []}, + {'id': 5, 'name': 'Carlos', 'addresses': [303]}, {'id': 6, 'name': 'Cristian', 'addresses': []}, {'id': 7, 'name': 'Ana', 'addresses': [302]}, {'id': 8, 'name': 'José', 'addresses': []}, @@ -65,4 +65,4 @@ class TestCustomersFromTryton(TestCase): updated_customer = Customer.objects.get(id=1) self.assertEqual(updated_customer.external_id, str(5)) self.assertEqual(updated_customer.name, 'Carlos') - self.assertIn(updated_customer.address_external_id, ['', None]) + self.assertIn(updated_customer.address_external_id, str(303)) diff --git a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py index a5efa8d..78c13c2 100644 --- a/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py +++ b/tienda_ilusion/don_confiao/tests/test_exportar_ventas_para_tryton.py @@ -19,7 +19,7 @@ class TestExportarVentasParaTryton(TestCase): self.customer = Customer.objects.create( name='Camilo', external_id=1, - address_external_id=1 + address_external_id=307, ) self.sale = Sale.objects.create( customer=self.customer, @@ -100,4 +100,4 @@ class TestExportarVentasParaTryton(TestCase): self.assertEqual(updated_sale.external_id, external_id) mock_connect.assert_called_once() mock_call.assert_called_once() - mock_call.assert_called_with('model.sale.sale.create', [[{'company': 1, 'shipment_address': '1', 'invoice_address': '1', 'currency': 31, 'description': '', 'party': '1', 'reference': 'don_confiao 1', 'sale_date': {'__class__': 'date', 'year': 2024, 'month': 9, 'day': 2}, 'lines': [['create', [{'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '2.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '3000.00'}}, {'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '3.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '5000.00'}}]]]}], {'company': 1, 'shops': [1]}]) + mock_call.assert_called_with('model.sale.sale.create', [[{'company': 1, 'shipment_address': '307', 'invoice_address': '307', 'currency': 31, 'description': '', 'party': '1', 'reference': 'don_confiao 1', 'sale_date': {'__class__': 'date', 'year': 2024, 'month': 9, 'day': 2}, 'lines': [['create', [{'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '2.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '3000.00'}}, {'product': '1', 'quantity': {'__class__': 'Decimal', 'decimal': '3.00'}, 'type': 'line', 'unit': '1', 'unit_price': {'__class__': 'Decimal', 'decimal': '5000.00'}}]]]}], {'company': 1, 'shops': [1]}]) -- 2.45.2