Example #1
0
    def populateChildren(self, treeview, iter, path):
        chiter = self.treestore.iter_children(iter)
        if chiter != None:
            #Checks name field(second) because code field(first) may have changed during parent code edition.
            value = self.treestore.get(chiter, 1)[0]
            if value == "":
                value = convertToLatin(self.treestore.get(iter, 0)[0])
                #remove empty subledger to add real children instead
                self.treestore.remove(chiter)

                parent_id = share.session.query(
                    Subject.id).select_from(Subject).filter(
                        Subject.code == value).all()

                Sub = aliased(Subject, name="s")
                Child = aliased(Subject, name="c")

                query = config.db.session.query(Sub.code, Sub.name, Sub.type,
                                                count(Child.id), Sub.lft,
                                                Sub.rgt)
                query = query.select_from(
                    outerjoin(Sub, Child, Sub.id == Child.parent_id))
                result = query.filter(
                    Sub.parent_id == parent_id[0][0]).group_by(Sub.id).all()
                for row in result:
                    code = row[0]
                    code = LN(code, False)
                    type = _(self.subjecttypes[row[2]])

                    #--------
                    subject_sum = config.db.session.query(sum(
                        Notebook.value)).select_from(
                            outerjoin(Subject, Notebook,
                                      Subject.id == Notebook.subject_id))
                    subject_sum = subject_sum.filter(
                        and_(Subject.lft >= row[4],
                             Subject.lft <= row[5])).first()
                    subject_sum = subject_sum[0]
                    if (subject_sum == None):
                        subject_sum = LN("0")
                    else:
                        if (subject_sum < 0):
                            subject_sum = "(-" + LN(-subject_sum) + ")"
                        else:
                            subject_sum = LN(subject_sum)

                    chiter = self.treestore.append(
                        iter, (code, row[1], type, subject_sum))
                    if row[3] != 0:
                        #add empty subledger for those children which have subledgers in turn. (to show expander)
                        self.treestore.append(chiter, ("", "", "", ""))
        return False
Example #2
0
    def editLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Edit Ledger"))
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]

        if iter != None:

            code = convertToLatin(self.treestore.get(iter, 0)[0])
            pcode = LN(code[0:-3], False)
            ccode = LN(code[-3:], False)

            self.builder.get_object("parentcode").set_text(pcode)
            self.code.set_text(ccode)

            name = self.treestore.get(iter, 1)[0]
            type = self.treestore.get(iter, 2)[0]

            if type == self.subjecttypes[0]:
                self.builder.get_object("debtor").set_active(True)
                self.builder.get_object("creditor").set_active(False)
            elif type == self.subjecttypes[1]:
                self.builder.get_object("creditor").set_active(True)
                self.builder.get_object("debtor").set_active(False)
            else:
                self.builder.get_object("debtor").set_active(True)
                self.builder.get_object("creditor").set_active(True)

            #label = self.builder.get_object("label3")
            #label.set_text(name)
            entry = self.builder.get_object("ledgername")
            entry.set_text(name)

            hbox = self.builder.get_object("hbox3")
            hbox.hide()
            result = dialog.run()

            ttype = 0
            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    ttype += 1
                if self.builder.get_object("creditor").get_active() == True:
                    ttype += 10
                a = [1, 10, 11]
                type = a.index(ttype)
                per = self.builder.get_object("permanent").get_active()
                self.saveLedger(unicode(entry.get_text()), type, iter, True,
                                dialog, per)

            dialog.hide()
Example #3
0
    def editLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Edit Ledger"))
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]

        if iter != None:

            code = convertToLatin(self.treestore.get(iter, 0)[0])
            pcode = LN(code[0:-2], False)
            ccode = LN(code[-2:], False)

            self.builder.get_object("parentcode").set_text(pcode)
            self.code.set_text(ccode)

            name = self.treestore.get(iter, 1)[0]
            type = self.treestore.get(iter, 2)[0]
            debtor = False
            creditor = False
            both = False

            if type == self.subjecttypes[0]:
                self.builder.get_object("debtor").set_active(True)
            else:
                if type == self.subjecttypes[1]:
                    self.builder.get_object("creditor").set_active(True)
                else:
                    self.builder.get_object("both").set_active(True)
            #label = self.builder.get_object("label3")
            #label.set_text(name)
            entry = self.builder.get_object("ledgername")
            entry.set_text(name)

            hbox = self.builder.get_object("hbox3")
            hbox.hide()
            result = dialog.run()

            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    type = 0
                else:
                    if self.builder.get_object(
                            "creditor").get_active() == True:
                        type = 1
                    else:
                        type = 2
                self.saveLedger(unicode(entry.get_text()), type, iter, True,
                                dialog)
            dialog.hide()
Example #4
0
    def addLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.hide()
        entry = self.builder.get_object("ledgername")
        entry.set_text("")

        query = config.db.session.query(
            Subject.code).select_from(Subject).order_by(Subject.id.desc())
        code = query.filter(Subject.parent_id == 0).first()
        if code == None:
            lastcode = "01"
        else:
            lastcode = "%02d" % (int(code[0][-2:]) + 1)

        lastcode = LN(lastcode, False)
        self.code.set_text(lastcode)
        self.builder.get_object("parentcode").set_text("")

        #        dialog.show_all()
        result = dialog.run()
        if result == 1:
            if self.builder.get_object("debtor").get_active() == True:
                type = 0
            else:
                if self.builder.get_object("creditor").get_active() == True:
                    type = 1
                else:
                    type = 2

            self.saveLedger(unicode(entry.get_text()), type, None, False,
                            dialog)
        dialog.hide()
