(20250225)
This commit is contained in:
@@ -359,6 +359,15 @@ class PaymentsController(CoreAuthTokenController, ABC):
|
|||||||
if sql_json["status"] == 1: return True
|
if sql_json["status"] == 1: return True
|
||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
|
async def add_sales_line_item(
|
||||||
|
self,
|
||||||
|
sql_conn: AsyncMySQL,
|
||||||
|
mongo_data_conn: AsyncMongo,
|
||||||
|
payment: CorePaymentModel,
|
||||||
|
session_token: str = None
|
||||||
|
):
|
||||||
|
pass
|
||||||
|
|
||||||
async def add_sales_transaction(
|
async def add_sales_transaction(
|
||||||
self,
|
self,
|
||||||
sql_conn: AsyncMySQL,
|
sql_conn: AsyncMySQL,
|
||||||
@@ -376,7 +385,7 @@ class PaymentsController(CoreAuthTokenController, ABC):
|
|||||||
:return: True is the receipt was added, else False.
|
:return: True is the receipt was added, else False.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Call the database's procedure:
|
# Add the master entry of the sales transaction:
|
||||||
sql_json = await self.call_procedure(
|
sql_json = await self.call_procedure(
|
||||||
sql_conn = sql_conn,
|
sql_conn = sql_conn,
|
||||||
proc_name = "sales_transaction_add",
|
proc_name = "sales_transaction_add",
|
||||||
@@ -396,9 +405,56 @@ class PaymentsController(CoreAuthTokenController, ABC):
|
|||||||
alert_on_all_failures = True
|
alert_on_all_failures = True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Return the response:
|
# If we could not create the master,
|
||||||
if sql_json["status"] == 1: return True
|
# we return with failure:
|
||||||
else: return False
|
if sql_json["status"] != 1: return False
|
||||||
|
|
||||||
|
# We format the line items to a simple array:
|
||||||
|
line_items = []
|
||||||
|
for account_group_id in payment.metadata.againstReference.keys():
|
||||||
|
for line_item in payment.metadata.againstReference[account_group_id]:
|
||||||
|
line_item["accountGroupId"] = account_group_id
|
||||||
|
line_items.append(line_item)
|
||||||
|
|
||||||
|
print("LINE ITEMS:", json.to_string(line_items, default=str))
|
||||||
|
|
||||||
|
# Now we add the line items for each entry:
|
||||||
|
journal_entry_id = sql_json["data"]["sales_id"]
|
||||||
|
success_count = 0
|
||||||
|
total_count = len(line_items)
|
||||||
|
for line_item in line_items:
|
||||||
|
sql_json = await self.call_procedure(
|
||||||
|
sql_conn = sql_conn,
|
||||||
|
proc_name = "sales_transaction_details_add",
|
||||||
|
proc_args = (
|
||||||
|
payment.user.userId,
|
||||||
|
payment.user.billingAccountId,
|
||||||
|
journal_entry_id,
|
||||||
|
line_item["accountId"],
|
||||||
|
json.to_string(
|
||||||
|
python_data = {
|
||||||
|
"clientId": payment.metadata.idClient,
|
||||||
|
"accountId": line_item.get("accountId"),
|
||||||
|
"accountName": line_item.get("accountName"),
|
||||||
|
"quantity": line_item.get("quantity"),
|
||||||
|
"uom": line_item.get("uom"),
|
||||||
|
"unitPrice": line_item.get("unitPrice"),
|
||||||
|
"hsnCode": line_item.get("hsnCode"),
|
||||||
|
},
|
||||||
|
no_space = True
|
||||||
|
),
|
||||||
|
line_item["total"],
|
||||||
|
),
|
||||||
|
retry_count = 1,
|
||||||
|
backoff_seconds = 0.5,
|
||||||
|
backoff_multiplier = 1.1,
|
||||||
|
session_token = session_token,
|
||||||
|
alert_on_all_failures = True
|
||||||
|
)
|
||||||
|
if sql_json["status"] == 1: success_count += 1
|
||||||
|
|
||||||
|
# Done here:
|
||||||
|
return True if total_count == success_count else False
|
||||||
|
|
||||||
async def add_event_by_payment_id(
|
async def add_event_by_payment_id(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user