Exemple #1
0
def route_to_budget_inspector(workitem):
    u''' Route to Budget Inspector 
        Тухайн хүсэлт дээрх төсвийн хянагчруу нь илгээнэ
    ''' 
        
    object = workitem.instance.wfobject()
    if object.budget :
        users = User.objects.filter(pk=object.budget.inspector.pk)
    elif hasattr(object,'budget_inspector') and object.budget_inspector :
        users = User.objects.filter(pk=object.budget_inspector.pk)
    else :
        users = User.objects.filter(username__iexact='sarnaitsetseg')
    
    if users :
        return users[0]
    else :
        err_msg = u'ERROR: Төсвийн хянагчыг тодорхойлж чадахгүй байна. \nТөсөв сонгогдоогүй эсвэл сонгосон төсвийн хянагч нь тодорхойгүй байна.\
            \nСистемийн админд хандана уу!'
        log.warning(err_msg)
        note = Workflow_note()
        note.user = User.objects.filter(username__iexact=u'auto').get()
        note.workitem = workitem
        note.note = err_msg
        note.submit_value = u'Захиалга унасан'
        note.save()
        object.notes.add(note)
        object.save()
        workitem.fall_out()
        return workitem.instance.user
Exemple #2
0
 def save(self, workitem=None, submit_value=None, commit=True):
     obj = super(BaseForm, self).save(commit=False)
     if submit_value != u'Хадгалах' :
         note = Workflow_note()
         note.workitem = workitem
         note.user = workitem.user
         note.note = self.cleaned_data['my_note']
         note.submit_value = submit_value
         note.save()
         obj.notes.add(note)
     obj.save()
     return obj
Exemple #3
0
    def save(self, workitem=None, submit_value=None, commit=True):
        obj = super(BaseForm, self).save(commit=False)
        obj.save()
        if submit_value != u'Хадгалах' :
            note = Workflow_note()
            note.workitem = workitem
            note.user = workitem.user
            note.note = self.cleaned_data['my_note']
            note.submit_value = submit_value
            note.save()
            obj.notes.add(note)

            if submit_value == u'Зөвшөөрөх' and obj.status == 'budget_inspect' :
                obj.status = 'new'
                obj.budget_approved_amount = obj.get_total_mnt()
                obj.budget_approved_budget = obj.budget
                consume = ProcurementConsume.objects.filter(eorder_id=obj.pk)
                if consume :
                    consume = consume[0]
                    amount = obj.get_total_mnt()
                    if consume.budget.pk != obj.budget.pk or consume.approved_amount != amount :
                        # Захиалгын төсвийг сольсон байвал өмнөх төсвөөс батлагдсан дүнг хасна.
                        #consume.budget.decrease_procurement(consume.approved_amount)
                        consume.budget = Budget.objects.get(pk=obj.budget.id)
                        # Шинэ төсвийн батлагдсан дүнг нэмнэ.
                        #consume.budget.increase_procurement(amount)
                        # Холбогдох cashflow_consume уудыг устгана.
                        #consume.remove_cashflow()
                        consume.approved_amount = amount
                    consume.eorder_no = obj.no
                    consume.approved_date = datetime.date.today()
                    consume.save()
            
            
            if submit_value == u'Буцаах' and obj.status in ('budget_inspect','new') :
                obj.status = 'cancel'
                obj.budget_approved_amount = decimal.Decimal("0.00")
                obj.budget_approved_budget = None
                
                consume = ProcurementConsume.objects.filter(eorder_id=obj.pk)
                if consume :
                    consume = consume[0]
                    consume.delete()
            if submit_value == u'Зөвшөөрөх' and obj.status == 'cancel' :
                obj.status = 'new'
        
        obj.save()
        return obj
Exemple #4
0
 def save(self, workitem=None, submit_value=None, commit=True):
     obj = super(BaseForm, self).save(commit=False)
     note = Workflow_note()
     note.workitem = workitem
     note.user = workitem.user
     note.note = self.cleaned_data['my_note']
     note.submit_value = submit_value
     log.debug('submit %s', submit_value)
     note.save()
     try :
         obj.notes.add(note)
         obj.status = 'approved'
         obj.save()
         debug("PO check form save succsess")
         
     except Exception:
         print sys.exc_info()
Exemple #5
0
 def save(self, workitem=None, submit_value=None, commit=True):
     obj = super(BaseForm, self).save(commit=False)
     obj.save()
     if submit_value != u'Хадгалах' : 
         note = Workflow_note()
         note.workitem = workitem
         note.user = workitem.user
         note.note = self.cleaned_data['my_note']
         note.submit_value = submit_value
         note.save()
         obj.notes.add(note)
         obj.status = 'prepare_procurement'
         if not obj.procurement_received :
             obj.procurement_received = datetime.date.today()
         obj.save()
         
     return obj
Exemple #6
0
 def save(self, workitem=None, submit_value=None, commit=True, user=None, data=None):
     #import copy
     #old_instance = copy.deepcopy(self.instance)
     try :
         obj = super(BaseForm, self).save(commit=False)
         if self.cleaned_data['product'] == None or self.cleaned_data['product'] == '' :
             obj.product = None
             obj.product_description = self.cleaned_data['product_description']
         
         if self.data.has_key('save_rate'): #or old_instance.currency != obj.currency :
             obj.c_rate = self.cleaned_data['currency'].last_rate()
             #print 'new obj.c_rate.rate :', obj.c_rate.rate
         if obj.currency.iso_code == 'MNT' :
             obj.c_rate = None
         
         #obj.save()
         #print submit_value
         if submit_value != u'Хадгалах' :
             if submit_value == u'Төсвийн хяналтад илгээх' :
                 obj.status = 'budget_inspect'
             #else :
                 #if submit_value not in u"Захиалга шилжүүлэх" and obj.amount() != obj.budget_approved_amount :
                  #   raise forms.ValidationError(u"Захиалгын дүн засагдсан тул төсвийн хяналтад илгээнэ үү!")
                 
             elif submit_value == u"Захиалга шилжүүлэх" :
                 obj.assigned_to = self.cleaned_data['assigned_to']
             #elif submit_value == u'Захиалга дуусгах' :
             #    obj.complete_date = datetime.date.today()
             note = Workflow_note()
             note.workitem = workitem
             note.user = workitem.user
             note.note = self.cleaned_data['my_note']
             note.submit_value = submit_value
             note.save()
             #print '184'
             obj.notes.add(note)
         
         obj.save()
         return obj
     except Exception, e:
         raise(e)
Exemple #7
0
 def save(self, workitem=None, submit_value=None, commit=True) :
     obj = super(BaseForm, self).save(commit=False)
     obj.save()
     if submit_value != u'Хадгалах' :
         note = Workflow_note()
         note.workitem = workitem
         note.user = workitem.user
         note.note = self.cleaned_data['my_note']
         note.submit_value = submit_value
         note.save()
         obj.notes.add(note)
     
         if submit_value == u'Зөвшөөрөх' and obj.status == 'budget_inspect' :
             obj.status = 'new'
             obj.budget_approved_amount = obj.get_total_mnt()
             obj.budget_approved_budget = obj.budget
             # Бэлтгэний зарцуулалтын жагсаалтад ороогүй байвал шинээр үүсгэнэ. Хэрэв уг захиалга дээр
             #     өөр төсөвөөс хасалт хийхээр тохируулагдсан байвал тэр бичлэгийг утсгана.
         
         if submit_value == u'Буцаах' and obj.status == 'budget_inspect' :
             obj.status = 'cancel'
             obj.budget_approved_amount = decimal.Decimal("0.00")
             obj.budget_approved_budget = None
             
             consume = ProcurementConsume.objects.filter(eorder_id=obj.pk)
             if consume :
                 for c in consume :
                     c.delete()
                     #for bgt in c.budget.get_parent_chain([]) :
                     #    bgt.procurement_amount -= c.approved_amount
                     #    bgt.save()
                     #for cf in c.cashflow_consumes.all() :
                     #    for bgt in c.budget.get_parent_chain([]) :
                     #        bgt.cashflow_amount -= cf.consumed_amount
                     #        bgt.save()
                     #    cf.delete()
                     
             
     obj.save()
     return obj
Exemple #8
0
def route_to_expense_acct(workitem, username='******'):
    u''' Route to Expense Accountant
    The model object should contain 'expense_accountant' field
     E-order гүй харилцагчийн төлбөрийн үед төлбөр үүсгэсэн нягтлан руу нь шиднэ.
        E-order той харилцагчийн төлбөрийн үед opex capex хяналтаас сонгогдсон зарлагын 
            нягтлан руу нь шиднэ.
    '''
    acct = None
    
    object = workitem.instance.wfobject()
    if object.category == 'MARKET' :
        acct = User.objects.filter(username__iexact=username)
        if acct :
            return acct[0]
        else :
            err_msg = u'ERROR: Зарлагын нягтланг зөв тодорхойлж чадахгүй байна. '+ \
            staff.shortname() +u' "%s" нэртэй хэрэглэгч олдохгүй байна. Системийн админд хандана уу! ' % username
            log.warning(err_msg)
            note = Workflow_note()
            note.user = User.objects.filter(username__iexact=u'auto').get()
            note.workitem = workitem
            note.note = err_msg
            note.submit_value = u'Захиалга унасан'
            note.save()
            object.notes.add(note)
            object.save()
            workitem.fall_out()
            return workitem.instance.user
    elif object.expense_accountant :
        acct = Staff.objects.get(pk=object.expense_accountant.id)
        log.debug('User %s routed to Expense accountant %s', workitem.instance.user, acct)
        if not acct :
            log.warning("Could't route the user %s to Expense accountant", workitem.instance.user)
            acct = workitem.instance.user
        return User.objects.get(pk=acct.id)
    else :
        return workitem.instance.user
Exemple #9
0
def route_to_pm(workitem):
    ''' Route to a Project Manager
    The model object should contain 'project' field
    '''
    prj = Project.objects.get(pk=workitem.instance.content_object.project.id)
    if prj.manager and Staff.objects.filter(pk=prj.manager.id, is_active=True) :
        pm = Staff.objects.get(pk=prj.manager.id, is_active=True)
        return pm
    else :
        err_msg = u'ERROR: Төслийн менежерийг зөв тодорхойлж чадахгүй байна. '+ \
        staff.shortname() +u' тухайн сонгосон төсөлд менежирийг тодорхойлоогүй байж магадгүй. \
        Системийн админд хандана уу!'
        log.warning(err_msg)
        note = Workflow_note()
        note.user = User.objects.filter(username__iexact=u'auto').get()
        note.workitem = workitem
        note.note = err_msg
        note.submit_value = u'Захиалга унасан'
        note.save()
        obj = workitem.instance.wfobject()
        obj.notes.add(note)
        obj.save()
        workitem.fall_out()
        return workitem.instance.user
Exemple #10
0
def route_to_depmgr(workitem):
    ''' Route to a Department Manager 
    '''
    try:
        staff = Staff.objects.get(pk=workitem.instance.user.id)
    except Staff.DoesNotExist:
        raise Exception(u'Системийн бус хэрэглэгч хүсэлт үүсгэсэн байна.')
    
    dept = None
    if not staff.department:
        note = Workflow_note()
        note.user = User.objects.filter(username__iexact=u'auto').get()
        note.workitem = workitem
        note.note = u'Албаны дарга захиалга үүсгэх боломжгүй.'
        note.submit_value = u'Захиалга унасан'
        note.save()
        obj = workitem.instance.wfobject() 
        obj.notes.add(note)
        obj.save()
        workitem.fall_out()
        return workitem.instance.user
    
    dept = staff.department
    depmgr = None
    if dept.manager:
        depmgr = dept.manager
    else:
        depmgr = Staff.objects.filter(department=dept, position__code_name='dep_mgr', is_active=True)
        if not depmgr :
            instance = workitem.instance
            #print "Instance Condition ", instance.condition
            
            err_msg = u'Хэлтсийн менежерийг олдохгүй байна. '+ \
            staff.shortname() +u' ажилтны хэлтсийн менежерийг сонгоогүй эсвэл байхгүй учир албаны захиралруу шууд дамжуулав. !'
            note = Workflow_note()
            div = None
            divdir = None
            if staff.department:
                div = staff.department.division
            elif staff.section:
                div = staff.section.department.division
            else:
                div = staff.division
            if div:
                if div.director:
                    divdir = div.director
                else:
                    divdir = Staff.objects.filter(division=div, position__code_name='div_dir', is_active=True)
            if not divdir :
                log.error(staff.shortname() +u"Ажилтаны албаны захиралын тодорхойлож чадсангүй")
                note.user = User.objects.filter(username__iexact=u'auto').get()
            else:
                note.user = divdir
                log.warning(err_msg)
            
            
            #note.user = User.objects.filter(username__iexact=u'auto').get()
            note.workitem = workitem
            note.note = err_msg
            if instance.condition in [None, u"Илгээх", ]:
                note.submit_value = u'Зөвшөөрөх'
            else:
                note.submit_value = instance.condition
            
            note.save()
            obj = workitem.instance.wfobject()
            obj.notes.add(note)
            obj.save()
            workitem.activate(note.user)
            
            instance.condition = note.submit_value
            instance.save()
            workitem.complete(note.user)
            
            return note.user
        
        
        depmgr = depmgr[0]
    
    log.debug('route_to_depmgr user %s Department manager %s', 
              workitem.instance.user, depmgr)
    return User.objects.get(pk=depmgr.id)
Exemple #11
0
def route_to_divdir(workitem):
    ''' Route to a Division Director
    '''
    try:
        staff = Staff.objects.get(pk=workitem.instance.user.id)
    except:
        staff = None
    # Өглөгийн нягтлан өөр албадын захирлаас сонгосон байвал 
    object = workitem.instance.wfobject()
    if object.type.abbr == 'PR' and object.category in ('CUSACCT','CUSELEC','CUSRENT','PTCPO','CUSPO') and object.other_divdir :
        log.debug('route_to_divdir Selected Division Director %s', object.other_divdir)
        return User.objects.get(pk=object.other_divdir.id)
    
    div = None
    if staff.department:
        div = staff.department.division
    elif staff.section:
        div = staff.section.department.division
    else:
        div = staff.division
    
    if not div:
        log.warning("Couldn't route from %s to Division Director", workitem.instance.user)
        note = Workflow_note()
        note.user = User.objects.filter(username__iexact=u'auto').get()
        note.workitem = workitem
        note.note = staff.shortname() + u' хэрэглэгч албаны харъяалалгүй байна Системийн админд хандана уу!.'
        note.submit_value = u'Захиалга унасан'
        note.save()
        obj = workitem.instance.wfobject() 
        obj.notes.add(note)
        obj.save()
        workitem.fall_out()
        return workitem.instance.user
    
    if div.director:
        divdir = div.director
    else:
        divdir = Staff.objects.filter(division=div, position__code_name='div_dir', is_active=True)
        if not divdir :
            err_msg = u'ERROR: Албаны захирлыг зөв тодорхойлж чадахгүй байна. '+ \
            staff.shortname() +u' ажилтны алба, хэлтсийн харъяаллыг зөв сонгоогүй эсвэл олон захирал сонгосон байж магадгүй. \
            Системийн админд хандана уу!'
            log.warning(err_msg)
            note = Workflow_note()
            note.user = User.objects.filter(username__iexact=u'auto').get()
            note.workitem = workitem
            note.note = err_msg
            note.submit_value = u'Захиалга унасан'
            note.save()
            obj = workitem.instance.wfobject()
            obj.notes.add(note)
            obj.save()
            workitem.fall_out()
            return workitem.instance.user
        divdir = divdir[0]
    
    log.debug('route_to_divdir user %s Division Director %s', workitem.instance.user, divdir)
    return User.objects.get(pk=divdir.id)