diff --git a/amocrm/v2/fields.py b/amocrm/v2/fields.py index 87ec0d0..6ddde1f 100644 --- a/amocrm/v2/fields.py +++ b/amocrm/v2/fields.py @@ -115,7 +115,7 @@ def _model(self): @property def _manager(self): - return self.__manager or self._model.objects + return self.__manager or self._model.objects if self._model else None def on_get(self, data): return self._manager.get(object_id=data) @@ -131,7 +131,7 @@ def __init__(self, data, instance, model, manager=None, links=LinksInteraction() self._data = data self._model = model self._instance = instance - self._manager = manager or model.objects + self._manager = manager or model.objects if model else None self._links = links def __iter__(self): diff --git a/tests/data/companies.py b/tests/data/companies.py index 967fae6..c00079b 100644 --- a/tests/data/companies.py +++ b/tests/data/companies.py @@ -21,3 +21,27 @@ "_links": {"self": {"href": "https://exmaple.amocrm.ru/api/v4/companies/1"}}, "_embedded": {"tags": []}, } + +DETAIL_INFO_2 = { + "id": 1, + "name": "АО Копыта и рыла", + "responsible_user_id": 504141, + "group_id": 0, + "created_by": 504141, + "updated_by": 504141, + "created_at": 1582117331, + "updated_at": 1586361223, + "closest_task_at": None, + "custom_fields_values": [ + { + "field_id": 3, + "field_name": "Телефон", + "field_code": "PHONE", + "field_type": "multitext", + "values": [{"value": "123213", "enum_id": 1, "enum": "WORK"}], + } + ], + "account_id": 10, + "_links": {"self": {"href": "https://exmaple.amocrm.ru/api/v4/companies/1"}}, + "_embedded": {"tags": []}, +} \ No newline at end of file diff --git a/tests/test_contacts.py b/tests/test_contacts.py index b181268..b9847f1 100644 --- a/tests/test_contacts.py +++ b/tests/test_contacts.py @@ -2,7 +2,7 @@ from amocrm.v2 import Contact, exceptions, filters -from .data.companies import DETAIL_INFO as COMPANY_DETAIL_INFO +from .data.companies import DETAIL_INFO as COMPANY_DETAIL_INFO, DETAIL_INFO_2 from .data.contacts import (CREATE_DATA, DETAIL_INFO, LIST_PAGE_1, LIST_PAGE_2, UPDATE) from .data.users import DETAIL_INFO as USER_DETAIL_INFO @@ -75,3 +75,15 @@ def test_update(response_mock): contact.last_name = "e" contact.tags.add("tag") contact.save() + + +def test_repr(response_mock): + response_mock.add("GET", "https://test.amocrm.ru/api/v4/contacts/3", match_querystring=False, json=DETAIL_INFO) + response_mock.add("GET", + "https://test.amocrm.ru/api/v4/companies/1?with=contacts%2Ccustomers%2Cleads%2Ctags", + match_querystring=False, + json=DETAIL_INFO_2) + contact = Contact.objects.get(3) + + representation = repr(contact) + assert representation