From 918d5e4c4d3357194de90dabd8852ca83efbc9be Mon Sep 17 00:00:00 2001 From: IriskaID Date: Wed, 26 Jul 2023 02:15:17 +0700 Subject: [PATCH 1/3] Add string date --- README.rst | 4 ++++ amocrm/v2/fields.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 7e743c7..75c79bc 100644 --- a/README.rst +++ b/README.rst @@ -127,7 +127,11 @@ Example:: utm = custom_field.UrlCustomField("UTM метка") delivery_type = custom_field.SelectCustomField("Способ доставки") address = custom_field.TextCustomField("Адрес") + date = custom_field.DateCustomField( + "Дата платежа") + my_lead = Lead.objects.get(object_id=33462781) + my_lead.date = "10.12.2025" # дату можно указать в виде строки День.Месяц.Год Однако мапинг всех кастомных полей дело утоминетльное, поэтому для генерации файла с готовым мапингом есть команда:: diff --git a/amocrm/v2/fields.py b/amocrm/v2/fields.py index 87ec0d0..75d88af 100644 --- a/amocrm/v2/fields.py +++ b/amocrm/v2/fields.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from . import exceptions from .links import LinksInteraction From 4865e7adb097edc20405b564da67e5ec8aa646b1 Mon Sep 17 00:00:00 2001 From: IriskaID Date: Wed, 26 Jul 2023 02:25:10 +0700 Subject: [PATCH 2/3] custom date string --- amocrm/v2/entity/custom_field.py | 6 +++++- amocrm/v2/fields.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/amocrm/v2/entity/custom_field.py b/amocrm/v2/entity/custom_field.py index 46a6fc2..c3caf32 100644 --- a/amocrm/v2/entity/custom_field.py +++ b/amocrm/v2/entity/custom_field.py @@ -1,5 +1,5 @@ from collections import namedtuple -from datetime import datetime +from datetime import datetime, timezone from .. import fields, manager, model from ..interaction import GenericInteraction @@ -244,6 +244,10 @@ def on_get(self, values): def on_set(self, value): if isinstance(value, datetime): value = value.timestamp() + if isinstance(value, str): + date_obj = datetime.strptime(value, "%d.%m.%Y") + date_obj_utc = date_obj.replace(tzinfo=timezone.utc) + value = date_obj_utc.strftime("%Y-%m-%dT%H:%M:%S%z") return super().on_set(value) diff --git a/amocrm/v2/fields.py b/amocrm/v2/fields.py index 75d88af..87ec0d0 100644 --- a/amocrm/v2/fields.py +++ b/amocrm/v2/fields.py @@ -1,4 +1,4 @@ -from datetime import datetime, timezone +from datetime import datetime from . import exceptions from .links import LinksInteraction From c26cab33c093e357e8fc832a7977f2936e6bb727 Mon Sep 17 00:00:00 2001 From: IriskaID Date: Mon, 31 Jul 2023 22:58:07 +0700 Subject: [PATCH 3/3] fix is_computed filed --- amocrm/v2/interaction.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/amocrm/v2/interaction.py b/amocrm/v2/interaction.py index 1ba811e..b01f915 100644 --- a/amocrm/v2/interaction.py +++ b/amocrm/v2/interaction.py @@ -127,6 +127,8 @@ def create(self, data): def update(self, object_id, data): path = "{}/{}".format(self._get_path(), object_id) + for item in data['custom_fields_values']: + item.pop('is_computed', None) response, status = self.request("patch", path, data=data) if status == 400: raise exceptions.ValidationError(response)