Skip to content

Commit

Permalink
Merge pull request #57 from navariltd/develop-10
Browse files Browse the repository at this point in the history
Inclusion of Batch no on item_designation, batch conflict solution
  • Loading branch information
maniamartial authored Jun 6, 2024
2 parents fa9e0e6 + 632932f commit 08fc4c9
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
19 changes: 15 additions & 4 deletions burundi_compliance/burundi_compliance/data/stock_ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import frappe
from ..utils.format_date_and_time import date_time_format
from burundi_compliance.burundi_compliance.api_classes.base import OBRAPIBase

import time
auth=OBRAPIBase()

def get_stock_ledger_data(doc):
Expand All @@ -26,11 +26,14 @@ def get_stock_ledger_data(doc):
formatted_date = date[0]

item_movement_invoice_ref=get_invoice_reference_number(voucher_type, voucher_no)



item_designation=create_item_designation(specified_doc, item_code)

data = {
"system_or_device_id": get_system_tax_id(),
"item_code": doc.item_code,
"item_designation": doc.item_code,
"item_designation": item_designation,
"item_quantity": abs(float(quantity_difference)) if voucher_type == "Stock Reconciliation" else abs(float(doc.actual_qty)),
"item_measurement_unit": doc.stock_uom,
"item_purchase_or_sale_price": int(valuation_rate),
Expand All @@ -40,7 +43,6 @@ def get_stock_ledger_data(doc):
"item_movement_description":movement_description,
"item_movement_date": formatted_date,
}

return data

def get_voucher_doc_details(stock_ledger_entry_doc, voucher_type, voucher_no, item_code):
Expand Down Expand Up @@ -281,3 +283,12 @@ def get_invoice_reference_number(voucher_type, voucher_no):
item_invoice_ref=sales_doc.name
return item_invoice_ref


def create_item_designation(specified_doc, item_code):
items=specified_doc.items
for item in items:
if item.item_code==item_code:
if item.batch_no:
return item.item_code + " - "+item.batch_no
else:
return item.item_code
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

auth_details=obr_integration_base.get_auth_details()
allow_obr_to_track_stock_movement=auth_details["allow_obr_to_track_stock_movement"]

import time


def on_update(doc, method=None):
obr_integration_base.authenticate()
send_data(doc)
pass
# obr_integration_base.authenticate()
# send_data(doc)


def send_data(doc):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@
</div>
{%- endif %}



</div>


Expand Down
54 changes: 11 additions & 43 deletions burundi_compliance/burundi_compliance/utils/format_date_and_time.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
from datetime import datetime, timedelta

# def date_time_format(doc):

# formatted_date = f'{doc.posting_date} {doc.posting_time}'
# datetime_obj = datetime.strptime(formatted_date, '%Y-%m-%d %H:%M:%S.%f')

# formatted_date = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
# identity_date=datetime_obj.strftime('%Y%m%d%H%M%S')

# return formatted_date, identity_date
# from datetime import datetime

# def date_time_format(doc):
# formatted_date = f'{doc.posting_date} {doc.posting_time}'
# datetime_obj = datetime.strptime(formatted_date, '%Y-%m-%d %H:%M:%S')

# formatted_date = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
# identity_date = datetime_obj.strftime('%Y%m%d%H%M%S')

# return formatted_date, identity_date

from datetime import datetime

def date_time_format(doc):
formatted_date = f'{doc.posting_date} {doc.posting_time}'
if doc.doctype == 'Sales Invoice':
formatted_date = f'{doc.posting_date} {doc.posting_time}'
else:
formatted_date = f'{doc.posting_date} {get_now_time()}'

# Check if microseconds are present in the formatted_date
if '.' in formatted_date:
Expand All @@ -36,36 +20,20 @@ def date_time_format(doc):
identity_date = datetime_obj.strftime('%Y%m%d%H%M%S')
return formatted_date, identity_date

# def date_time_format(doc):
# # Convert timedelta to hours, minutes, and seconds
# hours = doc.posting_time.seconds // 3600
# minutes = (doc.posting_time.seconds % 3600) // 60
# seconds = doc.posting_time.seconds % 60

# # Format time components with leading zeros if necessary
# formatted_time = f'{hours:02d}:{minutes:02d}:{seconds:02d}'

