Passed
Push — 2.x ( ee4c2a...00630e )
by Ramon
06:59
created

bika.lims.subscribers.referencesample   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A ObjectEditedEventHandler() 0 23 4
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