#14 feat(Tryton): add address on update customers from tryton.
This commit is contained in:
parent
69185f2460
commit
937fe06de4
@ -397,7 +397,7 @@ class CustomersFromTrytonView(APIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __get_party_datails(self, party_ids, tryton_client, context):
|
def __get_party_datails(self, party_ids, tryton_client, context):
|
||||||
tryton_fields = ['id', 'name']
|
tryton_fields = ['id', 'name', 'addresses']
|
||||||
method = 'model.party.party.read'
|
method = 'model.party.party.read'
|
||||||
params = (party_ids, tryton_fields, context)
|
params = (party_ids, tryton_fields, context)
|
||||||
response = tryton_client.call(method, params)
|
response = tryton_client.call(method, params)
|
||||||
@ -406,11 +406,16 @@ class CustomersFromTrytonView(APIView):
|
|||||||
def __need_update(self, customer, tryton_party):
|
def __need_update(self, customer, tryton_party):
|
||||||
if not customer.name == tryton_party.get('name'):
|
if not customer.name == tryton_party.get('name'):
|
||||||
return True
|
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):
|
def __create_customer(self, tryton_party):
|
||||||
customer = Customer()
|
customer = Customer()
|
||||||
customer.name = tryton_party.get('name')
|
customer.name = tryton_party.get('name')
|
||||||
customer.external_id = tryton_party.get('id')
|
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()
|
customer.save()
|
||||||
return customer
|
return customer
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@ class TestCustomersFromTryton(TestCase):
|
|||||||
return [5, 6, 7, 8]
|
return [5, 6, 7, 8]
|
||||||
|
|
||||||
party_read = 'model.party.party.read'
|
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)):
|
if (args == (party_read, read_args)):
|
||||||
return [
|
return [
|
||||||
{'id': 5, 'name': 'Carlos'},
|
{'id': 5, 'name': 'Carlos', 'addresses': []},
|
||||||
{'id': 6, 'name': 'Cristian'},
|
{'id': 6, 'name': 'Cristian', 'addresses': []},
|
||||||
{'id': 7, 'name': 'Ana'},
|
{'id': 7, 'name': 'Ana', 'addresses': [302]},
|
||||||
{'id': 8, 'name': 'José'},
|
{'id': 8, 'name': 'José', 'addresses': []},
|
||||||
]
|
]
|
||||||
|
|
||||||
raise Exception(f"Sorry, args non expected on this test: {args}")
|
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)
|
created_customer = Customer.objects.get(id=3)
|
||||||
self.assertEqual(created_customer.external_id, str(7))
|
self.assertEqual(created_customer.external_id, str(7))
|
||||||
self.assertEqual(created_customer.name, 'Ana')
|
self.assertEqual(created_customer.name, 'Ana')
|
||||||
|
self.assertEqual(created_customer.address_external_id, str(302))
|
||||||
|
|
||||||
updated_customer = Customer.objects.get(id=1)
|
updated_customer = Customer.objects.get(id=1)
|
||||||
self.assertEqual(updated_customer.external_id, str(5))
|
self.assertEqual(updated_customer.external_id, str(5))
|
||||||
self.assertEqual(updated_customer.name, 'Carlos')
|
self.assertEqual(updated_customer.name, 'Carlos')
|
||||||
|
self.assertIn(updated_customer.address_external_id, ['', None])
|
||||||
|
Loading…
Reference in New Issue
Block a user