Example #5
0
    def addLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.hide()
        entry = self.builder.get_object("ledgername")
        entry.set_text("")
        self.builder.get_object("debtor").set_active(False)
        self.builder.get_object("creditor").set_active(False)
        query = config.db.session.query(
            Subject.code).select_from(Subject).order_by(Subject.code.desc())
        code = query.filter(Subject.parent_id == 0).first()
        if code == None:
            lastcode = "001"
        else:
            lastcode = "%03d" % (int(code[0][-3:]) + 1)

        lastcode = LN(lastcode, False)
        self.code.set_text(lastcode)
        self.builder.get_object("parentcode").set_text("")

        ttype = 0
        result = dialog.run()
        if result == 1:
            if self.builder.get_object("debtor").get_active() == True:
                ttype += 1
            if self.builder.get_object("creditor").get_active() == True:
                ttype += 10
            a = [1, 10, 11]
            type = a.index(ttype)
            per = self.builder.get_object("permanent").get_active()
            self.saveLedger(unicode(entry.get_text()), type, None, False,
                            dialog, per)
        dialog.hide()
Example #6
0
 def editChildCodes(self, model, path, iter, data):
     basecode = data[0]
     length = data[1]
     chcode = model.get(iter, 0)[0]
     chcode = convertToLatin(chcode)[length:]
     chcode = LN(chcode, False)
     self.treestore.set(model.convert_iter_to_child_iter(iter), 0,
                        basecode + chcode)
Example #7
0
    def addSubLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Sub-ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.show()
        selection = self.treeview.get_selection()
        parent = selection.get_selected()[1]
        self.builder.get_object("debtor").set_active(False)
        self.builder.get_object("creditor").set_active(False)
        if parent != None:
            pcode = self.treestore.get(parent, 0)[0]
            self.builder.get_object("parentcode").set_text(pcode)
            pcode = convertToLatin(pcode)

            query = config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.code == pcode)
            psub = query.first()

            #parentname = self.treestore.get(parent, 1)[0]
            label = self.builder.get_object("label3")
            label.set_text(psub.name)
            entry = self.builder.get_object("ledgername")
            entry.set_text("")

            query = config.db.session.query(
                Subject.code).select_from(Subject).order_by(Subject.id.desc())
            code = query.filter(Subject.parent_id == psub.id).first()
            if code == None:
                lastcode = "001"
            else:
                lastcode = "%03d" % (int(code[0][-3:]) + 1)

            lastcode = LN(lastcode, False)
            self.code.set_text(lastcode)

            ttype = 0
            result = dialog.run()
            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    ttype += 1
                if self.builder.get_object("creditor").get_active() == True:
                    ttype += 10
                a = [1, 10, 11]
                type = a.index(ttype)
                per = self.builder.get_object("permanent").get_active()
                self.saveLedger(unicode(entry.get_text()), type, parent, False,
                                dialog, per)
            dialog.hide()
        else:
            msgbox = Gtk.MessageDialog(
                parent, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO,
                Gtk.ButtonsType.CLOSE,
                _("Please select an item from the list, to add subject for it."
                  ))
            msgbox.set_title(_("Select a subject"))
            msgbox.run()
            msgbox.destroy()
Example #8
0
    def on_cash_payment_entry_change(self, entry=None):
        val1 = self.cash_payment_entry.get_float()
        val2 = float(unicode(self.builder.get_object('non-cash-payment-label').get_text()).replace(','  ,  ''))
        val3 = float(unicode(self.builder.get_object('spend-cheque-label').get_text()).replace(','  ,  ''))
        discount = self.discount_entry.get_float()

        paid = val1+val2+val3+discount
        paid_label = self.builder.get_object('paid')
        paid_label.set_direction(Gtk.TextDirection.LTR)
        paid_label.set_text(LN(paid))

        total = self.total_credit_entry.get_float()
        r = total - (paid)
        mod = self.builder.get_object('mod')
        mod.set_direction(Gtk.TextDirection.LTR)
        mod.set_text(LN(r))

        self.check_save_button()
Example #9
0
    def addNewCustomer(self, sender, pcode=""):
        self.editCustomer = False

        self.customerForm = self.builder.get_object("customersWindow")
        self.customerForm.set_title(_("Add New Customer"))
        self.builder.get_object("addCustSubmitBtn").set_label(
            _("Add Customer"))

        query = config.db.session.query(
            Subject.code).select_from(Subject).order_by(Subject.id.desc())
        code = query.filter(
            Subject.parent_id == dbconf.get_int('custSubject')).first()
        if code == None:
            lastcode = "01"
        else:
            lastcode = "%02d" % (int(code[0][-2:]) + 1)

        self.builder.get_object("custCodeEntry").set_text(LN(lastcode))
        #self.custgrpentry.set_text("")
        self.builder.get_object("custNameEntry").set_text("")
        self.builder.get_object("custEcnmcsCodeEntry").set_text("")
        self.builder.get_object("custPrsnalCodeEntry").set_text("")

        self.builder.get_object("custPhoneEntry").set_text("")
        self.builder.get_object("custCellEntry").set_text("")
        self.builder.get_object("custFaxEntry").set_text("")
        self.builder.get_object("custWebPageEntry").set_text("")
        self.builder.get_object("custEmailEntry").set_text("")
        self.builder.get_object("custRepViaEmailChk").get_active()
        self.builder.get_object("custAddressEntry").set_text("")
        self.builder.get_object("cusPostalCodeEntry").set_text("")

        self.builder.get_object("callResponsibleEntry").set_text("")
        self.builder.get_object("custConnectorEntry").set_text("")

        self.builder.get_object("custDescEntry").set_text("")
        #----------------------------------
        self.builder.get_object("custTypeBuyerChk").set_active(True)
        self.builder.get_object("custTypeSellerChk").set_active(True)
        self.builder.get_object("custTypeMateChk").set_active(False)
        self.builder.get_object("custTypeAgentChk").set_active(False)
        self.custIntroducerEntry.set_text("")
        self.boxCommissionRateEntry.set_text("")
        self.boxDiscRateEntry.set_text("")
        self.builder.get_object("markedChk").set_active(False)
        self.builder.get_object("markedReasonEntry").set_text("")
        #----------------------------------
        self.boxBalanceEntry.set_text("")
        self.boxCreditEntry.set_text("")
        self.builder.get_object("custAccName1Entry").set_text("")
        self.builder.get_object("custAccNo1Entry").set_text("")
        self.builder.get_object("custAccBank1Entry").set_text("")
        self.builder.get_object("custAccName2Entry").set_text("")
        self.builder.get_object("custAccNo2Entry").set_text("")
        self.builder.get_object("custAccBank2Entry").set_text("")

        self.customerForm.show_all()
Example #10
0
    def addSubLedger(self, sender):
        dialog = self.builder.get_object("dialog1")
        dialog.set_title(_("Add Sub-ledger"))
        hbox = self.builder.get_object("hbox3")
        hbox.show()
        selection = self.treeview.get_selection()
        parent = selection.get_selected()[1]

        if parent != None:
            pcode = self.treestore.get(parent, 0)[0]
            self.builder.get_object("parentcode").set_text(pcode)
            pcode = convertToLatin(pcode)

            query = config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.code == pcode)
            psub = query.first()

            #parentname = self.treestore.get(parent, 1)[0]
            label = self.builder.get_object("label3")
            label.set_text(psub.name)
            entry = self.builder.get_object("ledgername")
            entry.set_text("")

            query = config.db.session.query(
                Subject.code).select_from(Subject).order_by(Subject.id.desc())
            code = query.filter(Subject.parent_id == psub.id).first()
            if code == None:
                lastcode = "01"
            else:
                lastcode = "%02d" % (int(code[0][-2:]) + 1)

            lastcode = LN(lastcode, False)
            self.code.set_text(lastcode)

            result = dialog.run()
            if result == 1:
                if self.builder.get_object("debtor").get_active() == True:
                    type = 0
                else:
                    if self.builder.get_object(
                            "creditor").get_active() == True:
                        type = 1
                    else:
                        type = 2

                self.saveLedger(unicode(entry.get_text()), type, parent, False,
                                dialog)
            dialog.hide()
        else:
            msgbox = gtk.MessageDialog(
                parent, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_CLOSE,
                _("Please select an item from the list, to add subject for it."
                  ))
            msgbox.set_title(_("Select a subject"))
            msgbox.run()
            msgbox.destroy()
Example #11
0
 def showDate(self, year, month, day):
     datelist = ["", "", ""]
     datelist[share.config.datefields["year"]] = year
     datelist[share.config.datefields["month"]] = month
     datelist[share.config.datefields["day"]] = day
     
     delim = share.config.datedelims[share.config.datedelim]
     datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(datelist[2])
     datestring = LN(datestring, False)
     self.set_text(datestring)
     self.year = year
     self.month = month
     self.day = day
Example #12
0
def dateToString(date):
    if share.config.datetypes[share.config.datetype] == "jalali":
        jd = DateEntry.cal.gregorian_to_jd(date.year, date.month, date.day)
        (year, month, day) = DateEntry.cal.jd_to_jalali(jd)
    else:
        (year, month, day) = (date.year, date.month, date.day)
        
    datelist = ["", "", ""]
    datelist[share.config.datefields["year"]] = year
    datelist[share.config.datefields["month"]] = month
    datelist[share.config.datefields["day"]] = day
        
    delim = share.config.datedelims[share.config.datedelim]
    datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(datelist[2])
    datestring = LN(datestring, False)
    return datestring
Example #13
0
    def on_save_button_clicked(self, button):
        result = {}
        result['type']                  = self.type_index
        result['total_value']           = self.total_credit_entry.get_float()
        result['cash_payment']          = self.cash_payment_entry.get_float()
        result['non_cash_payment']      = self.builder.get_object('non-cash-payment-label').get_text()
        result['spend_cheque']          = self.builder.get_object('spend-cheque-label').get_text()
        result['discount']              = self.discount_entry.get_float()
        result['non-cash-payment-info'] = None # TODO: = non cash payment infos
        result['spend-cheque-info']     = None # TODO = spent cheque infos
        result['desc']                  = self.builder.get_object('desc').get_text()
        result['from']                  = self.from_id
        result['to']                    = self.to_id

        dbconf = dbconfig.dbConfig()

        #Save data in data base for single use
        if self.liststore == None:
            type(result['from'])
            document = class_document.Document()
            document.add_notebook(result['from'],  result['total_value'], unicode(result['desc']))
            document.add_notebook(result['to']  , -result['cash_payment'], unicode(result['desc']))
            if result['discount'] :
                document.add_notebook(dbconf.get_int('sell-discount'), -result['discount'], result['desc'])
            cl_cheque = class_cheque.ClassCheque()
            for cheque in self.chequeui.new_cheques:
                if self.mode == 'our':
                    document.add_cheque(dbconf.get_int('our_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
                else:
                    document.add_cheque(dbconf.get_int('other_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #spendble cheque
            for sp_cheque in self.chequeui.spend_cheques:
                cl_cheque.update_status(sp_cheque['serial'],5)
                document.add_cheque(dbconf.get_int('other_cheque'), -sp_cheque['amount'] , unicode('kharj shodeh') , sp_cheque['serial'])
                    
            result = document.save()

            if result < 0:
                dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, 'Failed, %s' % document.get_error_message(result))
                dialog.run()
                dialog.destroy()
                return

            if self.type_configs[self.type_index][3] == True: # from is subject
                customer_id = 0
            else: # from is customer
                customer_id = share.config.db.session.query(Customers).select_from(Customers).filter(Customers.custSubj==self.from_id).first().custId

            for cheque in self.chequeui.new_cheques:
                notebook_id =document.cheques_result[cheque['serial']]
                cl_cheque.add_cheque(cheque['amount'], cheque['write_date'], cheque['due_date'],
                                     cheque['serial'], cheque['status'],
                                     customer_id, cheque['bank_account_id'],
                                     result, notebook_id, cheque['desc'])
            cl_cheque.save()
            cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
            
            share.mainwin.silent_daialog(_('successfully added. Document number : %d') % document.number)
#            infobar = gtk.InfoBar()
#            label = gtk.Label(_('successfully added. Document number : %d') % document.number)
#            infobar.get_content_area().add(label)
#            width , height = self.main_window_background.window.get_size()
#            infobar.set_size_request(width, -1)
#            self.main_window_background.put(infobar ,0 , 0)
#            infobar.show_all()
#
#            glib.timeout_add_seconds(3, lambda w: w.destroy(), infobar)

        #Store result in list store for showing in addeditdoc
        else:
            mysubject = Subjects()
            numrows = len(self.liststore) + 1
            #document.add_notebook(result['from'],  result['total_value'], result['desc'])
            self.liststore.append ((LN(numrows), LN(self.from_code), self.from_name, LN(0), LN(result['total_value']), result['desc'], None))
            #self.liststore.append ((numrows,                 code,                           sub.name,                          debt, credit,                              desc,           None))
            #document.add_notebook(result['to']  , -result['cash_payment'], result['desc'])
            numrows += 1
            self.liststore.append ((LN(numrows), LN(self.to_code), self.to_name, LN(result['cash_payment']), LN(0), result['desc'], None))
            if result['discount'] :
                numrows += 1
                self.liststore.append ((LN(numrows), LN(mysubject.get_code(dbconf.get_int('sell-discount'))), mysubject.get_name(dbconf.get_int('sell-discount')), LN(result['discount']), LN(0), result['desc'], None))

            #cl_cheque = class_cheque.ClassCheque()
            #or cheque in self.chequeui.new_cheques:
            #    if self.mode == 'our':
            #        document.add_cheque(dbconf.get_int('our_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #    else:
            #        document.add_cheque(dbconf.get_int('other_cheque'), -cheque['amount'], cheque['desc'], cheque['serial'])
            #spendble cheque
            #for sp_cheque in self.chequeui.spend_cheques:
            #   cl_cheque.update_status(sp_cheque['serial'],5)
            #    document.add_cheque(dbconf.get_int('other_cheque'), -sp_cheque['amount'] , unicode('kharj shodeh') , sp_cheque['serial'])
                    

            #if self.type_configs[self.type_index][3] == True: # from is subject
            #    customer_id = 0
            #else: # from is customer
            #    customer_id = config.db.session.query(Customers).select_from(Customers).filter(Customers.custSubj==self.from_id).first().custId

            #for cheque in self.chequeui.new_cheques:
            #    notebook_id =document.cheques_result[cheque['serial']]
            #    cl_cheque.add_cheque(cheque['amount'], cheque['write_date'], cheque['due_date'],
            #                         cheque['serial'], cheque['status'],
            #                         customer_id, cheque['bank_account_id'],
            #                         result, notebook_id, cheque['desc'])
            #cl_cheque.save()
            #cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
Example #14
0
    def on_save_button_clicked(self, button):
        share.config.db.session.rollback() 
        result = {}
        result['type']                  = self.type_index
        result['total_value']           = self.total_credit_entry.get_float()
        result['cash_payment']          = self.cash_payment_entry.get_float()
        result['non_cash_payment']      = self.builder.get_object('non-cash-payment-label').get_text()
        result['spend_cheque']          = self.builder.get_object('spend-cheque-label').get_text()
        result['discount']              = self.discount_entry.get_float()
        result['non-cash-payment-info'] = None # TODO: = non cash payment infos
        result['spend-cheque-info']     = None # TODO = spent cheque infos
        result['desc']                  = self.builder.get_object('desc').get_text()
        result['from']                  = self.from_id
        result['to']                    = self.to_id

        dbconf = dbconfig.dbConfig()

        #Save data in data base for single use
        if self.liststore == None:
            type(result['from'])
            if self.type_index is not None and self.type_configs[self.type_index][3]:
                mode = 'our'                
            else:
                mode = 'other'            
            desc = result['desc']
            if desc =="":
                desc = self.type_names[self.type_index][1]            
            document = class_document.Document()
            if result['cash_payment']  :
                document.add_notebook(result['from'], result['cash_payment'], unicode(desc))
                document.add_notebook(result['to']  ,  -result['cash_payment'], unicode(desc ))
            if result['discount'] :
                document.add_notebook(dbconf.get_int('sell-discount'), -result['discount'], desc)            

            if self.type_configs[self.type_index][3] == True: # from is subject
                custSubj = self.to_id                
            else: # from is customer
                custSubj = self.from_id
            print custSubj
            customer_id = share.config.db.session.query(Customers).filter(Customers.custSubj==custSubj).first().custId

            for cheque in self.addChequeui.chequesList:
                if mode == 'our':
                    document.add_cheque(dbconf.get_int('our_cheque'),custSubj,(cheque.chqAmount), cheque.chqDesc, cheque.chqId)
                else:
                    document.add_cheque(dbconf.get_int('other_cheque'),custSubj, -cheque.chqAmount, cheque.chqDesc, cheque.chqId)            

            cl_cheque = class_cheque.ClassCheque()

            #spendble cheques
            for sp_cheque in self.spendChequeui.chequesList:
                cl_cheque.update_status(sp_cheque.chqId,5 , customer_id)
                document.add_cheque(custSubj, dbconf.get_int('other_cheque'), -sp_cheque.chqAmount , unicode(_('Cheque No. %s spended') % sp_cheque.chqSerial) , sp_cheque.chqId)
                    
            result = document.save()

            if result < 0:
                dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _('Failed, %s') % document.get_error_message(result))
                dialog.run()
                dialog.destroy()
                return


            for cheque in self.addChequeui.chequesList:                
                cl_cheque.add_cheque(cheque.chqAmount, cheque.chqWrtDate, cheque.chqDueDate,
                                     cheque.chqSerial, cheque.chqStatus,
                                     customer_id, cheque.chqAccount,
                                     0, 0, cheque.chqDesc, 0, 0)
            cl_cheque.save()
            cl_cheque.save_cheque_history(self.current_time)
            self.on_destroy(self.builder.get_object('general'))
            
            share.mainwin.silent_daialog(_('successfully added. Document number : %d') % document.number)


        #Store result in list store for showing in addeditdoc
        else:
            mysubject = Subjects()
            numrows = len(self.liststore) + 1
            #document.add_notebook(result['from'],  result['total_value'], result['desc'])
            self.liststore.append ((LN(numrows), unicode(self.from_code), unicode(self.from_name), LN(0), LN(result['total_value']), result['desc'], None))
            #self.liststore.append ((numrows,                 code,                           sub.name,                          debt, credit,                              desc,           None))
            #document.add_notebook(result['to']  , -result['cash_payment'], result['desc'])
            numrows += 1
            self.liststore.append ((LN(numrows), unicode(self.to_code), unicode(self.to_name), LN(result['cash_payment']), LN(0), result['desc'], None))
            if result['discount'] :
                numrows += 1
                self.liststore.append ((LN(numrows), unicode(mysubject.get_code(dbconf.get_int('sell-discount'))), mysubject.get_name(dbconf.get_int('sell-discount')), LN(result['discount']), LN(0), result['desc'], None))

            self.on_destroy(self.builder.get_object('general'))
Example #15
0
    def on_type_change(self, combo):
        iter =  combo.get_active_iter()

        if iter == None:
            return
        
        # self.chequeui.new_cheques = []
        # self.chequeui.spend_cheques = []
        model = combo.get_model()
        index = model.get(iter, 0)[0]
        self.type_index = int(index)
        
        save_button = self.builder.get_object('save-button')
        
        non_cash, discount, spend_cheque = self.type_configs[self.type_index][:3]

        self.builder.get_object('discount-button').set_sensitive(discount)
        self.discount_entry.set_sensitive(discount)
        
        self.builder.get_object('list-cheque-button').set_sensitive(spend_cheque)
        self.builder.get_object('spend-cheque-label').set_sensitive(spend_cheque)

        self.builder.get_object('non-cash-payment-label').set_sensitive(non_cash)
        self.builder.get_object('non_cash_payment_button').set_sensitive(non_cash)

        self.cash_payment_entry.set_sensitive((non_cash or spend_cheque))

        self.from_entry.set_text("")
        self.to_entry.set_text("")
        self.cash_payment_entry.set_text(LN(0))
        self.total_credit_entry.set_text(LN(0))
        self.discount_entry.set_text(LN(0))

        dbconf = dbconfig.dbConfig()

        if self.type_index == 5:
            self.builder.get_object('to-button').set_sensitive(False)
            query = share.config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.id == dbconf.get_int('bank-wage'))
            query = query.first()
            self.to_id =  query.id
            self.to_entry.set_text(query.name)
            self.to_code = query.code
            self.to_name = query.name            
        elif self.type_index in [0,4] :
            self.builder.get_object('to-button').set_sensitive(False)
            query = share.config.db.session.query(Subject).select_from(Subject)
            query = query.filter(Subject.id == dbconf.get_int('cash'))
            query = query.first()
            self.to_id =  query.id
            self.to_entry.set_text(query.name)
            self.to_code = query.code
            self.to_name = query.name
        else:
            self.builder.get_object('to-button').set_sensitive(True)

        # resetting non-cash payments UI for adding :
        sellMode = 0
        if self.type_index is not None and self.type_configs[self.type_index][3]:
            #mode = 'our'
            sellMode = 0    # pardakhti
            customerEntry = self.to_entry
        else:
            #mode = 'other'
            sellMode = 1    # daryafti 
            customerEntry = self.from_entry
        self.addChequeui = payments.Payments(0 , sellMode , False)
        self.addChequeui.fillChequeTable()
        self.addChequeui.customerNameLbl.set_text(customerEntry.get_text())
        self.addChequeui.connect("payments-changed",self.update_non_cash_payment_label  )
Example #16
0
    def editCustAndGrps(self, sender):
        selection = self.treeview.get_selection()
        iter = selection.get_selected()[1]

        if self.treestore.iter_parent(iter) == None:
            #Iter points to a customer group
            self.editCustomerGroup(sender)
        else:
            code = self.treestore.get_value(iter, 0)
            code = readNumber(code)
            query = config.db.session.query(Customers, CustGroups.custGrpCode)
            query = query.select_from(
                outerjoin(CustGroups, Customers,
                          CustGroups.custGrpId == Customers.custGroup))
            result = query.filter(Customers.custCode == code).first()
            customer = result[0]
            groupcode = result[1]

            custCode = LN(customer.custCode, False)
            custGrp = LN(groupcode, False)
            custPhone = LN(customer.custPhone, False)
            custCell = LN(customer.custCell, False)
            custFax = LN(customer.custFax, False)
            custPostalCode = LN(customer.custPostalCode, False)

            self.customerForm = self.builder.get_object("customersWindow")
            self.customerForm.set_title(_("Edit Customer"))
            self.builder.get_object("addCustSubmitBtn").set_label(
                _("Save Customer"))

            self.builder.get_object("custCodeEntry").set_text(custCode)
            self.builder.get_object("custNameEntry").set_text(
                customer.custName)
            self.custgrpentry.set_text(groupcode)
            self.builder.get_object("custEcnmcsCodeEntry").set_text(
                customer.custEcnmcsCode)
            self.builder.get_object("custPrsnalCodeEntry").set_text(
                customer.custPersonalCode)
            self.builder.get_object("custPhoneEntry").set_text(custPhone)
            self.builder.get_object("custCellEntry").set_text(custCell)
            self.builder.get_object("custFaxEntry").set_text(custFax)
            self.builder.get_object("custWebPageEntry").set_text(
                customer.custWebPage)
            self.builder.get_object("custEmailEntry").set_text(
                customer.custEmail)
            self.builder.get_object("custRepViaEmailChk").set_active(
                customer.custRepViaEmail)
            self.builder.get_object("custAddressEntry").set_text(
                customer.custAddress)
            self.builder.get_object("callResponsibleEntry").set_text(
                customer.custResposible)
            self.builder.get_object("custConnectorEntry").set_text(
                customer.custConnector)
            self.builder.get_object("custDescEntry").set_text(
                customer.custDesc)
            self.builder.get_object("custTypeBuyerChk").set_active(
                customer.custTypeBuyer)
            #----------------------------------
            self.builder.get_object("custTypeSellerChk").set_active(
                customer.custTypeSeller)
            self.builder.get_object("custTypeMateChk").set_active(
                customer.custTypeMate)
            self.builder.get_object("custTypeAgentChk").set_active(
                customer.custTypeAgent)
            #self.custIntroducerEntry.set_text(customer.custIntroducer)
            self.boxCommissionRateEntry.set_text(customer.custCommission)
            self.boxDiscRateEntry.set_text(customer.custDiscRate)
            self.builder.get_object("markedChk").set_active(
                customer.custMarked)
            self.builder.get_object("markedReasonEntry").set_text(
                customer.custReason)
            #----------------------------------
            self.boxBalanceEntry.set_text(LN(customer.custBalance, False))
            self.boxCreditEntry.set_text(LN(customer.custCredit, False))
            self.builder.get_object("custAccName1Entry").set_text(
                customer.custAccName1)
            self.builder.get_object("custAccNo1Entry").set_text(
                customer.custAccNo1)
            self.builder.get_object("custAccBank1Entry").set_text(
                customer.custAccBank1)
            self.builder.get_object("custAccName2Entry").set_text(
                customer.custAccName2)
            self.builder.get_object("custAccNo2Entry").set_text(
                customer.custAccNo2)
            self.builder.get_object("custAccBank2Entry").set_text(
                customer.custAccBank2)

            self.builder.get_object("cusPostalCodeEntry").set_text(
                LN(customer.custPostalCode, False))
            self.builder.get_object("markedReasonEntry").set_sensitive(
                self.builder.get_object("markedChk").get_active())

            self.customerForm.show_all()

            self.editCustomer = True
            self.customerId = customer.custId
            self.editIter = iter
Example #17
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
Example #18
0
    def saveLedger(self, name, type, iter, edit, widget):
        if name == "":
            msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL,
                                       gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                       _("Subject name should not be empty."))
            msgbox.set_title(_("Empty subject name"))
            msgbox.run()
            msgbox.destroy()
        else:
            #Check to see if a subject with the given name exists already.
            if iter == None:
                iter_code = ""
                parent_id = 0
                parent_right = 0
                parent_left = 0
            else:
                iter_code = convertToLatin(self.treestore.get(iter, 0)[0])
                query = config.db.session.query(Subject).select_from(Subject)
                query = query.filter(Subject.code == iter_code)
                sub = query.first()
                if edit == True:
                    iter_id = sub.id
                    parent_id = sub.parent_id
                    temp_code = iter_code
                    iter_code = iter_code[0:-2]
                    parent_right = sub.rgt
                    parent_left = sub.lft
                else:
                    parent_id = sub.id
                    parent_right = sub.rgt
                    parent_left = sub.lft

            query = config.db.session.query(count(
                Subject.id)).select_from(Subject)
            query = query.filter(
                and_(Subject.name == name, Subject.parent_id == parent_id))
            if edit == True:
                query = query.filter(Subject.id != iter_id)
            result = query.first()

            if result[0] != 0:
                msgbox = gtk.MessageDialog(
                    widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
                    gtk.BUTTONS_CLOSE,
                    _("A subject with this name already exists in the current level."
                      ))
                msgbox.set_title(_("Duplicate subject name"))
                msgbox.run()
                msgbox.destroy()
                return

            #TODO pass code through function parameters
            lastcode = convertToLatin(self.code.get_text())[0:2]
            if lastcode == '':
                msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL,
                                           gtk.MESSAGE_ERROR,
                                           gtk.BUTTONS_CLOSE,
                                           _("Ledger Code field is empty"))
                msgbox.set_title(_("Invalid subject code"))
                msgbox.run()
                msgbox.destroy()
                return

            lastcode = iter_code + lastcode[0:2]
            query = config.db.session.query(count(
                Subject.id)).select_from(Subject)
            query = query.filter(
                and_(Subject.parent_id == parent_id, Subject.code == lastcode))
            if edit == True:
                query = query.filter(Subject.id != iter_id)
                result = query.first()

            if result[0] != 0:
                msgbox = gtk.MessageDialog(
                    widget, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
                    gtk.BUTTONS_CLOSE,
                    _("A subject with this code already exists."))
                msgbox.set_title(_("Duplicate subject code"))
                msgbox.run()
                msgbox.destroy()
                return

            if edit == True:
                query = config.db.session.query(count(
                    Notebook.id)).select_from(Notebook)
                query = query.filter(Notebook.subject_id == iter_id)
                rowcount = 0
                msg = ""
                if type == 1:
                    rowcounts = query.filter(Notebook.value < 0).first()
                    rowcount = rowcounts[0]
                    msg = _(
                        "The type of this subject can not be changed to 'creditor', Because there are \
                            %d documents that use it as debtor.") % rowcount
                elif type == 0:
                    rowcounts = query.filter(Notebook.value > 0).first()
                    rowcount = rowcounts[0]
                    msg = _(
                        "The type of this subject can not be changed to 'debtor', Because there are \
                            %d documents that use it as creditor.") % rowcount
                if (rowcount > 0):
                    msgbox = gtk.MessageDialog(widget, gtk.DIALOG_MODAL,
                                               gtk.MESSAGE_ERROR,
                                               gtk.BUTTONS_CLOSE, msg)
                    msgbox.set_title(_("Can not change subject type"))
                    msgbox.run()
                    msgbox.destroy()
                    return

                sub.code = lastcode
                sub.name = name
                sub.type = type

                #update subledger codes if parent ledger code has changed
                length = len(lastcode)
                if temp_code != lastcode:
                    query = config.db.session.query(Subject).select_from(
                        Subject)
                    query = query.filter(
                        and_(Subject.lft > parent_left,
                             Subject.rgt < parent_right))
                    result = query.all()
                    for child in result:
                        child.code = lastcode + child.code[length:]
                        config.db.session.add(child)

                config.db.session.commit()

                #TODO show updated children on screen
                basecode = LN(lastcode, False)

                if temp_code != lastcode:
                    #                    chiter = self.treestore.iter_children(iter)
                    tempstore = self.treestore.filter_new(
                        self.treestore.get_path(iter))
                    tempstore.foreach(self.editChildCodes, (basecode, length))
#                    while chiter:
#                        chcode = self.treestore.get(chiter, 0)[0]
#                        chcode = utility.convertToLatin(chcode)[-2:]
#                        if config.digittype == 1:
#                            chcode = utility.convertToPersian(chcode)
#                        self.treestore.set(chiter, 0, basecode + chcode )
#                        chiter = self.treestore.iter_next(chiter)

                self.treestore.set(iter, 0, basecode, 1, name, 2,
                                   _(self.subjecttypes[type]))

            else:
                #                    query = self.session.query(Subject.code).select_from(Subject).order_by(Subject.id.desc())
                #                    code = query.filter(Subject.parent_id == parent_id).first()
                #                    if code == None :
                #                        lastcode = "01"
                #                    else :
                #                        lastcode = "%02d" % (int(code[0][-2:]) + 1)

                # If row have not been expanded yet, function 'populateChidren' will be executed and adds children
                # to the row, then we insert new child in the database and call treeview.append to add it to the
                # end of the tree.
                if iter != None:
                    self.treeview.expand_row(self.treestore.get_path(iter),
                                             False)
                    sub_right = config.db.session.query(max(
                        Subject.rgt)).select_from(Subject).filter(
                            Subject.parent_id == parent_id).first()
                    sub_right = sub_right[0]
                    if sub_right == None:
                        sub_right = parent_left

                else:
                    #sub_right = self.session.query(Subject.rgt).select_from(Subject).order_by(Subject.rgt.desc()).first();
                    sub_right = config.db.session.query(max(
                        Subject.rgt)).select_from(Subject).first()
                    sub_right = sub_right[0]
                    if sub_right == None:
                        sub_right = 0

                #Update subjects which we want to place new subject before them:
                rlist = config.db.session.query(Subject).filter(
                    Subject.rgt > sub_right).all()
                for r in rlist:
                    r.rgt += 2
                    config.db.session.add(r)

                llist = config.db.session.query(Subject).filter(
                    Subject.lft > sub_right).all()
                for l in llist:
                    l.lft += 2
                    config.db.session.add(l)

                sub_left = sub_right + 1
                sub_right = sub_left + 1

                #Now create new subject:
                ledger = Subject(lastcode, name, parent_id, sub_left,
                                 sub_right, type)
                config.db.session.add(ledger)

                config.db.session.commit()

                lastcode = LN(lastcode, False)
                child = self.treestore.append(
                    iter,
                    (lastcode, name, _(self.subjecttypes[type]), LN("0")))

                self.temppath = self.treestore.get_path(child)
                self.treeview.scroll_to_cell(self.temppath, None, False, 0, 0)
                self.treeview.set_cursor(self.temppath, None, False)
