From 6ad683bc4a5bb74226c0f13ebb94a48607d4610e Mon Sep 17 00:00:00 2001 From: bedilbek Date: Thu, 27 Feb 2020 16:05:08 +0500 Subject: [PATCH] Add converter from qbd_mixin_model to qbd_task --- CHANGELOG.md | 1 + django_quickbooks/utils.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e32473d..4c5e107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### ADDED +- Add converter from qbd_mixin_model to qbd_task - Add signal to handle post_process after realm is authenticated successfully ## [0.6.3] - 2020-02-14 diff --git a/django_quickbooks/utils.py b/django_quickbooks/utils.py index 6ee7b12..d73fe84 100644 --- a/django_quickbooks/utils.py +++ b/django_quickbooks/utils.py @@ -45,3 +45,21 @@ def get_xml_meta_info(): def random_string(length=10): letters = string.ascii_lowercase + string.ascii_uppercase return ''.join(random.choice(letters) for i in range(length)) + + +def convert_qbd_model_to_qbdtask(obj, qb_resource, qb_operation=None, **kwargs): + from django_quickbooks import QUICKBOOKS_ENUMS + from django.contrib.contenttypes.models import ContentType + + if not qb_operation: + if obj.is_qbd_obj_created: + qb_operation = QUICKBOOKS_ENUMS.OPP_MOD + else: + qb_operation = QUICKBOOKS_ENUMS.OPP_ADD + + return dict( + qb_operation=qb_operation, + qb_resource=qb_resource, + object_id=obj.id, + content_type=ContentType.objects.get_for_model(obj), + )