diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index c8545c4..5b54659 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -313,15 +313,11 @@ def manual_response(name, response): if not frappe.db.exists("Quotation", name): raise Exception("Estimate not found.") estimate = frappe.get_doc("Quotation", name) - if estimate.docstatus != 1: - raise Exception("Estimate must be submitted to update response.") accepted = True if response == "Accepted" else False new_status = "Estimate Accepted" if accepted else "Lost" estimate.custom_response = response estimate.custom_current_status = new_status - # estimate.custom_current_status = new_status - # estimate.status = "Ordered" if accepted else "Closed" estimate.flags.ignore_permissions = True print("DEBUG: Updating estimate with response:", response, "and status:", new_status) estimate.save() diff --git a/custom_ui/migration_data/move_primary_contact.py b/custom_ui/migration_data/move_primary_contact.py new file mode 100644 index 0000000..6722f17 --- /dev/null +++ b/custom_ui/migration_data/move_primary_contact.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +"""Move primary_contact from addresses.json to address_updates.json as {first_name, last_name}.""" + +import json + +DATA_DIR = "/home/casey-wittrock/brotherton-bench/apps/custom_ui/custom_ui/migration_data" + + +def extract_full_name(primary_contact_str): + """Extract full_name from the 'full_name-full_name' format.""" + if not primary_contact_str: + return None + # Format is "FullName-FullName" where the name is duplicated + n = len(primary_contact_str) + if n >= 3: + mid = n // 2 + if primary_contact_str[mid] == '-' and primary_contact_str[:mid] == primary_contact_str[mid + 1:]: + return primary_contact_str[:mid] + # Fallback: return as-is + return primary_contact_str + + +def main(): + # Load contacts.json for first_name/last_name lookup + print("Loading contacts.json...") + with open(f"{DATA_DIR}/contacts.json", "r") as f: + contacts = json.load(f) + + contact_lookup = {} + for c in contacts: + first = c.get("first_name", "") + last = c.get("last_name", "") + full = f"{first} {last}".strip() + if full: + contact_lookup[full] = {"first_name": first, "last_name": last} + print(f" Built contact lookup with {len(contact_lookup)} entries") + + # Load addresses.json + print("Loading addresses.json...") + with open(f"{DATA_DIR}/addresses.json", "r") as f: + addresses = json.load(f) + + # Build map: address_title -> primary_contact info + primary_contact_map = {} + missing_contacts = set() + null_contacts = 0 + found_contacts = 0 + + for addr in addresses: + title = addr.get("address_title") + pc_str = addr.get("primary_contact") + if not title: + continue + if not pc_str: + null_contacts += 1 + continue + full_name = extract_full_name(pc_str) + if full_name and full_name in contact_lookup: + primary_contact_map[title] = contact_lookup[full_name] + found_contacts += 1 + elif full_name: + missing_contacts.add(full_name) + # Still use the full_name as first_name fallback + primary_contact_map[title] = {"first_name": full_name, "last_name": ""} + + print(f" Found {found_contacts} primary contacts, {null_contacts} null, {len(missing_contacts)} missing from contacts.json") + if missing_contacts: + for c in sorted(missing_contacts)[:5]: + print(f" - {c}") + if len(missing_contacts) > 5: + print(f" ... and {len(missing_contacts) - 5} more") + + # Remove primary_contact from addresses.json + print("\nRemoving primary_contact from addresses.json...") + for addr in addresses: + addr.pop("primary_contact", None) + with open(f"{DATA_DIR}/addresses.json", "w") as f: + json.dump(addresses, f, indent=2) + print(" Done.") + + # Add primary_contact to address_updates.json + print("Adding primary_contact to address_updates.json...") + with open(f"{DATA_DIR}/address_updates.json", "r") as f: + address_updates = json.load(f) + + added = 0 + for entry in address_updates: + title = entry.get("address_title") + if title and title in primary_contact_map: + entry["primary_contact"] = primary_contact_map[title] + added += 1 + + with open(f"{DATA_DIR}/address_updates.json", "w") as f: + json.dump(address_updates, f, indent=2) + print(f" Added primary_contact to {added} address update entries.") + + print("\nDone!") + + +if __name__ == "__main__": + main() diff --git a/frontend/src/components/pages/Estimate.vue b/frontend/src/components/pages/Estimate.vue index 3279910..25cf7f8 100644 --- a/frontend/src/components/pages/Estimate.vue +++ b/frontend/src/components/pages/Estimate.vue @@ -2,8 +2,8 @@