Esempio n. 1
0
    def synchronizeData(self, mvcsession, fieldName, fieldType):
        proxy = self.getBusinessObjectProxy()
        usrobj = proxy.getObject('USROBJ')
        glsobj = proxy.getObject('GLSOBJ')
        info = usrobj.retrieveUserInfoDict(mvcsession)
        cono = info['USRCONO']
        glopt = glsobj.getGLOpt(cono)
        if cono is None:
            cono = ''
        fields = mvcsession.entryDataset.FieldsAsDict()
        if fieldName not in ('GLARCUCD', 'GLAPCUCD'):
            fldNameAC = fieldName[:6] + 'AC'
            fldNameFM = fieldName[:6] + 'FM'
            fldNameNM = fieldName[:6] + 'NM'
            if (fields[fldNameFM] in (None, '')):
                raise Exception('Account ID must not empty')
            acct = GLACCT.stripedacct(fields[fldNameFM])
            obj = GLACCT.get((cono, acct))
            if not obj:
                raise Exception('Account ID does not exist')

            mvcsession.entryDataset.Edit()
            mvcsession.entryDataset.SetFieldValue(fldNameAC, obj.GLACACID)
            mvcsession.entryDataset.SetFieldValue(fldNameFM, obj.GLACACFM)
            mvcsession.entryDataset.SetFieldValue(fldNameNM, obj.GLACACNM)
            mvcsession.entryDataset.Post()

        return mvcsession
Esempio n. 2
0
  def openView(self, mvcsession):
    if mvcsession.paramDataset.IsEmpty:
      raise Exception('Program GLS452 could not be load directly by user')

    params = mvcsession.paramDataset.FieldsAsDict()
    proxy = self.getBusinessObjectProxy()
    usrobj = proxy.getObject('USROBJ')
    glsobj = proxy.getObject('GLSOBJ')
    info = usrobj.retrieveUserInfoDict(mvcsession)
    cono = info['USRCONO']
    glopt = glsobj.getGLOpt(cono)
    if (cono in (None, '')):
      raise Exception('Default company for user % is not assigned' % mvcsession.cookies['user_name'].encode('utf8'))

    acct = GLACCT.get((cono, params['GLRVACID']))
    if acct:
      mvcsession.paramDataset.Edit()
      mvcsession.paramDataset.SetFieldValue('GLRVACFM', acct.GLACACFM)
      mvcsession.paramDataset.SetFieldValue('GLRVACNM', acct.GLACACNM)
      mvcsession.paramDataset.Post()

    q = GLACRV.query
    q = q.filter_by(GLRVCONO = cono)
    q = q.filter_by(GLRVACID = params['GLRVACID'])
    q = q.order_by(sa.asc(GLACRV.GLRVCONO))
    q = q.order_by(sa.asc(GLACRV.GLRVACID))
    q = q.order_by(sa.asc(GLACRV.GLRVCUCD))
    obj = q.all()
    mvcsession.listDataset.CopyFromORMList(
      'GLRVCUCD;GLRVCUNM;GLRVRVST;GLRVRVNM',
      'GLRVCUCD;GLRVCUNM;GLRVRVST;GLRVRVNM',
      obj
      )
    return mvcsession
Esempio n. 3
0
 def acctexists(self, cono, acct):
     ret = [False, None]
     q = GLACCT.query.filter_by(GLACCONO=cono)
     q = q.filter_by(GLACACID=acct)
     obj = q.filter_by(GLACACST=1).first()
     if (obj is not None):
         ret[0] = True
         ret[1] = GLACCT.formatacct(cono, obj.GLACSTID, acct)
     return tuple(ret)
Esempio n. 4
0
    def verifyYearEnd(self):
        if self.info_dict['glopt'].GLOPCLCD in (None, ''):
            raise Exception(
                'Default closing account has not been setup properly')
        acctid = GLACCT.stripedacct(self.info_dict['glopt'].GLOPCLCD)
        closacct = GLACCT.get((self.info_dict['cono'], acctid))
        if not closacct:
            raise Exception('Default closing account is not found')
        if closacct.GLACACST == 0:
            raise Exception('Default closing account is disabled')
        if closacct.GLACACTP != 'R':
            raise Exception(
                'Default closing account is not on Retained Earnings type')
        self.info_dict['clossing_acct'] = closacct

        #check next fiscal yr
        q = CSYFSC.query
        q = q.filter_by(SYFSFSTP=self.info_dict['fstp'])
        q = q.filter(CSYFSC.SYFSFSYR > self.info_dict['fsyr'])
        nfsyr = q.first()
        if not nfsyr:
            raise Exception('Next fiscal year has not been created')

        self.info_dict['nfsyr'] = nfsyr.SYFSFSYR
Esempio n. 5
0
  def retrieveData(self, mvcsession):
    lists = mvcsession.listDataset.FieldsAsDict()
    params = mvcsession.paramDataset.FieldsAsDict()
    proxy = self.getBusinessObjectProxy()
    usrobj = proxy.getObject('USROBJ')
    glsobj = proxy.getObject('GLSOBJ')
    info = usrobj.retrieveUserInfoDict(mvcsession)
    cono = info['USRCONO']
    glopt = glsobj.getGLOpt(cono)
    if (cono in (None, '')):
      raise Exception('Default company for user % is not assigned' % mvcsession.cookies['user_name'].encode('utf8'))

    if mvcsession.execType in (MVCExecAppend, MVCExecCopy):
      acctid = GLACCT.get((cono, params['GLALACID']))
      if not acctid:
        raise Exception('Master account is not found')
      if acctid.GLACALST != 1:
        raise Exception('Master account is not marked to use allocation')

    if mvcsession.execType in (MVCExecShow, MVCExecEdit, MVCExecDelete, MVCExecCopy):
      q = GLALAC.query
      q = q.filter_by(GLALCONO = cono)
      q = q.filter_by(GLALACID = params['GLALACID'])
      q = q.filter_by(GLALALID = lists['GLALALID'])
      obj = q.first()

      if (mvcsession.execType != MVCExecCopy):
        mvcsession.entryDataset.CopyFromORM(
          'GLALALFM;GLALALNM;GLALALRF;GLALALPC',
          'GLALALFM;GLALALNM;GLALALRF;GLALALPC',
          obj)
      else:
        mvcsession.entryDataset.CopyFromORM(
          'GLALALRF;GLALALPC',
          'GLALALRF;GLALALPC',
          obj)

    if mvcsession.execType == MVCExecEdit:
      mvcsession.fieldDefs.GLALALFM.enabled = False

    return mvcsession
