@@ -1423,8 +1423,9 @@ def patch_bulk_projects(self, request):
14231423 )
14241424 qs = self .get_queryset ().filter (id__in = projectIds ).order_by (preserved )
14251425
1426- # IO-775: Capture original hkrId values BEFORE update for PW sync detection
1426+ # IO-775: Capture original values BEFORE update for PW sync detection
14271427 original_hkr_ids = {str (p .id ): p .hkrId for p in qs }
1428+ original_programmed = {str (p .id ): p .programmed for p in qs }
14281429 # Also capture which projects are getting hkrId in this request
14291430 hkr_ids_in_request = {
14301431 projectData ["id" ]: projectData ["data" ].get ("hkrId" )
@@ -1509,8 +1510,10 @@ def patch_bulk_projects(self, request):
15091510
15101511 # IO-396/IO-775: Sync whenever the updated project has an hkrId
15111512 # IO-396 requirement: Only sync programmed projects
1512- # This ensures that changes to phase, responsible person, dates, etc. sync to PW
1513- should_sync = has_hkr_id and updated_project .programmed
1513+ # Also sync when project WAS programmed (transitioning programmed→unprogrammed)
1514+ # so PW receives the updated phase/status
1515+ was_programmed = original_programmed .get (project_id_str , False )
1516+ should_sync = has_hkr_id and (updated_project .programmed or was_programmed )
15141517
15151518 if should_sync :
15161519 sync_reason = "HKR ID added for first time" if hkr_id_added_first_time else "updating existing PW project"
@@ -1786,14 +1789,16 @@ def _sync_project_to_projectwise(self, request_data: dict, original_project: Pro
17861789 # This ensures that:
17871790 # 1. When hkrId is added for the first time, we sync (initial sync)
17881791 # 2. When a project with existing hkrId is updated (phase, responsible person, dates, etc.), we sync
1789- # IO-396 requirement: Only sync programmed projects
1790- should_sync = updated_has_hkr_id and updated_project .programmed
1792+ # 3. When a programmed project becomes unprogrammed, we sync the change to PW
1793+ # IO-396 requirement: Only sync programmed projects (including those transitioning out)
1794+ original_was_programmed = bool (original_project .programmed )
1795+ should_sync = updated_has_hkr_id and (updated_project .programmed or original_was_programmed )
17911796
17921797 if not should_sync :
17931798 if not updated_has_hkr_id :
17941799 logger .debug (f"PW SYNC SKIPPED for '{ updated_project .name } ': Project has no hkrId" )
1795- elif not updated_project .programmed :
1796- logger .debug (f"PW SYNC SKIPPED for '{ updated_project .name } ': Project is not programmed" )
1800+ elif not updated_project .programmed and not original_was_programmed :
1801+ logger .debug (f"PW SYNC SKIPPED for '{ updated_project .name } ': Project is not and was not programmed" )
17971802 return
17981803
17991804 if hkr_id_added_first_time :
0 commit comments