Skip to content

Commit

Permalink
chore: Sage X3 and pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamoqs committed Dec 6, 2023
1 parent 366c58c commit aa37577
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion apps/billing/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-29 09:36
# Generated by Django 4.2.5 on 2023-12-06 15:19

import django.db.models.deletion
import django_countries.fields
Expand Down Expand Up @@ -90,6 +90,7 @@ class Migration(migrations.Migration):
("retries", models.PositiveIntegerField(default=0)),
("input_xml", models.TextField(blank=True, null=True)),
("output_xml", models.TextField(blank=True, null=True)),
("error_messages", models.TextField(blank=True, null=True)),
(
"transaction",
models.OneToOneField(
Expand Down
1 change: 1 addition & 0 deletions apps/billing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class SageX3TransactionInformation(BaseModel):
retries = models.PositiveIntegerField(default=0)
input_xml = models.TextField(null=True, blank=True)
output_xml = models.TextField(null=True, blank=True)
error_messages = models.TextField(null=True, blank=True)

def __str__(self):
return f"{self.transaction.transaction_id} - {self.status}"
12 changes: 7 additions & 5 deletions apps/billing/services/processor_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self) -> None:
self.__user_processor_auth = getattr(settings, "USER_PROCESSOR_AUTH")
self.__user_processor_password = getattr(settings, "USER_PROCESSOR_PASSWORD")

def __save_transaction_xml(self, transaction: Transaction, input_xml: str, output_xml: str) -> None:
def __save_transaction_xml(self, transaction: Transaction, informations: dict) -> None:
"""
Saves the XML content of a transaction to the database.
Expand All @@ -36,7 +36,7 @@ def __save_transaction_xml(self, transaction: Transaction, input_xml: str, outpu
"""
try:
created, obj = SageX3TransactionInformation.objects.get_or_create(
transaction=transaction, defaults={"input_xml": input_xml, "output_xml": output_xml}
transaction=transaction, defaults={**informations}
)
if not created:
obj.retries += 1
Expand All @@ -52,6 +52,7 @@ def send_transaction_to_processor(self, transaction: Transaction) -> dict:

try:
data = self.__generate_data_to_save(transaction=transaction)
informations = {"input_xml": data, "error_messages": ""}
response = requests.post(
url=self.__processor_url,
data=data,
Expand All @@ -62,12 +63,13 @@ def send_transaction_to_processor(self, transaction: Transaction) -> dict:
),
).content
response_as_json = dict(xmltodict.parse(response))

self.__save_transaction_xml(transaction, data, response)
informations["output_xml"] = response
self.__save_transaction_xml(transaction, informations)

return response_as_json
except Exception as e:
raise e
informations["error_messages"] = str(e)
self.__save_transaction_xml(transaction, informations)

def __generate_items_as_xml(self, items: list[TransactionItem]) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion apps/organization/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-29 09:36
# Generated by Django 4.2.5 on 2023-12-06 15:19

from django.db import migrations, models

Expand Down
2 changes: 1 addition & 1 deletion apps/shared_revenue/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-29 09:36
# Generated by Django 4.2.5 on 2023-12-06 15:19

import django.core.validators
import django.db.models.deletion
Expand Down
2 changes: 1 addition & 1 deletion apps/util/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.5 on 2023-11-29 09:36
# Generated by Django 4.2.5 on 2023-12-06 15:19

import uuid

Expand Down
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This is default configuration settings used to development purposes.
# We can override any default Django setting.
# The good default setting value should be the default value of the
#
# The good default setting value should be the default value of the
#
# CONFIG.get("KEY", <default value>)
#

Expand Down
10 changes: 4 additions & 6 deletions nau_financial_manager/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from .settings import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': "test.db",
'ATOMIC_REQUESTS': True,
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "test.db",
"ATOMIC_REQUESTS": True,
},
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ multi_line_output = 3
line_length = 119
default_section = "THIRDPARTY"
known_first_party = []
known_third_party = ["celery", "decouple", "django", "django_countries", "django_filters", "drf_yasg", "factory", "requests", "rest_framework", "safedelete", "xlsxwriter", "xmltodict"]
known_third_party = ["celery", "django", "django_countries", "django_filters", "drf_yasg", "factory", "requests", "rest_framework", "safedelete", "xlsxwriter", "xmltodict", "yaml"]

0 comments on commit aa37577

Please sign in to comment.