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 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. 3
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. 4
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. 5
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. 6
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