# # Concatenate posting_date and formatted_time
# formatted_date = f'{doc.posting_date} {formatted_time}'

# # Parse formatted_date
# datetime_obj = datetime.strptime(formatted_date, '%Y-%m-%d %H:%M:%S')

# # Format datetime_obj
# formatted_date = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
# identity_date = datetime_obj.strftime('%Y%m%d%H%M%S')

# return formatted_date, identity_date


def date_time_format_on_cancel(doc):
formatted_date = f'{doc.posting_date} {doc.posting_time}'
formatted_date = f'{doc.posting_date} {get_now_time()}'
datetime_obj = datetime.strptime(formatted_date, '%Y-%m-%d %H:%M:%S.%f')

# Add 1 second to the datetime object
datetime_obj += timedelta(seconds=1)
datetime_obj += timedelta(seconds=2)

formatted_date = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
identity_date = datetime_obj.strftime('%Y%m%d%H%M%S')

return formatted_date, identity_date

def get_now_time():
currentDT = datetime.now()
current_time = currentDT.strftime("%H:%M:%S")
return current_time
34 changes: 28 additions & 6 deletions burundi_compliance/burundi_compliance/utils/schedular.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,44 @@

from burundi_compliance.burundi_compliance.overrides.stock_ledger_entry import send_data
from burundi_compliance.burundi_compliance.overrides.sales_invoice import submit_invoice_request

import time
# def check_and_send_pending_stock_ledger_entry():
# '''
# Check and send unsend stock ledger entries
# '''
# stock_ledger_entries = frappe.get_all("Stock Ledger Entry", filters={"docstatus": 1, "custom_etracker": 0}, fields=["name"])

# for stock_ledger_entry in stock_ledger_entries:

# try:

# stock_ledger_entry_doc = frappe.get_doc("Stock Ledger Entry", stock_ledger_entry.name)

# check_item = frappe.get_doc("Item", stock_ledger_entry_doc.item_code)
# if check_item.custom_allow_obr_to_track_stock_movement == 0:
# continue
# send_data(stock_ledger_entry_doc)

# except Exception as e:
# frappe.log_error(frappe.get_traceback(), "Error in sending stock ledger entry {0}".format(stock_ledger_entry.name))
# continue
def check_and_send_pending_stock_ledger_entry():
'''
Check and send unsend stock ledger entries
'''
stock_ledger_entries = frappe.get_all("Stock Ledger Entry", filters={"docstatus": 1, "custom_etracker": 0}, fields=["name"])
stock_ledger_entries = frappe.get_all("Stock Ledger Entry", filters={"docstatus": 1, "custom_etracker": 0}, fields=["name"], order_by='posting_time asc')

for stock_ledger_entry in stock_ledger_entries:

try:

time.sleep(3)
stock_ledger_entry_doc = frappe.get_doc("Stock Ledger Entry", stock_ledger_entry.name)
if stock_ledger_entry_doc.voucher_type == "Stock Reconciliation" and stock_ledger_entry_doc.has_batch_no == 1 and stock_ledger_entry_doc.actual_qty < 0:
continue
check_item = frappe.get_doc("Item", stock_ledger_entry_doc.item_code)
if check_item.custom_allow_obr_to_track_stock_movement == 0:
continue
# frappe.publish_realtime("msgpring",f'{stock_ledger_entry_doc}', user=frappe.session.user)
send_data(stock_ledger_entry_doc)

except Exception as e:
Expand All @@ -36,6 +60,4 @@ def check_and_send_pending_sales_invoices():
except Exception as e:
frappe.log_error(frappe.get_traceback(), "Error in sending sales invoice {0}".format(sales_invoice.name))
continue

def testing_schedular():
frappe.publish_realtime("testing_schedular", user=frappe.session.user)

2 changes: 1 addition & 1 deletion burundi_compliance/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@

"cron":{
"0 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_sales_invoices"],
"2 * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_stock_ledger_entry"],
"* * * * *":["burundi_compliance.burundi_compliance.utils.schedular.check_and_send_pending_stock_ledger_entry"],
},

}
Expand Down

0 comments on commit 08fc4c9

Please sign in to comment.