feat: add site code doctype #21
12 changed files with 301 additions and 165 deletions
|
|
@ -25,11 +25,7 @@
|
|||
<div class="row">
|
||||
<label for="bill_no" class="col-sm-3 col-form-label">Invoice Number</label>
|
||||
<div class="col-sm-8">
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="bill_no"
|
||||
v-model.number="invoiceData.bill_no" />
|
||||
<input type="text" class="form-control" id="bill_no" v-model.number="invoiceData.bill_no" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -246,3 +246,5 @@ website_route_rules = [
|
|||
{"from_route": "/supplier-portal/<path:app_path>", "to_route": "supplier-portal"},
|
||||
{"from_route": "/erpnext", "to_route": "/app"},
|
||||
]
|
||||
|
||||
export_python_type_annotations = True
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@
|
|||
<div id="popovers"></div>
|
||||
|
||||
<script> window.csrf_token = '{{ csrf_token }}'; </script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,137 +1,137 @@
|
|||
{
|
||||
"custom_fields": [
|
||||
{
|
||||
"_assign": null,
|
||||
"_comments": null,
|
||||
"_liked_by": null,
|
||||
"_user_tags": null,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"creation": "2025-05-19 02:22:24.828657",
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"dt": "Purchase Invoice",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "service_date",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"idx": 12,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "due_date",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Service Date",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2025-05-19 02:22:24.828657",
|
||||
"modified_by": "Administrator",
|
||||
"module": null,
|
||||
"name": "Purchase Invoice-service_date",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"owner": "Administrator",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"_assign": null,
|
||||
"_comments": null,
|
||||
"_liked_by": null,
|
||||
"_user_tags": null,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"creation": "2025-05-19 02:22:24.721092",
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"dt": "Purchase Invoice",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "site_code",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"idx": 6,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "company",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Site Code",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2025-05-19 02:22:24.721092",
|
||||
"modified_by": "Administrator",
|
||||
"module": null,
|
||||
"name": "Purchase Invoice-site_code",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"owner": "Administrator",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
],
|
||||
"custom_perms": [],
|
||||
"doctype": "Purchase Invoice",
|
||||
"links": [],
|
||||
"property_setters": [],
|
||||
"sync_on_migrate": 1
|
||||
"custom_fields": [
|
||||
{
|
||||
"_assign": null,
|
||||
"_comments": null,
|
||||
"_liked_by": null,
|
||||
"_user_tags": null,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"creation": "2025-05-19 02:22:24.828657",
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"dt": "Purchase Invoice",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "service_date",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"idx": 12,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "due_date",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Service Date",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2025-05-19 02:22:24.828657",
|
||||
"modified_by": "Administrator",
|
||||
"module": null,
|
||||
"name": "Purchase Invoice-service_date",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"owner": "Administrator",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"_assign": null,
|
||||
"_comments": null,
|
||||
"_liked_by": null,
|
||||
"_user_tags": null,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"creation": "2025-05-19 02:22:24.721092",
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"dt": "Purchase Invoice",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "site_code",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"idx": 6,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "company",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Site Code",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2025-05-19 02:22:24.721092",
|
||||
"modified_by": "Administrator",
|
||||
"module": null,
|
||||
"name": "Purchase Invoice-site_code",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": null,
|
||||
"owner": "Administrator",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 1,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
],
|
||||
"custom_perms": [],
|
||||
"doctype": "Purchase Invoice",
|
||||
"links": [],
|
||||
"property_setters": [],
|
||||
"sync_on_migrate": 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) 2025, jeowsome15@gmail.com and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('Site Code', {
|
||||
refresh(frm) {
|
||||
if (!frm.doc.__islocal) {
|
||||
frappe.contacts.render_address_and_contact(frm)
|
||||
} else {
|
||||
frappe.contacts.clear_address_and_contact(frm)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
"actions": [],
|
||||
"autoname": "field:site_code",
|
||||
"creation": "2025-06-17 01:51:35.709515",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": ["site_code", "column_break_pwyn", "addresses_section", "address_html"],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "site_code",
|
||||
"fieldtype": "Data",
|
||||
"in_global_search": 1,
|
||||
"in_list_view": 1,
|
||||
"in_preview": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Site Code",
|
||||
"no_copy": 1,
|
||||
"not_nullable": 1,
|
||||
"reqd": 1,
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_pwyn",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: !doc.__islocal",
|
||||
"fieldname": "address_html",
|
||||
"fieldtype": "HTML",
|
||||
"label": "Address HTML",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "addresses_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Addresses"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2025-06-17 02:29:32.191624",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Suppliers Portal",
|
||||
"name": "Site Code",
|
||||
"naming_rule": "By fieldname",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "site_code"
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright (c) 2025, jeowsome15@gmail.com and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from frappe.contacts.address_and_contact import delete_contact_and_address, load_address_and_contact
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class SiteCode(Document):
|
||||
# begin: auto-generated types
|
||||
# This code is auto-generated. Do not modify anything in this block.
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frappe.types import DF
|
||||
|
||||
site_code: DF.Data
|
||||
# end: auto-generated types
|
||||
|
||||
def onload(self):
|
||||
load_address_and_contact(self)
|
||||
|
||||
def on_trash(self):
|
||||
delete_contact_and_address("Site Code", self.name)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2025, jeowsome15@gmail.com and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestSiteCode(FrappeTestCase):
|
||||
pass
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
<div id="popovers"></div>
|
||||
|
||||
<script> window.csrf_token = '{{ csrf_token }}'; </script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue