Пример #1
0
    def add_account(self,
                    id,
                    name,
                    number="",
                    type=0,
                    owner="",
                    bank=1,
                    branch="",
                    address="",
                    phone="",
                    webpage="",
                    desc=""):
        name = unicode(name)
        number = unicode(number)
        owner = unicode(owner)
        bank = unicode(bank)
        branch = unicode(branch)
        address = unicode(address)
        phone = unicode(phone)
        webpage = unicode(webpage)
        desc = unicode(desc)

        bank_id = bank
        dbconf = dbconfig.dbConfig()
        if id == -1:
            bank_account = BankAccounts(name, number, type, owner, bank_id,
                                        branch, address, phone, webpage, desc)
            config.db.session.add(bank_account)
            config.db.session.commit()
            sub = class_subject.Subjects()
            # accountId = str(bank_account.accId)
            # accSubjectCode = accountId.rjust(3 - len(accountId)+1 , '0')
            sub.add(dbconf.get_int('bank'), name)
        else:
            query = config.db.session.query(BankAccounts).filter(
                BankAccounts.accId == id)
            prevName = query.first().accName
            q = config.db.session.query(Subject).filter(
                Subject.parent_id == (dbconf.get_int('bank'))).filter(
                    Subject.name == prevName)
            if q:
                q.update({Subject.name: name})
            query.update({
                BankAccounts.accName: name,
                BankAccounts.accNumber: number,
                BankAccounts.accType: type,
                BankAccounts.accOwner: owner,
                BankAccounts.accBank: bank_id,
                BankAccounts.accBankBranch: branch,
                BankAccounts.accBankAddress: address,
                BankAccounts.accBankPhone: phone,
                BankAccounts.accBankWebPage: webpage,
                BankAccounts.accDesc: desc
            })

        if id == -1 and bank_account:
            return bank_account.accId
        return id
Пример #2
0
    def on_subject_multi_selected(self, subject, items, entry):
        sub = class_subject.Subjects()
        selected = []

        new_txt = ''
        for item in items:
            name = sub.get_name(item[0])
            new_txt += '%s,' % name
        new_txt = new_txt[:-1]

        entry.set_text(new_txt)
        subject.window.destroy()
Пример #3
0
    def applyConfigSetting(self):
        conf = dbconfig.dbConfig()
        sub = class_subject.Subjects()

        # self.config_items( 0 => item_id, 1 => get_val function, 2 => exists in subjects)
        for item in self.config_items:
            val = item[1]()

            if val == None or val == '':
                #TODO Can be return on empty row
                val = conf.get_default(item[3])
            elif item[2] == True:
                ids = ''
                val = unicode(val)
                for name in val.split(','):
                    ids += '%d,' % sub.get_id_from_name(name)
                val = ids[:-1]
            conf.set_value(item[0], val, False)

        config.db.session.commit()
Пример #4
0
    def add_account(self, id, name, number, type, owner, bank, branch, address, phone, webpage, desc):
        name    = unicode(name)
        number  = unicode(number)
        owner   = unicode(owner)
        bank    = unicode(bank)
        branch  = unicode(branch)
        address = unicode(address)
        phone   = unicode(phone)
        webpage = unicode(webpage)
        desc    = unicode(desc)

        bank_id = config.db.session.query(BankNames).select_from(BankNames).filter(BankNames.Name == bank).first().Id

        if id == -1:
            bank_account = BankAccounts(name, number, type, owner, bank_id, branch, address, phone, webpage, desc)
            config.db.session.add(bank_account)
            sub = class_subject.Subjects()
            dbconf = dbconfig.dbConfig()
            sub.add(dbconf.get_int('bank'), name, str(bank_account.accId).rjust(2, '0'))
        else:
            query = config.db.session.query(BankAccounts).select_from(BankAccounts)
            query = query.filter(BankAccounts.accId == id)
            query.update( {BankAccounts.accName        : name,
                           BankAccounts.accNumber      : number,
                           BankAccounts.accType        : type,
                           BankAccounts.accOwner       : owner,
                           BankAccounts.accBank        : bank_id,
                           BankAccounts.accBankBranch  : branch,
                           BankAccounts.accBankAddress : address,
                           BankAccounts.accBankPhone   : phone,
                           BankAccounts.accBankWebPage : webpage,
                           BankAccounts.accDesc        : desc})
        config.db.session.commit()

        if id == -1:
            return bank_account.accId
        return id
Пример #5
0
    def saveCustomer(self):
        custCode = unicode(self.builder.get_object("custCodeEntry").get_text())
        custGrp = self.custgrpentry.get_int()
        custName = unicode(self.builder.get_object("custNameEntry").get_text())
        custEcnmcsCode = unicode(
            self.builder.get_object("custEcnmcsCodeEntry").get_text())
        custPersonalCode = unicode(
            self.builder.get_object("custPrsnalCodeEntry").get_text())

        custPhone = unicode(
            self.builder.get_object("custPhoneEntry").get_text())
        custCell = unicode(self.builder.get_object("custCellEntry").get_text())
        custFax = unicode(self.builder.get_object("custFaxEntry").get_text())
        custWebPage = unicode(
            self.builder.get_object("custWebPageEntry").get_text())
        custEmail = unicode(
            self.builder.get_object("custEmailEntry").get_text())
        custRepViaEmail = self.builder.get_object(
            "custRepViaEmailChk").get_active()
        custAddress = unicode(
            self.builder.get_object("custAddressEntry").get_text())
        custPostalCode = unicode(
            self.builder.get_object("cusPostalCodeEntry").get_text())

        callResponsible = unicode(
            self.builder.get_object("callResponsibleEntry").get_text())
        custConnector = unicode(
            self.builder.get_object("custConnectorEntry").get_text())

        custDesc = unicode(self.builder.get_object("custDescEntry").get_text())
        #----------------------------------
        custTypeBuyer = self.builder.get_object(
            "custTypeBuyerChk").get_active()
        custTypeSeller = self.builder.get_object(
            "custTypeSellerChk").get_active()
        custTypeMate = self.builder.get_object("custTypeMateChk").get_active()
        custTypeAgent = self.builder.get_object(
            "custTypeAgentChk").get_active()
        custIntroducer = self.custIntroducerEntry.get_int()
        custCommission = self.boxCommissionRateEntry.get_float()
        custDiscRate = self.boxDiscRateEntry.get_float()
        custMarked = self.builder.get_object("markedChk").get_active()
        custReason = unicode(
            self.builder.get_object("markedReasonEntry").get_text())
        #----------------------------------
        custBalance = self.boxBalanceEntry.get_float()
        custCredit = self.boxCreditEntry.get_float()
        custAccName1 = unicode(
            self.builder.get_object("custAccName1Entry").get_text())
        custAccNo1 = unicode(
            self.builder.get_object("custAccNo1Entry").get_text())
        custAccBank1 = unicode(
            self.builder.get_object("custAccBank1Entry").get_text())
        custAccName2 = unicode(
            self.builder.get_object("custAccName2Entry").get_text())
        custAccNo2 = unicode(
            self.builder.get_object("custAccNo2Entry").get_text())
        custAccBank2 = unicode(
            self.builder.get_object("custAccBank2Entry").get_text())

        msg = ""
        if custCode == "":
            msg += _("Customer code should not be empty.\n")
        else:
            codeQuery = config.db.session.query(Customers).select_from(
                Customers)
            codeQuery = codeQuery.filter(Customers.custCode == custCode)
            if self.editCustomer:
                codeQuery = codeQuery.filter(
                    Customers.custId != self.customerId)

            codeQuery = codeQuery.first()
            if codeQuery:
                msg += _("Customer code has been used before.\n")

        #--------------------
        groupid = 0
        if custGrp == "":
            msg += _("Customer group should not be empty.\n")
        else:
            query = config.db.session.query(
                CustGroups.custGrpId).select_from(CustGroups).filter(
                    CustGroups.custGrpCode == custGrp)
            groupid = query.first()
            if groupid == None:
                msg += _(
                    "No customer group registered with code %s.\n") % custGrp
            else:
                groupid = groupid[0]

        #--------------------
        if custName == "":
            msg += _("Customer name should not be empty.\n")

        #--------------------
        if msg != "":
            msgbox = gtk.MessageDialog(self.customerForm, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                       msg)
            msgbox.set_title(_("Can not save customer"))
            msgbox.run()
            msgbox.destroy()
            return -1

        if not self.editCustomer:
            #New Customer
            sub = class_subject.Subjects()
            custSubj = sub.add(dbconf.get_int('custSubject'), custName)
            customer = Customers(
                custCode, custName, custSubj, custPhone, custCell, custFax,
                custAddress, custEmail, custEcnmcsCode, custWebPage,
                callResponsible, custConnector, groupid, custPostalCode,
                custPersonalCode, custDesc, custBalance, custCredit,
                custRepViaEmail, custAccName1, custAccNo1, custAccBank1,
                custAccName2, custAccNo2, custAccBank2, custTypeBuyer,
                custTypeSeller, custTypeMate, custTypeAgent, custIntroducer,
                custCommission, custMarked, custReason, custDiscRate)
        else:
            query = config.db.session.query(Customers).select_from(Customers)
            customer = query.filter(
                Customers.custId == self.customerId).first()
            #customer code not need to change
            #customer.custCode = custCode
            customer.custName = custName
            customer.custPhone = custPhone
            customer.custCell = custCell
            customer.custFax = custFax
            customer.custAddress = custAddress
            customer.custPostalCode = custPostalCode
            customer.custEmail = custEmail
            customer.custEcnmcsCode = custEcnmcsCode
            customer.custPersonalCode = custPersonalCode
            customer.custWebPage = custWebPage
            customer.custResponsible = callResponsible
            customer.custConnector = custConnector
            customer.custGroup = groupid
            customer.custDesc = custDesc
            #----------------------------------
            customer.custTypeBuyer = custTypeBuyer
            customer.custTypeSeller = custTypeSeller
            customer.custTypeMate = custTypeMate
            customer.custTypeAgent = custTypeAgent
            customer.custIntroducer = custIntroducer
            customer.custCommission = custCommission
            customer.custDiscRate = custDiscRate
            customer.custMarked = custMarked
            customer.custReason = custReason
            #----------------------------------
            customer.custBalance = custBalance
            customer.custCredit = custCredit
            customer.custAccName1 = custAccName1
            customer.custAccNo1 = custAccNo1
            customer.custAccBank1 = custAccBank1
            customer.custAccName2 = custAccName2
            customer.custAccNo2 = custAccNo2
            customer.custAccBank2 = custAccBank2

        config.db.session.add(customer)
        config.db.session.commit()

        #Show new customer in table
        if self.treestore != None:
            parent_iter = self.treestore.get_iter_first()
            while parent_iter:
                itercode = self.treestore.get_value(parent_iter, 0)
                if itercode == str(custGrp):
                    break
                parent_iter = self.treestore.iter_next(parent_iter)

            custCode = LN(custCode)

            if not self.editCustomer:
                self.treestore.append(parent_iter,
                                      (custCode, custName, "0", "0", "0"))
            else:
                self.treestore.set(self.editIter, 0, custCode, 1, custName)

        return 0
Пример #6
0
    def setup_config_tab(self):
        sub = class_subject.Subjects()
        query = config.db.session.query(database.Config).all()

        company = self.builder.get_object('company_table')
        subjects = self.builder.get_object('subjects_table')
        others = self.builder.get_object('others_table')
        company_top = subjects_top = others_top = 0

        destroy = lambda table: [
            widget.destroy() for widget in table.get_children()
        ]
        destroy(company)
        destroy(subjects)
        destroy(others)
        del destroy

        self.config_items = []

        for row in query:
            if row.cfgCat == 0:
                table = company
                top = company_top = company_top + 1
            elif row.cfgCat == 1:
                table = subjects
                top = subjects_top = subjects_top + 1
            else:
                table = others
                top = others_top = others_top + 1

            # self.config_items( 0 => item_id, 1 => get_val function, 2 => exists in subjects)
            if row.cfgType == 0:
                widget = Gtk.FileChooserButton(row.cfgKey)
                filt = Gtk.FileFilter()
                filt.set_name('png,jpg')
                filt.add_pattern('*.png')
                filt.add_pattern('*.jpg')
                widget.add_filter(filt)
                filt = Gtk.FileFilter()
                filt.set_name('All files')
                filt.add_pattern('*')
                widget.add_filter(filt)

                if row.cfgValue != '':
                    widget.set_filename(row.cfgValue)
                self.config_items.append(
                    (row.cfgId, widget.get_filename, False, row.cfgKey))
            elif row.cfgType in (1, 2, 3):
                widget = Gtk.Entry()
                if row.cfgType == 1:
                    self.config_items.append(
                        (row.cfgId, widget.get_text, False, row.cfgKey))
                else:
                    self.config_items.append(
                        (row.cfgId, widget.get_text, True, row.cfgKey))

            widget2 = None
            widget3 = None
            widget4 = None
            if row.cfgType == 0:
                widget2 = Gtk.Button()  # clear button
                widget2.set_image(
                    Gtk.Image.new_from_stock(Gtk.STOCK_CLEAR,
                                             Gtk.IconSize.MENU))
                widget2.connect('clicked',
                                lambda widget2, widget: widget.unselect_all(),
                                widget)
            elif row.cfgType == 1:
                widget.set_text(row.cfgValue)
            elif row.cfgType in (2, 3):
                txt = ''
                if len(row.cfgValue) != 0:
                    for id in row.cfgValue.split(','):
                        txt += sub.get_name(id) + ','
                    txt = txt[:-1]
                widget.set_text(txt)

                widget.set_sensitive(False)
                widget2 = Gtk.Button()  # clear button
                widget2.set_image(
                    Gtk.Image.new_from_stock(Gtk.STOCK_CLEAR,
                                             Gtk.IconSize.MENU))
                widget3 = Gtk.Button('Select')  # select button
                if row.cfgType == 2:
                    multivalue = False
                elif row.cfgType == 3:
                    multivalue = True
                widget2.connect('clicked',
                                lambda button, entry: entry.set_text(''),
                                widget)
                widget3.connect('clicked', self.on_select_button_clicked,
                                widget, multivalue)

            if row.cfgCat == 2:
                widget4 = Gtk.Button()  # Delete Button
                widget4.set_image(
                    Gtk.Image.new_from_stock(Gtk.STOCK_DELETE,
                                             Gtk.IconSize.MENU))
                widget4.connect('clicked', self.on_delete_row_clicked,
                                row.cfgId)

            table.attach(Gtk.Label(label=row.cfgKey), 0, 1, top - 1, top,
                         Gtk.AttachOptions.SHRINK)
            table.attach(widget, 1, 2, top - 1, top)
            if widget2:
                table.attach(widget2, 2, 3, top - 1, top,
                             Gtk.AttachOptions.SHRINK)
            if widget3:
                table.attach(widget3, 3, 4, top - 1, top,
                             Gtk.AttachOptions.SHRINK)
            if widget4:
                table.attach(widget4, 4, 5, top - 1, top,
                             Gtk.AttachOptions.SHRINK)
            table.attach(Gtk.Label(label=row.cfgDesc), 5, 6, top - 1, top)
            table.show_all()

        if others_top == 0:
            others.attach(Gtk.Label(), 0, 5, 0, 1, Gtk.AttachOptions.SHRINK)