Example #19
0
    def __init__(self, ledgers_only=False,
                 parent_id=[
                     0,
                 ], multiselect=False):
        gobject.GObject.__init__(self)

        self.builder = get_builder("notebook")

        self.window = self.builder.get_object("subjectswindow")
        self.window.set_modal(True)

        self.treeview = self.builder.get_object("treeview")

        if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL:
            halign = 1
        else:
            halign = 0

        self.treestore = gtk.TreeStore(str, str, str, str)
        column = gtk.TreeViewColumn(_("Subject Code"),
                                    gtk.CellRendererText(),
                                    text=0)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Subject Name"),
                                    gtk.CellRendererText(),
                                    text=1)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Debtor or Creditor"),
                                    gtk.CellRendererText(),
                                    text=2)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        column = gtk.TreeViewColumn(_("Sum"), gtk.CellRendererText(), text=3)
        column.set_alignment(halign)
        column.set_spacing(5)
        column.set_resizable(True)
        self.treeview.append_column(column)
        self.treeview.get_selection().set_mode(gtk.SELECTION_SINGLE)

        self.code = numberentry.NumberEntry()
        box = self.builder.get_object("codebox")
        box.add(self.code)
        self.code.show()

        #config.db.session = config.db.session

        Subject1 = aliased(Subject, name="s1")
        Subject2 = aliased(Subject, name="s2")

        #Find top level ledgers (with parent_id equal to 0)
        query = config.db.session.query(Subject1.code, Subject1.name,
                                        Subject1.type, Subject1.lft,
                                        Subject1.rgt, count(Subject2.id))
        query = query.select_from(
            outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id))
        if len(parent_id) == 1:
            result = query.filter(Subject1.parent_id == parent_id[0]).group_by(
                Subject1.id).all()
        else:
            result = query.filter(Subject1.id.in_(parent_id)).group_by(
                Subject1.id).all()

        for a in result:
            type = _(self.subjecttypes[a[2]])
            code = LN(a[0], False)
            #--------
            subject_sum = config.db.session.query(sum(
                Notebook.value)).select_from(
                    outerjoin(Subject, Notebook,
                              Subject.id == Notebook.subject_id))
            subject_sum = subject_sum.filter(
                and_(Subject.lft >= a.lft, Subject.lft <= a.rgt)).first()
            subject_sum = subject_sum[0]

            if (subject_sum == None):
                subject_sum = LN("0")
            else:
                if (subject_sum < 0):
                    subject_sum = "( -" + LN(-subject_sum) + " )"
                else:
                    subject_sum = LN(subject_sum)

            iter = self.treestore.append(None, (code, a[1], type, subject_sum))
            if (a[5] != 0 and ledgers_only == False):
                #Add empty subledger to show expander for ledgers which have chidren
                self.treestore.append(iter, ("", "", "", ""))

        if ledgers_only == True:
            btn = self.builder.get_object("addsubtoolbutton")
            btn.hide()

        self.treeview.set_model(self.treestore)
        self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING)
        self.window.show_all()
        self.builder.connect_signals(self)
        #self.rebuild_nested_set(0, 0)

        if multiselect:
            self.treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
            self.builder.get_object('toolbar4').hide_all()
            self.builder.get_object('statusbar1').hide_all()
        else:
            self.builder.get_object('hbox5').hide_all()