Esempio n. 6
0
  def retrieveData(self, mvcsession):
    lists = mvcsession.listDataset.FieldsAsDict()
    params = mvcsession.paramDataset.FieldsAsDict()
    proxy = self.getBusinessObjectProxy()
    usrobj = proxy.getObject('USROBJ')
    glsobj = proxy.getObject('GLSOBJ')
    info = usrobj.retrieveUserInfoDict(mvcsession)
    cono = info['USRCONO']
    glopt = glsobj.getGLOpt(cono)
    if (cono in (None, '')):
      raise Exception('Default company for user % is not assigned' % mvcsession.cookies['user_name'].encode('utf8'))

    if mvcsession.execType in (MVCExecAppend, MVCExecCopy):
      acctid = GLACCT.get((cono, params['GLRVACID']))
      if not acctid:
        raise Exception('Master account is not found')

      mvcsession.entryDataset.Edit()
      mvcsession.entryDataset.SetFieldValue('GLRVRVST', 0)
      mvcsession.entryDataset.Post()

    if mvcsession.execType in (MVCExecShow, MVCExecEdit, MVCExecDelete, MVCExecCopy):
      obj = GLACRV.get((cono, params['GLRVACID'], lists['GLRVCUCD']))

      if (mvcsession.execType != MVCExecCopy):
        mvcsession.entryDataset.CopyFromORM(
          'GLRVCUCD;GLRVCUNM;GLRVRVST;GLRVRVNM',
          'GLRVCUCD;GLRVCUNM;GLRVRVST;GLRVRVNM',
          obj)
      else:
        mvcsession.entryDataset.CopyFromORM(
          'GLRVRVST;GLRVRVNM',
          'GLRVRVST;GLRVRVNM',
          obj)

    if mvcsession.execType == MVCExecEdit:
      mvcsession.fieldDefs.GLRVCUCD.enabled = False

    return mvcsession
Esempio n. 7
0
    def do_updateRetEarnItm(self):
        rearnsumrz = {}
        for name, item in self.ret_earningcl.iteritems():
            acctid = GLACCT.stripedacct(name)
            acct = GLACCT.get((self.info_dict['cono'], acctid))
            if not acct:
                raise Exception('Clossing account %s is lost' % acct)

            td = dt.datetime.today()
            # ret earning does not have allocation
            if (acct.GLACALST == 0):
                for curtp, infoitem in item.iteritems():
                    smrz = GLSMRZ.get((self.info_dict['cono'], acct.GLACACID, \
                            self.info_dict['fstp'], self.info_dict['fsyr'],
                            1, infoitem[0], infoitem[1]))
                    if smrz:
                        end_bal = self.get_EndBalance(smrz)
                    else:
                        dcm.getcontext().prec = 9
                        end_bal = (dcm.Decimal(0, CurrencyContext),
                                   dcm.Decimal(0, CurrencyContext),
                                   dcm.Decimal(0, CurrencyContext))

                    if not rearnsumrz.has_key(
                            '%s_%s_%s' %
                        (acct.GLACACID, infoitem[0], infoitem[1])):
                        rearnsumrz['%s_%s_%s' % (acct.GLACACID, infoitem[0],
                                                 infoitem[1])] = [False, None]
                    rsmrz = rearnsumrz['%s_%s_%s' % (acct.GLACACID,
                                                     infoitem[0], infoitem[1])]
                    if not rsmrz[1]:
                        update_only = True
                        nsmrz = GLSMRZ.get((self.info_dict['cono'], acct.GLACACID, \
                                self.info_dict['fstp'], self.info_dict['nfsyr'],
                                1, infoitem[0], infoitem[1]))
                        if not nsmrz:
                            update_only = False
                            nsmrz = GLSMRZ()
                            nsmrz.GLSMCONO = self.info_dict['cono']
                            nsmrz.GLSMACID = acct.GLACACID
                            nsmrz.GLSMFSTP = self.info_dict['fstp']
                            nsmrz.GLSMFSYR = self.info_dict['nfsyr']
                            nsmrz.GLSMSMTP = 1
                            nsmrz.GLSMCUCD = infoitem[0]
                            nsmrz.GLSMCUTP = infoitem[1]
                            nsmrz.GLNTOPBL = dcm.Decimal(0, CurrencyContext)
                            nsmrz.GLCROPBL = dcm.Decimal(0, CurrencyContext)
                            nsmrz.GLDBOPBL = dcm.Decimal(0, CurrencyContext)

                        rsmrz[0] = update_only
                        rsmrz[1] = nsmrz

                    nsmrz = rsmrz[1]
                    dcm.getcontext().prec = 9
                    nsmrz.GLNTOPBL = dcm.Decimal(end_bal[0] + infoitem[3],
                                                 CurrencyContext)
                    nsmrz.GLCROPBL = dcm.Decimal(end_bal[1] + infoitem[4],
                                                 CurrencyContext)
                    nsmrz.GLDBOPBL = dcm.Decimal(end_bal[2] + infoitem[5],
                                                 CurrencyContext)
                    nsmrz.GLSMAUDT = td.date().tointeger()
                    nsmrz.GLSMAUTM = td.time().tointeger()
                    nsmrz.GLSMAUUS = self.info_dict['usr_info'][3]

            # ret earning does have allocation accounts
            elif (acct.GLACALST == 1):
                alaccts = GLALAC.getObj(True, GLALCONO = acct.GLACCONO, \
                  GLALACID = acct.GLACACID)
                for alacct in alaccts:
                    _alacct = GLACCT.stripedacct(alacct.GLALALID)
                    if not GLACCT.acctexists(acct.GLACCONO, _alacct)[0]:
                        raise Exception('Allocation account %s is not found' %
                                        alacct.GLALALID)

                    for curtp, infoitem in item.iteritems():
                        smrz = GLSMRZ.get((self.info_dict['cono'], _alacct, \
                              self.info_dict['fstp'], self.info_dict['fsyr'],
                              1, infoitem[0], infoitem[1]))
                        if smrz:
                            end_bal = self.get_EndBalance(smrz)
                        else:
                            dcm.getcontext().prec = 9
                            end_bal = (dcm.Decimal(0, CurrencyContext),
                                       dcm.Decimal(0, CurrencyContext),
                                       dcm.Decimal(0, CurrencyContext))

                        if not rearnsumrz.has_key(
                                '%s_%s_%s' %
                            (_alacct, infoitem[0], infoitem[1])):
                            rearnsumrz['%s_%s_%s' %
                                       (_alacct, infoitem[0], infoitem[1])] = [
                                           False, None
                                       ]
                        rsmrz = rearnsumrz['%s_%s_%s' %
                                           (_alacct, infoitem[0], infoitem[1])]
                        if not rsmrz[1]:
                            update_only = True
                            nsmrz = GLSMRZ.get((self.info_dict['cono'], _alacct, \
                                    self.info_dict['fstp'], self.info_dict['nfsyr'],
                                    1, infoitem[0], infoitem[1]))
                            if not nsmrz:
                                update_only = False
                                nsmrz = GLSMRZ()
                                nsmrz.GLSMCONO = self.info_dict['cono']
                                nsmrz.GLSMACID = _alacct
                                nsmrz.GLSMFSTP = self.info_dict['fstp']
                                nsmrz.GLSMFSYR = self.info_dict['nfsyr']
                                nsmrz.GLSMSMTP = 1
                                nsmrz.GLSMCUCD = infoitem[0]
                                nsmrz.GLSMCUTP = infoitem[1]
                                nsmrz.GLNTOPBL = dcm.Decimal(
                                    0, CurrencyContext)
                                nsmrz.GLCROPBL = dcm.Decimal(
                                    0, CurrencyContext)
                                nsmrz.GLDBOPBL = dcm.Decimal(
                                    0, CurrencyContext)

                            rsmrz[0] = update_only
                            rsmrz[1] = nsmrz

                        nsmrz = rsmrz[1]
                        dcm.getcontext().prec = 9
                        alcuam = (dcm.Decimal(infoitem[3]) * dcm.Decimal(
                            alacct.GLALALPC)) / dcm.Decimal(100)
                        alcucr = (dcm.Decimal(infoitem[4]) * dcm.Decimal(
                            alacct.GLALALPC)) / dcm.Decimal(100)
                        alcudb = (dcm.Decimal(infoitem[5]) * dcm.Decimal(
                            alacct.GLALALPC)) / dcm.Decimal(100)
                        nsmrz.GLNTOPBL = dcm.Decimal(end_bal[0] + alcuam,
                                                     CurrencyContext)
                        nsmrz.GLCROPBL = dcm.Decimal(end_bal[1] + alcucr,
                                                     CurrencyContext)
                        nsmrz.GLDBOPBL = dcm.Decimal(end_bal[2] + alcudb,
                                                     CurrencyContext)
                        nsmrz.GLSMAUDT = td.date().tointeger()
                        nsmrz.GLSMAUTM = td.time().tointeger()
                        nsmrz.GLSMAUUS = self.info_dict['usr_info'][3]

        for name, item in rearnsumrz.iteritems():
            if item[0] == True:
                self.session.update(item[1])
            else:
                self.session.save(item[1])
Esempio n. 8
0
    def do_updateRetEarning(self):
        acct = self.info_dict['clossing_acct']
        if not acct:
            raise Exception('Clossing account is lost')

        td = dt.datetime.today()
        # ret earning does not have allocation
        if (acct.GLACALST == 0):
            for name, item in self.ret_earning.iteritems():
                smrz = GLSMRZ.get((self.info_dict['cono'], acct.GLACACID, \
                        self.info_dict['fstp'], self.info_dict['fsyr'],
                        1, item[0], item[1]))
                if smrz:
                    end_bal = self.get_EndBalance(smrz)
                else:
                    dcm.getcontext().prec = 9
                    end_bal = (dcm.Decimal(0, CurrencyContext),
                               dcm.Decimal(0, CurrencyContext),
                               dcm.Decimal(0, CurrencyContext))

                update_only = True
                nsmrz = GLSMRZ.get((self.info_dict['cono'], acct.GLACACID, \
                        self.info_dict['fstp'], self.info_dict['nfsyr'],
                        1, item[0], item[1]))
                if not nsmrz:
                    update_only = False
                    nsmrz = GLSMRZ()
                    nsmrz.GLSMCONO = self.info_dict['cono']
                    nsmrz.GLSMACID = acct.GLACACID
                    nsmrz.GLSMFSTP = self.info_dict['fstp']
                    nsmrz.GLSMFSYR = self.info_dict['nfsyr']
                    nsmrz.GLSMSMTP = 1
                    nsmrz.GLSMCUCD = item[0]
                    nsmrz.GLSMCUTP = item[1]
                    nsmrz.GLNTOPBL = dcm.Decimal(0, CurrencyContext)
                    nsmrz.GLCROPBL = dcm.Decimal(0, CurrencyContext)
                    nsmrz.GLDBOPBL = dcm.Decimal(0, CurrencyContext)

                dcm.getcontext().prec = 9
                nsmrz.GLNTOPBL = dcm.Decimal(end_bal[0] + item[2],
                                             CurrencyContext)
                nsmrz.GLCROPBL = dcm.Decimal(end_bal[1] + item[3],
                                             CurrencyContext)
                nsmrz.GLDBOPBL = dcm.Decimal(end_bal[2] + item[4],
                                             CurrencyContext)
                nsmrz.GLSMAUDT = td.date().tointeger()
                nsmrz.GLSMAUTM = td.time().tointeger()
                nsmrz.GLSMAUUS = self.info_dict['usr_info'][3]

                if update_only:
                    self.session.update(nsmrz)
                else:
                    self.session.save(nsmrz)

        # ret earning does have allocation accounts
        elif (acct.GLACALST == 1):
            alaccts = GLALAC.getObj(True, GLALCONO = acct.GLACCONO, \
              GLALACID = acct.GLACACID)
            for alacct in alaccts:
                _alacct = GLACCT.stripedacct(alacct.GLALALID)
                if not GLACCT.acctexists(acct.GLACCONO, _alacct)[0]:
                    raise Exception('Allocation account %s is not found' %
                                    alacct.GLALALID)

                for name, item in self.ret_earning.iteritems():
                    smrz = GLSMRZ.get((self.info_dict['cono'], _alacct, \
                          self.info_dict['fstp'], self.info_dict['fsyr'],
                          1, item[0], item[1]))
                    if smrz:
                        end_bal = self.get_EndBalance(smrz)
                    else:
                        dcm.getcontext().prec = 9
                        end_bal = (dcm.Decimal(0, CurrencyContext),
                                   dcm.Decimal(0, CurrencyContext),
                                   dcm.Decimal(0, CurrencyContext))

                    update_only = True
                    nsmrz = GLSMRZ.get((self.info_dict['cono'], _alacct, \
                            self.info_dict['fstp'], self.info_dict['nfsyr'],
                            1, item[0], item[1]))
                    if not nsmrz:
                        update_only = False
                        nsmrz = GLSMRZ()
                        nsmrz.GLSMCONO = self.info_dict['cono']
                        nsmrz.GLSMACID = _alacct
                        nsmrz.GLSMFSTP = self.info_dict['fstp']
                        nsmrz.GLSMFSYR = self.info_dict['nfsyr']
                        nsmrz.GLSMSMTP = 1
                        nsmrz.GLSMCUCD = item[0]
                        nsmrz.GLSMCUTP = item[1]
                        nsmrz.GLNTOPBL = dcm.Decimal(0, CurrencyContext)
                        nsmrz.GLCROPBL = dcm.Decimal(0, CurrencyContext)
                        nsmrz.GLDBOPBL = dcm.Decimal(0, CurrencyContext)

                    dcm.getcontext().prec = 9
                    alcuam = (dcm.Decimal(item[2]) *
                              dcm.Decimal(alacct.GLALALPC)) / dcm.Decimal(100)
                    alcucr = (dcm.Decimal(item[3]) *
                              dcm.Decimal(alacct.GLALALPC)) / dcm.Decimal(100)
                    alcudb = (dcm.Decimal(item[4]) *
                              dcm.Decimal(alacct.GLALALPC)) / dcm.Decimal(100)
                    nsmrz.GLNTOPBL = dcm.Decimal(end_bal[0] + alcuam,
                                                 CurrencyContext)
                    nsmrz.GLCROPBL = dcm.Decimal(end_bal[1] + alcucr,
                                                 CurrencyContext)
                    nsmrz.GLDBOPBL = dcm.Decimal(end_bal[2] + alcudb,
                                                 CurrencyContext)
                    nsmrz.GLSMAUDT = td.date().tointeger()
                    nsmrz.GLSMAUTM = td.time().tointeger()
                    nsmrz.GLSMAUUS = self.info_dict['usr_info'][3]

                    if update_only:
                        self.session.update(nsmrz)
                    else:
                        self.session.save(nsmrz)
Esempio n. 9
0
    def postData(self, mvcsession):
        fields = mvcsession.entryDataset.FieldsAsDict()
        params = mvcsession.paramDataset.FieldsAsDict()
        validators.NotEmpty(messages={
            'empty': 'Acct code must not empty'
        }).to_python(fields['GLJIACFM'])
        validators.NotEmpty(messages={
            'empty': 'Nominal amount must not empty'
        }).to_python(fields['GLJITRAM'])

        proxy = self.getBusinessObjectProxy()
        usrobj = proxy.getObject('USROBJ')
        glsobj = proxy.getObject('GLSOBJ')
        info = usrobj.retrieveUserInfoDict(mvcsession)
        cono = info['USRCONO']
        glopt = glsobj.getGLOpt(cono)

        bcid = None
        if params['GLJIBCID'] not in (None, ''):
            bctl = GLBCTL.getObj(False,
                                 GLBCCONO=cono,
                                 GLBCNOID=glopt['GLOPBCNO'],
                                 GLBCLSID=params['GLJIBCID'])
            if not bctl:
                raise Exception('Batch no %s could not be found')
        else:
            raise Exception('Batch No. could not be retrieved')

        jhdr = GLJHDR.getObj(False,
                             GLJHCONO=cono,
                             GLJHNOID=glopt['GLOPBCNO'],
                             GLJHBCID=int(params['GLJIBCID']),
                             GLJHJEID=int(params['GLJIJEID']))
        if not jhdr:
            raise Exception('Could not find header transaction')

        td = dt.datetime.now()
        if (mvcsession.execType in (MVCExecAppend, MVCExecCopy)):
            if jhdr.GLJHJEST == 2:
                raise Exception(
                    'No modification allowed for this kind of journal')
            # batch status not in (Open, ERROR)
            if bctl.GLBCBCST not in (1, 5):
                raise Exception(
                    'Could not create a new transaction for this batch %s ' %
                    params['GLJIBCID'])

            lsno = GLJITM.getTRNO(jhdr)
            acct = GLACCT.stripedacct(fields['GLJIACFM'])

            splitted = GLSRCE.expandSourceCode(fields['GLJISRCL'])
            glsrc = GLSRCE.get(splitted[2])
            if not glsrc:
                raise Exception('G/L Source code is undefined')

            rate_date = None
            if fields['GLJICSCD'] != fields['GLJICHCD']:
                validators.NotEmpty(messages={
                    'empty': 'rate date must not empty'
                }).to_python(fields['GLJIRTDT'])
                crextp = MSTCRT.get((fields['GLJICSCD'], fields['GLJICRTP']))
                if not crextp:
                    raise Exception(
                        'No exchange rate definition found for combination of currency and rate type used'
                    )

                currat = CURRAT.getRateDate(crextp, fields['GLJICHCD'], \
                          fields['GLJIRTDT'].date().tointeger())
                if not currat:
                    raise Exception(
                        'Could not find currency rate for selected date')

                rate_date = fields['GLJIRTDT'].date().tointeger()

            rec = GLJITM(
                GLJICONO=cono,
                GLJINOID=glopt['GLOPBCNO'],
                GLJIBCID=int(params['GLJIBCID']),
                GLJIJEID=int(params['GLJIJEID']),
                GLJITRID=lsno[0],
                GLJITRDT=fields['GLJITRDT'].date().tointeger(),
                GLJITRDS=fields['GLJITRDS'],
                GLJITRRF=fields['GLJITRRF'],
                GLJISQNO=fields['GLJISQNO'],
                GLJIACID=acct,
                GLJIACFM=fields['GLJIACFM'],
                GLJIACNM=fields['GLJIACNM'],
                GLJITRTP=fields['GLJITRTP'],
                GLJISRLG=fields['GLJISRLG'],
                GLJISRTP=fields['GLJISRTP'],
                GLJICHCD=fields['GLJICHCD'],
                GLJICSCD=fields['GLJICSCD'],
                GLJICRTP=fields['GLJICRTP'],
                GLJIRTOP=fields['GLJIRTOP'],
                GLJIDTMT=fields['GLJIDTMT'],
                GLJIRTDT=rate_date,
                GLJIRCVL=fields['GLJIRCVL'],
                GLJIRTVL=fields['GLJIRTVL'],
                GLJIRTSP=fields['GLJIRTSP'],
                GLJIAUDT=td.date().tointeger(),
                GLJIAUTM=td.time().tointeger(),
                GLJIAUUS=mvcsession.cookies['user_name'].encode('utf8'))

            dcm.getcontext().prec = 9
            amount = dcm.Decimal(fields['GLJITRAM'], CurrencyContext)
            if amount < dcm.Decimal(0):
                amount = dcm.Decimal(
                    fields['GLJITRAM'] * dcm.Decimal(-1, CurrencyContext),
                    CurrencyContext)
            amountcr = dcm.Decimal(amount * dcm.Decimal(-1, CurrencyContext),
                                   CurrencyContext)

            namount = dcm.Decimal(0, CurrencyContext)
            if fields['GLJICSCD'] == fields['GLJICHCD']:
                namount = amount
            else:
                if fields['GLJIRTVL']:
                    deviation = dcm.Decimal(
                        fields['GLJIRTVL'], CurrencyContext) - dcm.Decimal(
                            fields['GLJIRCVL'], CurrencyContext)
                    if (abs(deviation) > fields['GLJIRTSP']):
                        raise Exception(
                            'Currency rate out of it\'s maximum spread allowed'
                        )
                    if fields['GLJIRTOP'] == '*':
                        namount = amount * dcm.Decimal(fields['GLJIRTVL'])
                    elif fields['GLJIRTOP'] == '/':
                        divider = dcm.Decimal(fields['GLJIRTVL'])
                        if divider <> dcm.Decimal(0):
                            namount = amount / divider
            namountcr = dcm.Decimal(namount * dcm.Decimal(-1, CurrencyContext),
                                    CurrencyContext)

            if rec.GLJITRTP == 1:
                rec.GLJITRDB = amount
                rec.GLJITRAM = amount
                rec.GLJITRCR = dcm.Decimal(0, CurrencyContext)
                rec.GLJICUAM = namount
                rec.GLJICUDB = namount
                rec.GLJICUCR = dcm.Decimal(0, CurrencyContext)
            else:
                rec.GLJITRCR = amount
                rec.GLJITRAM = amountcr
                rec.GLJITRDB = dcm.Decimal(0, CurrencyContext)
                rec.GLJICUAM = namountcr
                rec.GLJICUCR = namount
                rec.GLJICUDB = dcm.Decimal(0, CurrencyContext)

            bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                        CurrencyContext) - jhdr.GLJHNTDB
            bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                        CurrencyContext) - jhdr.GLJHNTCR

            jhdr.GLJHNTDB = dcm.Decimal(jhdr.GLJHNTDB,
                                        CurrencyContext) + rec.GLJITRDB
            jhdr.GLJHNTCR = dcm.Decimal(jhdr.GLJHNTCR,
                                        CurrencyContext) + rec.GLJITRCR

            bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                        CurrencyContext) + jhdr.GLJHNTDB
            bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                        CurrencyContext) + jhdr.GLJHNTCR

            if not session.transaction_started():
                session.begin()
            try:
                session.save(rec)
                session.update(jhdr)
                session.update(bctl)
                session.commit()
            except:
                session.clear()
                session.rollback()
                raise

        if (mvcsession.execType in (MVCExecEdit, MVCExecDelete)):
            # batch status not in (Open, ERROR)
            if bctl.GLBCBCST not in (1, 4, 5):
                raise Exception(
                    'Could not change transaction on this batch %s ' %
                    params['GLJIBCID'])

            jitm = GLJITM.getObj(False,
                                 GLJICONO=cono,
                                 GLJINOID=glopt['GLOPBCNO'],
                                 GLJIBCID=int(params['GLJIBCID']),
                                 GLJIJEID=int(params['GLJIJEID']),
                                 GLJITRID=fields['GLJITRID'])
            if not jitm:
                raise Exception(
                    'Transaction could not be find on the database')

            if (mvcsession.execType == MVCExecEdit):
                if jhdr.GLJHJEST == 2:
                    raise Exception(
                        'No modification allowed for this kind of journal')
                rate_date = None
                if fields['GLJICSCD'] != fields['GLJICHCD']:
                    crextp = MSTCRT.get(
                        (fields['GLJICSCD'], fields['GLJICRTP']))
                    if not crextp:
                        raise Exception(
                            'No exchange rate definition found for combination of currency and rate type used'
                        )

                    currat = CURRAT.getRateDate(crextp, fields['GLJICHCD'], \
                              fields['GLJIRTDT'].date().tointeger())
                    if not currat:
                        raise Exception(
                            'Could not find currency rate for selected date')

                    rate_date = fields['GLJIRTDT'].date().tointeger()

                splitted = GLSRCE.expandSourceCode(fields['GLJISRCL'])
                glsrc = GLSRCE.get(splitted[2])
                if not glsrc:
                    raise Exception('G/L Source code is undefined')

                dcm.getcontext().prec = 9
                amount = dcm.Decimal(fields['GLJITRAM'], CurrencyContext)
                if amount < dcm.Decimal(0):
                    amount = dcm.Decimal(
                        amount * dcm.Decimal(-1, CurrencyContext),
                        CurrencyContext)
                amountcr = dcm.Decimal(
                    amount * dcm.Decimal(-1, CurrencyContext), CurrencyContext)

                namount = dcm.Decimal(0, CurrencyContext)
                if fields['GLJICSCD'] == fields['GLJICHCD']:
                    namount = amount
                else:
                    if fields['GLJIRTVL']:
                        deviation = dcm.Decimal(
                            fields['GLJIRTVL'], CurrencyContext) - dcm.Decimal(
                                fields['GLJIRCVL'], CurrencyContext)
                        if (abs(deviation) > fields['GLJIRTSP']):
                            raise Exception(
                                'Currency rate out of it\'s maximum spread allowed'
                            )
                        if fields['GLJIRTOP'] == '*':
                            namount = amount * dcm.Decimal(fields['GLJIRTVL'])
                        elif fields['GLJIRTOP'] == '/':
                            divider = dcm.Decimal(fields['GLJIRTVL'])
                            if divider <> dcm.Decimal(0):
                                namount = amount / divider
                namountcr = dcm.Decimal(
                    namount * dcm.Decimal(-1, CurrencyContext),
                    CurrencyContext)

                bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                            CurrencyContext) - jhdr.GLJHNTDB
                bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                            CurrencyContext) - jhdr.GLJHNTCR

                jhdr.GLJHNTDB = dcm.Decimal(jhdr.GLJHNTDB,
                                            CurrencyContext) - jitm.GLJITRDB
                jhdr.GLJHNTCR = dcm.Decimal(jhdr.GLJHNTCR,
                                            CurrencyContext) - jitm.GLJITRCR

                if fields['GLJITRTP'] == 1:
                    jitm.GLJITRDB = amount
                    jitm.GLJITRAM = amount
                    jitm.GLJITRCR = dcm.Decimal(0, CurrencyContext)
                    jitm.GLJICUDB = namount
                    jitm.GLJICUAM = namount
                    jitm.GLJICUCR = dcm.Decimal(0, CurrencyContext)
                else:
                    jitm.GLJITRCR = amount
                    jitm.GLJITRAM = amountcr
                    jitm.GLJITRDB = dcm.Decimal(0, CurrencyContext)
                    jitm.GLJICUCR = namount
                    jitm.GLJICUAM = namountcr
                    jitm.GLJICUDB = dcm.Decimal(0, CurrencyContext)

                jhdr.GLJHNTDB = dcm.Decimal(jhdr.GLJHNTDB,
                                            CurrencyContext) + jitm.GLJITRDB
                jhdr.GLJHNTCR = dcm.Decimal(jhdr.GLJHNTCR,
                                            CurrencyContext) + jitm.GLJITRCR

                bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                            CurrencyContext) + jhdr.GLJHNTDB
                bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                            CurrencyContext) + jhdr.GLJHNTCR

                acct = GLACCT.stripedacct(fields['GLJIACFM'])
                jitm.GLJITRDS = fields['GLJITRDS']
                jitm.GLJITRRF = fields['GLJITRRF']
                jitm.GLJISQNO = fields['GLJISQNO']
                jitm.GLJIACID = acct
                jitm.GLJIACFM = fields['GLJIACFM']
                jitm.GLJIACNM = fields['GLJIACNM']
                jitm.GLJISRLG = fields['GLJISRLG']
                jitm.GLJISRTP = fields['GLJISRTP']
                jitm.GLJITRTP = fields['GLJITRTP']
                jitm.GLJISRLG = fields['GLJISRLG']
                jitm.GLJISRTP = fields['GLJISRTP']
                jitm.GLJITRDT = fields['GLJITRDT'].date().tointeger()
                jitm.GLJICHCD = fields['GLJICHCD']
                jitm.GLJICSCD = fields['GLJICSCD']
                jitm.GLJICRTP = fields['GLJICRTP']
                jitm.GLJIRTOP = fields['GLJIRTOP']
                jitm.GLJIDTMT = fields['GLJIDTMT']
                jitm.GLJIRTDT = rate_date
                jitm.GLJIRTVL = fields['GLJIRTVL']
                jitm.GLJIRTSP = fields['GLJIRTSP']
                jitm.GLJIAUDT = td.date().tointeger()
                jitm.GLJIAUTM = td.time().tointeger()
                jitm.GLJIAUUS = mvcsession.cookies['user_name'].encode('utf8')

                if not session.transaction_started():
                    session.begin()
                try:
                    session.update(jitm)
                    session.update(jhdr)
                    session.update(bctl)
                    session.commit()
                except:
                    session.clear()
                    session.rollback()
                    raise

            if (mvcsession.execType == MVCExecDelete):
                dcm.getcontext().prec = 9
                bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                            CurrencyContext) - jhdr.GLJHNTDB
                bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                            CurrencyContext) - jhdr.GLJHNTCR

                jhdr.GLJHNTDB = dcm.Decimal(jhdr.GLJHNTDB,
                                            CurrencyContext) - jitm.GLJITRDB
                jhdr.GLJHNTCR = dcm.Decimal(jhdr.GLJHNTCR,
                                            CurrencyContext) - jitm.GLJITRCR

                bctl.GLBCNTDB = dcm.Decimal(bctl.GLBCNTDB,
                                            CurrencyContext) + jhdr.GLJHNTDB
                bctl.GLBCNTCR = dcm.Decimal(bctl.GLBCNTCR,
                                            CurrencyContext) + jhdr.GLJHNTCR

                if not session.transaction_started():
                    session.begin()
                try:
                    session.delete(jitm)
                    session.update(jhdr)
                    session.update(bctl)
                    session.commit()
                except:
                    session.clear()
                    session.rollback()
                    raise
        return mvcsession
Esempio n. 10
0
    def synchronizeData(self, mvcsession, fieldName, fieldType):
        fields = mvcsession.entryDataset.FieldsAsDict()
        params = mvcsession.paramDataset.FieldsAsDict()
        proxy = self.getBusinessObjectProxy()
        usrobj = proxy.getObject('USROBJ')
        glsobj = proxy.getObject('GLSOBJ')
        info = usrobj.retrieveUserInfoDict(mvcsession)
        cono = info['USRCONO']
        glopt = glsobj.getGLOpt(cono)
        if (fieldName == 'GLJISRCL'):
            splitted = GLSRCE.expandSourceCode(fields['GLJISRCL'])
            glsrc = GLSRCE.get(splitted[2])
            if not glsrc:
                raise Exception('G/L Source code is undefined')

            mvcsession.entryDataset.Edit()
            mvcsession.entryDataset.SetFieldValue('GLJISRLG', splitted[0])
            mvcsession.entryDataset.SetFieldValue('GLJISRTP', splitted[1])
            mvcsession.entryDataset.Post()

        if (fieldName == 'GLJIACFM'):
            if (fields['GLJIACFM'] in (None, '')):
                raise Exception('Account ID must not empty')

            acct = GLACCT.stripedacct(fields['GLJIACFM'])
            q = GLACCT.query.filter_by(GLACCONO=cono)
            obj = q.filter_by(GLACACID=acct).first()
            if not obj:
                raise Exception('Account ID does not exist')

            if obj.GLACBLTP == 'D':
                trtp = 1
            else:
                trtp = 2

            mvcsession.entryDataset.Edit()
            mvcsession.entryDataset.SetFieldValue('GLJIACFM', obj.GLACACFM)
            mvcsession.entryDataset.SetFieldValue('GLJIACNM', obj.GLACACNM)
            mvcsession.entryDataset.SetFieldValue('GLJITRTP', trtp)
            mvcsession.entryDataset.Post()

        if (fieldName == 'GLJITRAM'):
            dcm.getcontext().prec = 9
            amount = dcm.Decimal(fields['GLJITRAM'], CurrencyContext)
            if amount < dcm.Decimal(0):
                amount = dcm.Decimal(
                    fields['GLJITRAM'] * dcm.Decimal(-1, CurrencyContext),
                    CurrencyContext)

            mvcsession.entryDataset.Edit()
            mvcsession.entryDataset.SetFieldValue('GLJITRAM', amount)
            mvcsession.entryDataset.Post()

        if (fieldName in ('GLJITRAM', 'GLJICHCD', 'GLJICRTP', 'GLJIRTDT')):

            if (fields['GLJICSCD'] not in (None, '')) and \
               (fields['GLJICRTP'] not in (None, '')):
                crextp = MSTCRT.get((fields['GLJICSCD'], fields['GLJICRTP']))
                if not crextp:
                    raise Exception(
                        'No exchange rate definition found for combination of currency and rate type used'
                    )

                mvcsession.entryDataset.Edit()
                mvcsession.entryDataset.SetFieldValue('GLJIRTOP',
                                                      crextp.CMCTRTOP)
                mvcsession.entryDataset.SetFieldValue('GLJIDTMT',
                                                      crextp.CMCTDTMT)
                mvcsession.entryDataset.Post()

            if (fields['GLJICHCD'] not in (None, '')) and \
               (fields['GLJICRTP'] not in (None, '')) and \
               (fields['GLJIRTDT'] not in (None, '')) and \
               (fields['GLJICSCD'] not in (None, '')):

                currat = CURRAT.getRateDate(crextp, fields['GLJICHCD'], \
                            fields['GLJIRTDT'].date().tointeger())
                if not currat:
                    raise Exception(
                        'Could not find currency rate for selected date')

                mvcsession.entryDataset.Edit()
                mvcsession.entryDataset.SetFieldValue('GLJIRCVL',
                                                      currat.CRRTRTVL)
                mvcsession.entryDataset.SetFieldValue('GLJIRTVL',
                                                      currat.CRRTRTVL)
                mvcsession.entryDataset.SetFieldValue('GLJIRTSP',
                                                      currat.CRRTRTSP)
                mvcsession.entryDataset.Post()

            fields = mvcsession.entryDataset.FieldsAsDict()
            dcm.getcontext().prec = 9
            amount = dcm.Decimal(fields['GLJITRAM'], CurrencyContext)
            if amount < dcm.Decimal(0):
                amount = dcm.Decimal(
                    fields['GLJITRAM'] * dcm.Decimal(-1, CurrencyContext),
                    CurrencyContext)

            namount = dcm.Decimal(0, CurrencyContext)
            if fields['GLJICSCD'] == fields['GLJICHCD']:
                namount = amount
            else:
                if fields['GLJIRTVL']:
                    if fields['GLJIRTOP'] == '*':
                        namount = amount * dcm.Decimal(fields['GLJIRTVL'])
                    elif fields['GLJIRTOP'] == '/':
                        divider = dcm.Decimal(fields['GLJIRTVL'])
                        if divider <> dcm.Decimal(0):
                            namount = amount / divider

            mvcsession.entryDataset.Edit()
            mvcsession.entryDataset.SetFieldValue('GLJICUAM', namount)
            mvcsession.entryDataset.Post()

        return mvcsession
Esempio n. 11
0
  def postData(self, mvcsession):
    params = mvcsession.paramDataset.FieldsAsDict()
    fields = mvcsession.entryDataset.FieldsAsDict()
    validators.NotEmpty(messages={'empty': 'Curr code must not empty'}).to_python(fields['GLRVCUCD'])

    proxy = self.getBusinessObjectProxy()
    usrobj = proxy.getObject('USROBJ')
    glsobj = proxy.getObject('GLSOBJ')
    info = usrobj.retrieveUserInfoDict(mvcsession)
    cono = info['USRCONO']
    glopt = glsobj.getGLOpt(cono)
    if (cono in (None, '')):
      raise Exception('Default company for user % is not assigned' % mvcsession.cookies['user_name'].encode('utf8'))

    sacct = GLACCT.get((cono, params['GLRVACID']))
    if not sacct:
      raise Exception('Master account does not exist')

    cur = MSTCUR.get((fields['GLRVCUCD']))
    if not cur:
      raise Exception('Currency does not exist')

    rval = None
    if fields['GLRVRVNM'] not in (None, ''):
      obj = GLRVAL.get((cono, fields['GLRVRVNM']))
      if not obj:
        raise Exception('Revaluation code does not exist')
      rval = obj.GLRVRVNM

    obj = GLACRV.get((cono, params['GLRVACID'], fields['GLRVCUCD']))

    td = dt.datetime.now()
    if (mvcsession.execType in (MVCExecAppend, MVCExecCopy)):
      if obj:
        raise Exception('Duplicate record found')
      obj = GLACRV()
      obj.GLRVCONO = cono
      obj.GLRVACID = sacct.GLACACID
      obj.GLRVCUCD = cur.CMCRCUCD
      obj.GLRVCUNM = cur.CMCRCUNM
      obj.GLRVRVST = fields['GLRVRVST']
      obj.GLRVRVNM = rval
      obj.GLRVAUDT = td.date().tointeger()
      obj.GLRVAUTM = td.time().tointeger()
      obj.GLRVAUUS = mvcsession.cookies['user_name'].encode('utf8')

      if not session.transaction_started():
        session.begin()
      try:
        session.save(obj)
        session.commit()
      except:
        session.rollback()
        session.expunge(obj)
        raise
    if (mvcsession.execType == MVCExecEdit):
      if not obj:
        raise Exception('Record could not be found')

      obj.GLRVRVST = fields['GLRVRVST']
      obj.GLRVRVNM = rval
      obj.GLRVAUDT = td.date().tointeger()
      obj.GLRVAUTM = td.time().tointeger()
      obj.GLRVAUUS = mvcsession.cookies['user_name'].encode('utf8')

      if not session.transaction_started():
        session.begin()
      try:
        session.update(obj)
        session.commit()
      except:
        session.rollback()
        session.expunge(obj)
        raise
    if (mvcsession.execType == MVCExecDelete):
      if not obj:
        raise Exception('Record could not be found')
      if not session.transaction_started():
        session.begin()
      try:
        session.delete(obj)
        session.commit()
      except:
        session.rollback()
        raise

    return mvcsession
Esempio n. 12
0
  def postData(self, mvcsession):
    params = mvcsession.paramDataset.FieldsAsDict()
    fields = mvcsession.entryDataset.FieldsAsDict()
    validators.NotEmpty(messages={'empty': 'Acct code must not empty'}).to_python(fields['GLALALFM'])
    validators.NotEmpty(messages={'empty': 'Allocation percentage must not empty'}).to_python(fields['GLALALPC'])
    proxy = self.getBusinessObjectProxy()
    usrobj = proxy.getObject('USROBJ')
    glsobj = proxy.getObject('GLSOBJ')
    info = usrobj.retrieveUserInfoDict(mvcsession)
    cono = info['USRCONO']
    glopt = glsobj.getGLOpt(cono)
    if (cono in (None, '')):
      raise Exception('Default company for user % is not assigned' % mvcsession.cookies['user_name'].encode('utf8'))
    pre = re.compile('\w+')
    acct = ''.join(pre.findall(fields['GLALALFM']))
    if acct == params['GLALACID']:
      raise Exception('Account used to be allocated could not be reused with allocation detail')

    sacct = GLACCT.get((cono, params['GLALACID']))
    if not sacct:
      raise Exception('Master account does not exist')

    ret = GLACCT.get((cono, acct))
    if not ret:
      raise Exception('Account does not exist')
    fmtvalue = ret.GLACACFM

    q = GLALAC.query
    q = q.filter_by(GLALCONO = cono)
    q = q.filter_by(GLALACID = params['GLALACID'])
    q = q.filter_by(GLALALID = acct)
    obj = q.first()

    td = dt.datetime.now()
    if (mvcsession.execType in (MVCExecAppend, MVCExecCopy)):
      if obj:
        raise Exception('Duplicate record found')
      rec = GLALAC(
        GLALCONO = cono,
        GLALACID = sacct.GLACACID,
        GLALALID = ret.GLACACID,
        GLALALFM = ret.GLACACFM,
        GLALALNM = ret.GLACACNM,
        GLALALRF = fields['GLALALRF'],
        GLALALPC = fields['GLALALPC'],
        GLALAUDT = td.date().tointeger(),
        GLALAUTM = td.time().tointeger(),
        GLALAUUS = mvcsession.cookies['user_name'].encode('utf8')
      )
      dcm.getcontext().prec = 9
      sacct.GLACALPC  = dcm.Decimal(sacct.GLACALPC + dcm.Decimal(rec.GLALALPC, CurrencyContext), CurrencyContext)
      if not session.transaction_started():
        session.begin()
      try:
        session.save(rec)
        session.update(sacct)
        session.commit()
      except:
        session.rollback()
        session.expunge(rec)
        raise
    if (mvcsession.execType == MVCExecEdit):
      if not obj:
        raise Exception('Record could not be found')
      dcm.getcontext().prec = 9
      sacct.GLACALPC  = dcm.Decimal(sacct.GLACALPC - dcm.Decimal(obj.GLALALPC, CurrencyContext), CurrencyContext)
      mvcsession.entryDataset.CopyIntoORM(
        'GLALALRF;GLALALPC',
        'GLALALRF;GLALALPC',
        obj)
      obj.GLALAUDT = td.date().tointeger()
      obj.GLALAUTM = td.time().tointeger()
      obj.GLALAUUS = mvcsession.cookies['user_name'].encode('utf8')
      if not session.transaction_started():
        session.begin()
      try:
        dcm.getcontext().prec = 9
        sacct.GLACALPC  = dcm.Decimal(sacct.GLACALPC + dcm.Decimal(obj.GLALALPC, CurrencyContext), CurrencyContext)
        session.update(obj)
        session.update(sacct)
        session.commit()
      except:
        session.rollback()
        session.expunge(obj)
        raise
    if (mvcsession.execType == MVCExecDelete):
      if not obj:
        raise Exception('Record could not be found')
      if not session.transaction_started():
        session.begin()
      try:
        dcm.getcontext().prec = 9
        sacct.GLACALPC  = dcm.Decimal(sacct.GLACALPC - dcm.Decimal(obj.GLALALPC, CurrencyContext), CurrencyContext)
        session.delete(obj)
        session.update(sacct)
        session.commit()
      except:
        session.rollback()
        raise

    return mvcsession
