diff --git a/supplier-portal/src/pages/NewInvoice.vue b/supplier-portal/src/pages/NewInvoice.vue
index 9f71c5c..7cd1eab 100644
--- a/supplier-portal/src/pages/NewInvoice.vue
+++ b/supplier-portal/src/pages/NewInvoice.vue
@@ -25,11 +25,7 @@
diff --git a/supplier-portal/src/pages/SupplierInvoice.vue b/supplier-portal/src/pages/SupplierInvoice.vue
index 0b21772..0dc5e89 100644
--- a/supplier-portal/src/pages/SupplierInvoice.vue
+++ b/supplier-portal/src/pages/SupplierInvoice.vue
@@ -288,14 +288,14 @@ const documents = reactive({})
const invoice = createDocumentResource({
doctype: 'Purchase Invoice',
name: supplierInvoiceNumber,
- onSuccess: (data) => {
+ onSuccess: data => {
documents.invoice = data
documents.address = createDocumentResource({
doctype: 'Address',
name: data.supplier_address,
- auto: true
+ auto: true,
})
- }
+ },
})
diff --git a/suppliers_portal/hooks.py b/suppliers_portal/hooks.py
index 5402507..93d4742 100644
--- a/suppliers_portal/hooks.py
+++ b/suppliers_portal/hooks.py
@@ -246,3 +246,5 @@ website_route_rules = [
{"from_route": "/supplier-portal/", "to_route": "supplier-portal"},
{"from_route": "/erpnext", "to_route": "/app"},
]
+
+export_python_type_annotations = True
diff --git a/suppliers_portal/patches/move_invoices_to_erpnext.py b/suppliers_portal/patches/move_invoices_to_erpnext.py
index f8b8667..aff3f26 100644
--- a/suppliers_portal/patches/move_invoices_to_erpnext.py
+++ b/suppliers_portal/patches/move_invoices_to_erpnext.py
@@ -1,4 +1,5 @@
import json
+import re
import frappe
from erpnext.accounts.doctype.account.account import update_account_number
@@ -88,9 +89,7 @@ def setup_accounts():
force=True,
)
update_account_number(f"1110 - Cash - {abbr}", "Petty Cash", account_number="1110")
- update_account_number(
- f"Primary Checking - {abbr}", "Primary Checking", account_number="1201"
- )
+ update_account_number(f"Primary Checking - {abbr}", "Primary Checking", account_number="1201")
def create_fiscal_years():
@@ -255,12 +254,13 @@ def import_invoices():
if frappe.db.exists("Purchase Invoice", {"name": invoice.get("name")}):
continue
+ site_code = get_site_code(invoice)
invoice_doc = frappe.new_doc("Purchase Invoice")
invoice_doc.update(
{
"supplier": invoice.get("supplier"),
"bill_no": invoice.get("supplier_invoice_number"),
- "site_code": invoice.get("site_code"),
+ "site_code": site_code or "",
"set_posting_time": True,
"bill_date": getdate(invoice.get("invoice_date")),
"posting_date": getdate(invoice.get("invoice_date")),
@@ -294,16 +294,35 @@ def import_invoices():
continue
if invoice.get("street"):
- address = create_address(
- {
- **invoice,
- "title": invoice.get("supplier"),
- "ref_doctype": "Supplier",
- "ref_name": invoice.get("supplier"),
- }
- )
- invoice_doc.supplier_address = address.name
- invoice_doc.save()
+ if site_code:
+ if frappe.db.exists("Site Code", site_code):
+ site_code_doc = frappe.get_doc("Site Code", site_code)
+ else:
+ site_code_doc = frappe.new_doc("Site Code")
+ site_code_doc.site_code = site_code
+ site_code_doc.save(ignore_permissions=True)
+
+ address = create_address(
+ {
+ **invoice,
+ "title": site_code,
+ "ref_doctype": "Site Code",
+ "ref_name": site_code_doc.name,
+ }
+ )
+ invoice_doc.dispatch_address = address.name
+ invoice_doc.save()
+ else:
+ address = create_address(
+ {
+ **invoice,
+ "title": invoice.get("supplier"),
+ "ref_doctype": "Supplier",
+ "ref_name": invoice.get("supplier"),
+ }
+ )
+ invoice_doc.supplier_address = address.name
+ invoice_doc.save()
try:
invoice_doc.submit()
@@ -324,9 +343,7 @@ def import_invoices():
"paid_from": get_account_name("Bank", "Asset"),
"reference_no": payment.get("payment_reference_number")
or "Note: Missing reference during ERPNext import",
- "reference_date": getdate(
- payment.get("payment_reference_date")
- ),
+ "reference_date": getdate(payment.get("payment_reference_date")),
"references": [
{
"reference_doctype": invoice_doc.doctype,
@@ -341,6 +358,17 @@ def import_invoices():
payment_doc.insert(ignore_permissions=True)
payment_doc.submit()
except Exception as e:
- print(
- f"Error importing payment for invoice {invoice_doc.bill_no}: {e}"
- )
+ print(f"Error importing payment for invoice {invoice_doc.bill_no}: {e}")
+
+
+def get_site_code(invoice):
+ if invoice.get("site_code"):
+ return invoice["site_code"].upper()
+
+ # try to find it in the notes
+ site_pattern = re.compile(r"\bsite\s+([A-Z0-9]+)", re.IGNORECASE)
+ notes = invoice.get("notes", "")
+ if notes:
+ matches = site_pattern.findall(notes)
+ if len(matches) > 0:
+ return ", ".join(matches).upper()
diff --git a/suppliers_portal/public/supplier-portal/index.html b/suppliers_portal/public/supplier-portal/index.html
index a6d8cb3..8f3a79b 100644
--- a/suppliers_portal/public/supplier-portal/index.html
+++ b/suppliers_portal/public/supplier-portal/index.html
@@ -16,6 +16,6 @@
-
+