lots of updates
This commit is contained in:
parent
02c48e6108
commit
8ed083fce1
14 changed files with 730 additions and 83 deletions
|
|
@ -178,6 +178,15 @@ def add_custom_fields():
|
|||
default=0,
|
||||
insert_after="custom_installation_address"
|
||||
)
|
||||
],
|
||||
"Sales Order": [
|
||||
dict(
|
||||
fieldname="requires_half_payment",
|
||||
label="Requires Half Payment",
|
||||
fieldtype="Check",
|
||||
default=0,
|
||||
insert_after="custom_installation_address"
|
||||
)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -239,29 +248,55 @@ def update_address_fields():
|
|||
|
||||
print(f"\n📍 Updating fields for {total_addresses} addresses...")
|
||||
|
||||
# Verify custom fields exist by checking the meta
|
||||
address_meta = frappe.get_meta("Address")
|
||||
required_fields = ['full_address', 'custom_onsite_meeting_scheduled',
|
||||
'custom_estimate_sent_status', 'custom_job_status',
|
||||
'custom_payment_received_status']
|
||||
|
||||
# Verify custom fields exist by checking the meta for every doctype that was customized
|
||||
def has_any_field(meta, candidates):
|
||||
return any(meta.has_field(f) for f in candidates)
|
||||
|
||||
custom_field_expectations = {
|
||||
"Address": [
|
||||
["full_address"],
|
||||
["custom_onsite_meeting_scheduled", "onsite_meeting_scheduled"],
|
||||
["custom_estimate_sent_status", "estimate_sent_status"],
|
||||
["custom_job_status", "job_status"],
|
||||
["custom_payment_received_status", "payment_received_status"]
|
||||
],
|
||||
"Contact": [
|
||||
["custom_role", "role"],
|
||||
["custom_email", "email"]
|
||||
],
|
||||
"On-Site Meeting": [
|
||||
["custom_notes", "notes"],
|
||||
["custom_assigned_employee", "assigned_employee"],
|
||||
["custom_status", "status"],
|
||||
["custom_completed_by", "completed_by"]
|
||||
],
|
||||
"Quotation": [
|
||||
["custom_requires_half_payment", "requires_half_payment"]
|
||||
],
|
||||
"Sales Order": [
|
||||
["custom_requires_half_payment", "requires_half_payment"]
|
||||
]
|
||||
}
|
||||
|
||||
missing_fields = []
|
||||
for field in required_fields:
|
||||
if not address_meta.has_field(field):
|
||||
missing_fields.append(field)
|
||||
|
||||
for doctype, field_options in custom_field_expectations.items():
|
||||
meta = frappe.get_meta(doctype)
|
||||
for candidates in field_options:
|
||||
if not has_any_field(meta, candidates):
|
||||
missing_fields.append(f"{doctype}: {'/'.join(candidates)}")
|
||||
|
||||
if missing_fields:
|
||||
print(f"\n❌ Missing custom fields: {', '.join(missing_fields)}")
|
||||
print("\n❌ Missing custom fields:")
|
||||
for entry in missing_fields:
|
||||
print(f" • {entry}")
|
||||
print(" Custom fields creation may have failed. Skipping address updates.")
|
||||
return
|
||||
|
||||
|
||||
print("✅ All custom fields verified. Proceeding with address updates...")
|
||||
|
||||
# Field update counters
|
||||
field_counters = {
|
||||
'full_address': 0,
|
||||
'latitude': 0,
|
||||
'longitude': 0,
|
||||
'custom_onsite_meeting_scheduled': 0,
|
||||
'custom_estimate_sent_status': 0,
|
||||
'custom_job_status': 0,
|
||||
|
|
@ -270,6 +305,9 @@ def update_address_fields():
|
|||
total_field_updates = 0
|
||||
addresses_updated = 0
|
||||
|
||||
onsite_meta = frappe.get_meta("On-Site Meeting")
|
||||
onsite_status_field = "custom_status" if onsite_meta.has_field("custom_status") else "status"
|
||||
|
||||
for index, name in enumerate(addresses, 1):
|
||||
# Calculate progress
|
||||
progress_percentage = int((index / total_addresses) * 100)
|
||||
|
|
@ -277,13 +315,25 @@ def update_address_fields():
|
|||
filled_length = int(bar_length * index // total_addresses)
|
||||
bar = '█' * filled_length + '░' * (bar_length - filled_length)
|
||||
|
||||
# Print progress bar with field update count
|
||||
print(f"\r📊 Progress: [{bar}] {progress_percentage:3d}% ({index}/{total_addresses}) | Fields Updated: {total_field_updates} - Processing: {name[:25]}...", end='', flush=True)
|
||||
|
||||
# Print a three-line, refreshing progress block to avoid terminal wrap
|
||||
progress_line = f"📊 Progress: [{bar}] {progress_percentage:3d}% ({index}/{total_addresses})"
|
||||
counters_line = f" Fields updated: {total_field_updates} | Addresses updated: {addresses_updated}"
|
||||
detail_line = f" Processing: {name[:40]}..."
|
||||
|
||||
if index == 1:
|
||||
# Save cursor position at the start of the progress block
|
||||
print("\033[s", end='')
|
||||
else:
|
||||
# Restore to the saved cursor position to rewrite the three-line block
|
||||
print("\033[u", end='')
|
||||
|
||||
print(f"\r\033[K{progress_line}")
|
||||
print(f"\r\033[K{counters_line}")
|
||||
print(f"\r\033[K{detail_line}", end='' if index != total_addresses else '\n', flush=True)
|
||||
|
||||
should_update = False
|
||||
address = frappe.get_doc("Address", name)
|
||||
current_address_updates = 0
|
||||
current_address_updates = 0
|
||||
|
||||
# Use getattr with default values instead of direct attribute access
|
||||
if not getattr(address, 'full_address', None):
|
||||
|
|
@ -310,14 +360,15 @@ def update_address_fields():
|
|||
job_status = "Not Started"
|
||||
payment_received = "Not Started"
|
||||
|
||||
onsite_meetings = frappe.get_all("On-Site Meeting", fields=["docstatus"],filters={"address": address.address_title})
|
||||
onsite_meetings = frappe.get_all("On-Site Meeting", fields=[onsite_status_field], filters={"address": address.address_title})
|
||||
if onsite_meetings and onsite_meetings[0]:
|
||||
onsite_meeting = "Completed" if onsite_meetings[0]["docstatus"] == 1 else "In Progress"
|
||||
status_value = onsite_meetings[0].get(onsite_status_field)
|
||||
onsite_meeting = "Completed" if status_value == "Completed" else "In Progress"
|
||||
|
||||
estimates = frappe.get_all("Quotation", fields=["custom_sent", "docstatus"], filters={"custom_installation_address": address.address_title})
|
||||
if estimates and estimates[0] and estimates[0]["custom_sent"] == 1 and estimates[0]["docstatus"] == 1:
|
||||
estimates = frappe.get_all("Quotation", fields=["custom_sent", "docstatus", "custom_response"], filters={"custom_installation_address": address.address_title})
|
||||
if estimates and estimates[0] and estimates[0]["custom_sent"] == 1 and estimates[0]["custom_response"]:
|
||||
estimate_sent = "Completed"
|
||||
elif estimates and estimates[0] and estimates[0]["docstatus"] != 1:
|
||||
elif estimates and estimates[0] and not (estimates[0]["custom_sent"] == 1 and estimates[0]["custom_response"]):
|
||||
estimate_sent = "In Progress"
|
||||
|
||||
jobs = frappe.get_all("Project", fields=["status"], filters={"custom_installation_address": address.address_title, "project_template": "SNW Install"})
|
||||
|
|
@ -367,8 +418,6 @@ def update_address_fields():
|
|||
print(f" • Total field updates: {total_field_updates:,}")
|
||||
print(f"\n📝 Field-specific updates:")
|
||||
print(f" • Full Address: {field_counters['full_address']:,}")
|
||||
print(f" • Latitude: {field_counters['latitude']:,}")
|
||||
print(f" • Longitude: {field_counters['longitude']:,}")
|
||||
print(f" • On-Site Meeting Status: {field_counters['custom_onsite_meeting_scheduled']:,}")
|
||||
print(f" • Estimate Sent Status: {field_counters['custom_estimate_sent_status']:,}")
|
||||
print(f" • Job Status: {field_counters['custom_job_status']:,}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue