When creating a new module, there are two types of defaults for activity completion:
DEFAULT 1 (moodleform_mod.php line 651):
If the 'completiondefault' config option is set, and the module sets the 'defaultcompletion' feature, then the completion dropdown will be set to 'Automatic' provided the activity has either custom completion rules, or tracks views. If it doesn't have rules/views then the dropdown will be set to 'Manual'. If it doesn't have the feature, or the config option is unset, then the dropdown will be set to 'None'.
DEFAULT 2 (course/modlib.php prepare_new_moduleinfo_data(), line 746):
If there is an entry in course_completion_defaults for the module, it uses those settings. Otherwise it does logic quite similar to DEFAULT 1 except that it never sets automatic completion, only manual.
The system behaviour means that the code in DEFAULT 2 is always used - it looks like this was added in 3.2, so probably since then. The code in DEFAULT 1, though still present, is never actually used because the data is always set in the form.
Conclusion: To maintain current (since 3.2) behaviour and avoid confusion with code that is unused, the code about this in moodleform_mod should be removed. However, somebody might like to think about whether the behaviour about defaulting to automatic (if available), from that code, is appropriate. If so it should be moved into the newer code.
A "standard_coursemodule_elements" function generate course activity setting form including "completion". In this function set completion tracking configuration's default selection, but "$mform->set_data($data)" override this configuration without any check.
I think "standard_coursemodule_elements" function should be called in "get_moduleinfo_data".
related post: https://moodle.org/mod/forum/discuss.php?d=362529.