From 5814c87ae2bb23504c0ca0b9369950b0cdf2ec1a Mon Sep 17 00:00:00 2001 From: Dave Porter Date: Mon, 20 Oct 2025 14:52:44 -0400 Subject: [PATCH] Fix duplicate deliverables: Separate OMG# and OMG URL fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - Added OMG_URL custom field (IEAGU2B2JUAJRZ7Y) - Updated OMG# field ID (IEAGU2B2JUAJV4P7) - Deliverables now use: - OMG# = plain number (e.g., "6027380") for duplicate detection - OMG_URL = clickable URL (e.g., "https://bissell.omg.oliver.solutions/jobs/5027381") - Fixed find_deliverable_by_omg_number() to search on plain number - Improved error handling in duplicate detection - Tested: Duplicate prevention works correctly This prevents duplicate deliverable creation by searching on the plain OMG# number while still providing clickable URLs in the OMG_URL field. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- wrike_monitor.py | 69 ++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/wrike_monitor.py b/wrike_monitor.py index a8252f7..260611a 100644 --- a/wrike_monitor.py +++ b/wrike_monitor.py @@ -65,7 +65,8 @@ class Config: "deliverable_category": "IEAGU2B2JUAJRZ7T", "actions": "IEAGU2B2JUAJRZ7W", "shoot_date": "IEAGU2B2JUAJRZ7X", - "omg_number": "IEAGU2B2JUAJRZ7Y", + "omg_number": "IEAGU2B2JUAJV4P7", # Plain OMG# number + "omg_url": "IEAGU2B2JUAJRZ7Y", # OMG URL field "box_link": "IEAGU2B2JUAJRZ7Z", "owner": "IEAGU2B2JUAJRZ72" } @@ -420,27 +421,38 @@ class WrikeMonitor: if not omg_number: return None - # Get folder tree - result = self.make_wrike_request("GET", f"/folders/{parent_project_id}/folders?fields=[\"customFields\",\"project\"]") + try: + # Get all subfolders/projects with custom fields + result = self.make_wrike_request("GET", f"/folders/{parent_project_id}/folders") - if result and "data" in result: - # Find parent folder with childIds - parent_folder = None - for item in result["data"]: - if item["id"] == parent_project_id: - parent_folder = item - break - - if parent_folder: - child_ids = parent_folder.get("childIds", []) - # Search only in direct children that are projects + if result and "data" in result: + # Find parent folder with childIds + parent_folder = None for item in result["data"]: - if item["id"] in child_ids and "project" in item: - custom_fields = item.get("customFields", []) - for field in custom_fields: - if field.get("id") == Config.CUSTOM_FIELDS["omg_number"]: - if field.get("value") == omg_number: - return item["id"] + if item["id"] == parent_project_id: + parent_folder = item + break + + if parent_folder: + child_ids = parent_folder.get("childIds", []) + + # For each child, get its details with custom fields + for child_id in child_ids: + child_result = self.make_wrike_request("GET", f"/folders/{child_id}") + if child_result and "data" in child_result and len(child_result["data"]) > 0: + child = child_result["data"][0] + + # Check if it's a project (deliverable) + if "project" in child: + custom_fields = child.get("customFields", []) + for field in custom_fields: + if field.get("id") == Config.CUSTOM_FIELDS["omg_number"]: + if field.get("value") == omg_number: + self.logger.debug(f"Found existing deliverable with OMG# {omg_number}: {child_id}") + return child_id + except Exception as e: + self.logger.error(f"Error searching for deliverable: {e}") + return None def generate_omg_url(self, omg_number): @@ -500,20 +512,21 @@ class WrikeMonitor: # Add custom fields custom_fields = [] - # For deliverables: OMG# field gets the URL, not just the number + # For deliverables: OMG# = plain number, OMG_URL = URL if job_number: + # Plain OMG# number for duplicate detection + custom_fields.append({ + "id": Config.CUSTOM_FIELDS["omg_number"], + "value": job_number + }) + + # Generate and add URL to OMG_URL field omg_url = self.generate_omg_url(job_number) if omg_url: custom_fields.append({ - "id": Config.CUSTOM_FIELDS["omg_number"], + "id": Config.CUSTOM_FIELDS["omg_url"], "value": omg_url }) - else: - # Fallback to just the number if URL generation fails - custom_fields.append({ - "id": Config.CUSTOM_FIELDS["omg_number"], - "value": job_number - }) job_category = job_details.get("JobCategory", job_details.get("MediaType", "")) if job_category: