| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | |||
| 3 | from bika.lims import api |
||
| 4 | |||
| 5 | |||
| 6 | def ObjectEditedEventHandler(obj, event): |
||
| 7 | """Event called after modifying a ReferenceSample, that is not in the |
||
| 8 | creation stage any more. It updates the ID of the reference sample with the |
||
| 9 | value of field ManualID if valid and different from current id |
||
| 10 | """ |
||
| 11 | # compare with current id |
||
| 12 | obj_id = obj.getId() |
||
| 13 | manual_id = obj.getManualId() |
||
| 14 | if obj_id == manual_id: |
||
| 15 | return |
||
| 16 | |||
| 17 | # check if this new id is valid |
||
| 18 | parent = api.get_parent(obj) |
||
| 19 | if not api.is_valid_id(manual_id, container=parent): |
||
| 20 | return |
||
| 21 | |||
| 22 | # do not modify the id if it has objects inside |
||
| 23 | if obj.objectIds(): |
||
| 24 | return |
||
| 25 | |||
| 26 | # re-assign id and reindex |
||
| 27 | parent.manage_renameObject(obj_id, manual_id) |
||
| 28 | obj.reindexObject() |
||
| 29 |