Esempio n. 13
0
    def postData(self, mvcsession):
        fields = mvcsession.entryDataset.FieldsAsDict()
        validators.NotEmpty(messages={
            'empty': 'Acct code must not empty'
        }).to_python(fields['GLACACFM'])
        validators.NotEmpty(messages={
            'empty': 'Default acct structure must not empty'
        }).to_python(fields['GLACSTID'])
        proxy = self.getBusinessObjectProxy()
        usrobj = proxy.getObject('USROBJ')
        glsobj = proxy.getObject('GLSOBJ')
        info = usrobj.retrieveUserInfoDict(mvcsession)
        cono = info['USRCONO']
        glopt = glsobj.getGLOpt(cono)
        if (cono in (None, '')):
            raise Exception('Default company for user % is not assigned' %
                            mvcsession.cookies['user_name'].encode('utf8'))
        pre = re.compile('\w+')
        acct = ''.join(pre.findall(fields['GLACACFM']))
        acctvalues = glsobj.formatacct(cono, fields['GLACSTID'], acct)
        q = GLACCT.query
        q = q.filter_by(GLACCONO=cono)
        q = q.filter_by(GLACACID=acct)
        obj = q.first()
        td = dt.datetime.now()
        srcid = None
        if fields['GLACALSR'] not in (None, ''):
            srcid = GLSRCE.expandSourceCode(fields['GLACALSR'])[2]
        if (mvcsession.execType in (MVCExecAppend, MVCExecCopy)):
            if obj:
                raise Exception('Duplicate record found')
            rec = GLACCT(
                GLACCONO=cono,
                GLACACID=acct,
                GLACACFM=acctvalues[0],
                GLACACNM=fields['GLACACNM'],
                GLACACTP=fields['GLACACTP'],
                GLACBLTP=fields['GLACBLTP'],
                GLACGRTP=fields['GLACGRTP'],
                GLACACST=fields['GLACACST'],
                GLACCSST=fields['GLACCSST'],
                GLACALST=fields['GLACALST'],
                GLACALSR=srcid,
                GLACSRNM=fields['GLACSRNM'],
                GLACALTO=0,
                GLACALPC=0,
                GLACSTID=fields['GLACSTID'],
                GLACSTNM=fields['GLACSTNM'],
                GLACLCST=0,
                GLACCUCD=fields['GLACCUCD'],
                GLACCPTP=fields['GLACCPTP'],
                GLACAUDT=td.date().tointeger(),
                GLACAUTM=td.time().tointeger(),
                GLACAUUS=mvcsession.cookies['user_name'].encode('utf8'))
            for (csid, csvalue) in acctvalues[1:]:
                setattr(rec, 'GLACCS%.2d' % csid, csvalue)

            if not session.transaction_started():
                session.begin()
            try:
                session.save(rec)
                session.commit()
            except:
                session.rollback()
                session.expunge(rec)
                raise
        if (mvcsession.execType == MVCExecEdit):
            if not obj:
                raise Exception('Record could not be found')
            mvcsession.entryDataset.CopyIntoORM(
              'GLACACFM;GLACACNM;GLACACTP;GLACBLTP;GLACGRTP;'\
              'GLACACST;GLACCSST;GLACALST;GLACALSR;GLACSRNM;GLACSTID;GLACSTNM;GLACCUCD;GLACCPTP',
              'GLACACFM;GLACACNM;GLACACTP;GLACBLTP;GLACGRTP;'\
              'GLACACST;GLACCSST;GLACALST;GLACALSR;GLACSRNM;GLACSTID;GLACSTNM;GLACCUCD;GLACCPTP',
              obj)
            obj.GLACALSR = srcid
            obj.GLACAUDT = td.date().tointeger()
            obj.GLACAUTM = td.time().tointeger()
            obj.GLACAUUS = mvcsession.cookies['user_name'].encode('utf8')
            if not session.transaction_started():
                session.begin()
            try:
                session.update(obj)
                session.commit()
            except:
                session.rollback()
                session.expunge(obj)
                raise

        if (mvcsession.execType == MVCExecDelete):
            if not obj:
                raise Exception('Record could not be found')
            if not session.transaction_started():
                session.begin()
            try:
                session.delete(obj)
                session.commit()
            except:
                session.rollback()
                raise
        return mvcsession