I think I have fixed this now. I did the following:
- In the module editing form, if there is no existing completion data, it automatically 'unlocks' completion settings (meaning that completion data is recalculated when you save changes).
Previously, you got an option to unlock completion data by clicking a button, but this applied only when there was existing completion data that would potentially be lost. When there was no completion data, it remained in the 'locked' state, assuming that there was no need to update it.
- In the module edit handling code, I noticed that completion data was updated before saving the changes to the course-module object, which didn't sound like a good idea, so I moved the code slightly later.
I retested using the scenario given and it now appears to work. As previously mentioned, if you are already logged in as the user (who has now completed something), the change will not show until you log out/log in again. It shows immediately to admin, if you look at the activity completion report.
Mark: Thanks for reporting this issue!