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 = utility.convertToLatin(self.treestore.get(chiter, 1)[0]) if value == "": value = utility.convertToLatin(self.treestore.get(iter, 0)[0]) #remove empty subledger to add real children instead self.treestore.remove(chiter) Sub = aliased(Subject, name="s") Child = aliased(Subject, name="c") Parent = aliased(Subject, name="p") query = config.db.session.query(Sub.code, Sub.name, Sub.type, count(Child.id), Sub.lft, Sub.rgt) query = query.select_from( outerjoin( outerjoin(Parent, Sub, Sub.parent_id == Parent.id), Child, Sub.id == Child.parent_id)) result = query.filter(Parent.code == value).group_by( Sub.id).all() for row in result: code = row[0] if config.digittype == 1: code = utility.convertToPersian(code) type = _(self.__class__.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.rgt)).first() subject_sum = subject_sum[0] if (subject_sum == None): subject_sum = utility.showNumber("0") else: if (subject_sum < 0): subject_sum = "(-" + utility.showNumber( -subject_sum) + ")" else: subject_sum = utility.showNumber(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
def selectProductFromList(self, treeview, path, view_column): iter = self.treestore.get_iter(path) if self.treestore.iter_parent(iter) != None: code = utility.convertToLatin(self.treestore.get_value(iter, 0)) parent_iter = self.treestore.iter_parent(iter) group = utility.convertToLatin( self.treestore.get_value(parent_iter, 0)) query = config.db.session.query(Products).select_from(Products) query = query.filter(Products.code == code).filter( Products.accGroup == group) product_id = query.first().id self.emit("product-selected", product_id, code)
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) self.treestore.set(model.convert_iter_to_child_iter(iter), 0, basecode + chcode )
def editCustomerGroup(self, sender): dialog = self.builder.get_object("addCustGrpDlg") dialog.set_title(_("Edit group")) selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: if config.digittype == 1: code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) else: code = self.treestore.get(iter, 0)[0] query = config.db.session.query(CustGroups).select_from(CustGroups) group = query.filter(CustGroups.custGrpCode == code).first() name = group.custGrpName desc = group.custGrpDesc self.grpCodeEntry.set_text(code) self.builder.get_object("grpNameEntry").set_text(name) self.builder.get_object("grpDescEntry").set_text(desc) result = dialog.run() if result == 1: grpcode = self.grpCodeEntry.get_text() grpname = self.builder.get_object("grpNameEntry").get_text() grpdesc = self.builder.get_object("grpDescEntry").get_text() self.saveCustGroup(grpcode, unicode(grpname), unicode(grpdesc), iter) dialog.hide()
def onFreeChequeSelected(self, sender, path=None, col=0): treeiter = self.sltCheqListStore.get_iter(path) chequeId = utility.convertToLatin( self.sltCheqListStore.get_value(treeiter, 0)) cheque = self.session.query(Cheque).filter( Cheque.chqId == chequeId).first() cheque.chqStatus = 5 cheque.chqTransId = self.transId self.chequesList.append(cheque) self.numcheqs += 1 #chequeNo = self.sltCheqListStore.get_value(treeiter , 1) chequeCust = self.sltCheqListStore.get_value(treeiter, 2) chequeAmnt = self.sltCheqListStore.get_value(treeiter, 3) chequeWDate = self.sltCheqListStore.get_value(treeiter, 4) chequeDDate = self.sltCheqListStore.get_value(treeiter, 5) chequeBank = self.sltCheqListStore.get_value(treeiter, 6) chequeSerial = self.sltCheqListStore.get_value(treeiter, 7) chequeStatus = self.chequeStatus[ cheque.chqStatus] #self.sltCheqListStore.get_value(treeiter , 7) chequeDesc = self.sltCheqListStore.get_value(treeiter, 7) self.cheqListStore.append( (chequeId, utility.LN(self.numcheqs), chequeCust, chequeAmnt, chequeWDate, chequeDDate, chequeBank, chequeSerial, chequeStatus, chequeDesc)) self.addToTotalAmount(utility.getFloat(chequeAmnt)) #self.cheqListStore .append(cheque) self.closeSltChqWnd()
def saveDocument(self, sender): sender.grab_focus() self.cl_document.date = self.date.getDateObject() #TODO if number is not equal to the maximum BigInteger value, prevent bill registration. iter = self.liststore.get_iter_first() while iter != None: code = utility.convertToLatin(self.liststore.get(iter, 1)[0]) debt = utility.getFloatNumber(self.liststore.get(iter, 3)[0]) value = -(debt) if (self.liststore.get(iter, 6)[0] != None): id = self.liststore.get(iter, 6)[0] else: id = 0 if value == 0: credit = utility.getFloatNumber(self.liststore.get(iter, 4)[0]) value = credit desctxt = unicode(self.liststore.get(iter, 5)[0]) query = config.db.session.query(Subject) query = query.filter(Subject.code == code) subject_id = query.first().id self.cl_document.add_notebook(subject_id, value, desctxt, int(id)) iter = self.liststore.iter_next(iter) result = self.cl_document.save(delete_items=self.deleted_items) self.deleted_items = [] if result == -1: msgbox = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Document should not be empty")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() self.cl_document.clear_notebook() return elif result == -2: msgbox = Gtk.MessageDialog( self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, _("Debt sum and Credit sum should be equal")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() self.cl_document.clear_notebook() return else: self.liststore.clear() self.deleted_items = [] self.cl_document.clear_notebook() self.showRows() docnum = utility.LN(self.cl_document.number) self.builder.get_object("docnumber").set_text(docnum) share.mainwin.silent_daialog( _("Document saved with number %s.") % docnum)
def deleteLedger(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") code = convertToLatin(self.treestore.get(iter, 0)[0]) #Check to see if there is any subledger for this ledger. query = config.db.session.query(Subject1.id, count(Subject2.id)) query = query.select_from( outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.code == code).first() if result[1] != 0: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject can not be deleted, because it has some child subjects." )) msgbox.set_title(_("Error deleting subject")) msgbox.run() msgbox.destroy() else: # check to see if there is any document registered for this ledger. query = config.db.session.query(count(Notebook.id)) query = query.filter(Notebook.subject_id == result[0]) rowcount = query.first()[0] if rowcount != 0: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject can not be deleted, because there are some documents registered for it." )) msgbox.set_title(_("Error deleting subject")) msgbox.run() msgbox.destroy() else: # Now it's OK to delete ledger row = config.db.session.query(Subject).filter( Subject.id == result[0]).first() sub_left = row.lft config.db.session.delete(row) rlist = config.db.session.query(Subject).filter( Subject.rgt > sub_left).all() for r in rlist: r.rgt -= 2 config.db.session.add(r) llist = config.db.session.query(Subject).filter( Subject.lft > sub_left).all() for l in llist: l.lft -= 2 config.db.session.add(l) config.db.session.commit() self.treestore.remove(iter)
def deleteCustomerGroup(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) query = config.db.session.query(CustGroups, count(Customers.custId)) query = query.select_from( outerjoin(CustGroups, Customers, CustGroups.custGrpId == Customers.custGroup)) result = query.filter(CustGroups.custGrpCode == code).first() if result[1] != 0: msgbox = gtk.MessageDialog( self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Group can not be deleted, Because there are some customers registered in it." )) msgbox.set_title(_("Error deleting group")) msgbox.run() msgbox.destroy() else: group = result[0] config.db.session.delete(group) config.db.session.commit() self.treestore.remove(iter)
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)
def selectCustGroupFromList(self, treeview, path, view_column): iter = self.treestore.get_iter(path) code = utility.convertToLatin(self.treestore.get_value(iter, 0)) query = config.db.session.query(CustGroups).select_from(CustGroups) query = query.filter(CustGroups.custGrpCode == code) group_id = query.first().custGrpId self.emit("group-selected", group_id, code)
def editChildCodes(self, model, path, iter, data): basecode = data[0] length = data[1] chcode = model.get(iter, 0)[0] chcode = utility.convertToLatin(chcode)[length:] if config.digittype == 1: chcode = utility.convertToPersian(chcode) self.treestore.set(model.convert_iter_to_child_iter(iter), 0, basecode + chcode )
def match_func(self, iter, data): (column, key) = data # data is a tuple containing column number, key value = convertToLatin(self.treestore.get_value(iter, column)) if value < key: return -1 elif value == key: return 0 else: return 1
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()
def selectSubjectFromList(self, treeview, path, view_column): iter = self.treestore.get_iter(path) code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) name = self.treestore.get(iter, 1)[0] query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub_id = query.first().id self.emit("subject-selected", sub_id, code, name)
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 = utility.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) if config.digittype == 1: lastcode = utility.convertToPersian(lastcode) 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()
def editChildCodes(self, model, path, iter, data): basecode = data[0] length = data[1] chcode = model.get(iter, 0)[0] chcode = utility.convertToLatin(chcode)[length:] if config.digittype == 1: chcode = utility.convertToPersian(chcode) self.treestore.set(model.convert_iter_to_child_iter(iter), 0, basecode + chcode)
def selectCustomerFromList(self, treeview, path, view_column): iter = self.treestore.get_iter(path) if self.treestore.iter_parent(iter) != None: code = utility.convertToLatin(self.treestore.get_value(iter, 0)) query = config.db.session.query(Customers).select_from(Customers) query = query.filter(Customers.custCode == code) customer_id = query.first().custId self.emit("customer-selected", customer_id, code)
def deleteGroup(self, sender): selection = self.groupTreeview.get_selection() iter = selection.get_selected()[1] if iter != None: code = convertToLatin(self.groupTreestore.get(iter, 0)[0]) row = config.db.session.query(Permissions).filter( Permissions.id == code).first() config.db.session.delete(row) config.db.session.commit() self.groupTreestore.remove(iter)
def saveDocument(self, sender): sender.grab_focus() self.cl_document.date = self.date.getDateObject() #TODO if number is not equal to the maximum BigInteger value, prevent bill registration. iter = self.liststore.get_iter_first() while iter != None : code = utility.convertToLatin(self.liststore.get(iter, 1)[0]) debt = unicode(self.liststore.get(iter, 3)[0].replace(",", "")) value = -(int(debt)) if(self.liststore.get(iter,6)[0] != None): id = self.liststore.get(iter,6)[0] else: id = 0 if value == 0 : credit = unicode(self.liststore.get(iter, 4)[0].replace(",", "")) value = int(credit) desctxt = unicode(self.liststore.get(iter, 5)[0]) query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) subject_id = query.first().id self.cl_document.add_notebook(subject_id, value, desctxt, int(id)) iter = self.liststore.iter_next(iter) result = self.cl_document.save(self.deleted_items) if result == -1: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Document should not be empty")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() self.cl_document.clear_notebook() return elif result == -2: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Debt sum and Credit sum should be equal")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() self.cl_document.clear_notebook() return else: self.liststore.clear() self.deleted_items = [] self.showRows() docnum = utility.LN(self.cl_document.number) self.builder.get_object("docnumber").set_text (docnum) share.mainwin.silent_daialog(_("Document saved with number %s.") % docnum)
def selectGroupFromList(self, treeview, path, view_column): selection = self.groupTreeview.get_selection() if selection.get_mode() == Gtk.SelectionMode.MULTIPLE: return iter = self.groupTreestore.get_iter(path) self.groupId = convertToLatin(self.groupTreestore.get(iter, 0)[0]) self.groupName = self.groupTreestore.get(iter, 1)[0] self.builder.get_object("permissionEdit").set_text(self.groupName) self.builder.get_object("permissionNew").set_text(self.groupName) self.window1.hide()
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 = utility.convertToLatin(self.treestore.get(chiter, 1)[0]) if value == "" : value = utility.convertToLatin(self.treestore.get(iter, 0)[0]) #remove empty subledger to add real children instead self.treestore.remove(chiter) Sub = aliased(Subject, name="s") Child = aliased(Subject, name="c") Parent = aliased(Subject, name="p") query = config.db.session.query(Sub.code, Sub.name, Sub.type, count(Child.id), Sub.lft, Sub.rgt) query = query.select_from(outerjoin(outerjoin(Parent, Sub, Sub.parent_id == Parent.id), Child, Sub.id == Child.parent_id)) result = query.filter(Parent.code == value).group_by(Sub.id).all() for row in result : code = row[0] if config.digittype == 1: code = utility.convertToPersian(code) type = _(self.__class__.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.rgt)).first() subject_sum = subject_sum[0] if(subject_sum == None): subject_sum = utility.showNumber("0") else : if(subject_sum < 0): subject_sum = "(-" + utility.showNumber(-subject_sum) + ")" else : subject_sum = utility.showNumber(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
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: if config.digittype == 1: code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) pcode = utility.convertToPersian(code[0:-2]) ccode = utility.convertToPersian(code[-2:]) else: code = self.treestore.get(iter, 0)[0] pcode = code[0:-2] ccode = code[-2:] 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.__class__.subjecttypes[0]: self.builder.get_object("debtor").set_active(True) else: if type == self.__class__.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()
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 = utility.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) if config.digittype == 1: lastcode = utility.convertToPersian(lastcode) 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()
def selectSubjectFromList(self, treeview, path, view_column): selection = self.treeview.get_selection() if selection.get_mode() == gtk.SELECTION_MULTIPLE: return iter = self.treestore.get_iter(path) code = convertToLatin(self.treestore.get(iter, 0)[0]) name = self.treestore.get(iter, 1)[0] query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub_id = query.first().id self.emit("subject-selected", sub_id, code, name)
def deleteUser(self, sender): selection = self.userTreeview.get_selection() iter = selection.get_selected()[1] if iter != None: Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") code = convertToLatin(self.userTreestore.get(iter, 0)[0]) row = config.db.session.query(Users).filter( Users.id == code).first() config.db.session.delete(row) config.db.session.commit() self.userTreestore.remove(iter)
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()
def on_select_clicked(self, button): selection = self.treeview.get_selection() items = [] model, pathes = selection.get_selected_rows() for path in pathes: iter = self.treestore.get_iter(path) code = convertToLatin(self.treestore.get(iter, 0)[0]) name = self.treestore.get(iter, 1)[0] query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub_id = query.first().id items.append((sub_id, code, name)) self.emit("subject-multi-selected", items)
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 : if config.digittype == 1: code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) pcode = utility.convertToPersian(code[0:-2]) ccode = utility.convertToPersian(code[-2:]) else: code = self.treestore.get(iter, 0)[0] pcode = code[0:-2] ccode = code[-2:] 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.__class__.subjecttypes[0]: self.builder.get_object("debtor").set_active(True) else: if type == self.__class__.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()
def deleteCustAndGrps(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: msgbox = Gtk.MessageDialog(self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK_CANCEL, _("Are you sure to remove this row?")) msgbox.set_title(_("Are you sure?")) result = msgbox.run() msgbox.destroy() if result != Gtk.ResponseType.OK: return if self.treestore.iter_parent(iter) == None: #Iter points to a customer group self.deleteCustomerGroup(sender) else: #Iter points to a customer code = utility.convertToLatin(self.treestore.get_value(iter, 0)) query = config.db.session.query(Customers) customer = query.filter(Customers.custCode == code).first() custId = customer.custId q1 = config.db.session.query(Factors.Cust).filter( Factors.Cust == custId) #.limit(1) q2 = config.db.session.query(Cheque.chqCust).filter( Cheque.chqCust == custId) #.limit(1) existsFlag = (q1.union(q2)).first() if existsFlag: msgbox = Gtk.MessageDialog( self.window, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, _("Customer can not be deleted, Because there are some Factors or Cheques related to it. \nPlease delete them first.\n(Note: If there is some cheque, deleting that will not be usefull.)" )) msgbox.set_title(_("Error deleting customer")) msgbox.run() msgbox.destroy() else: subjectCode = config.db.session.query(Subject).filter( Subject.id == dbconf.get_int('custSubject')).first().code subjectCode = unicode(subjectCode) + unicode(code) #TODO check if this customer is used somewhere else config.db.session.delete(customer) config.db.session.delete( config.db.session.query(Subject).filter( Subject.code == subjectCode).first()) config.db.session.commit() self.treestore.remove(iter)
def deleteLedger(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None : Subject1 = aliased(Subject, name="s1") Subject2 = aliased(Subject, name="s2") code = utility.convertToLatin(self.treestore.get(iter, 0)[0]) #Check to see if there is any subledger for this ledger. query = config.db.session.query(Subject1.id, count(Subject2.id)) query = query.select_from(outerjoin(Subject1, Subject2, Subject1.id == Subject2.parent_id)) result = query.filter(Subject1.code == code).first() if result[1] != 0 : msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject can not be deleted, because it has some child subjects.")) msgbox.set_title(_("Error deleting subject")) msgbox.run() msgbox.destroy() else : # check to see if there is any document registered for this ledger. query = config.db.session.query(count(Notebook.id)) query = query.filter(Notebook.subject_id == result[0]) rowcount = query.first()[0] if rowcount != 0 : msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("Subject can not be deleted, because there are some documents registered for it.")) msgbox.set_title(_("Error deleting subject")) msgbox.run() msgbox.destroy() else : # Now it's OK to delete ledger row = config.db.session.query(Subject).filter(Subject.id == result[0]).first() sub_left = row.lft config.db.session.delete(row) rlist = config.db.session.query(Subject).filter(Subject.rgt > sub_left).all() for r in rlist: r.rgt -= 2 config.db.session.add(r) llist = config.db.session.query(Subject).filter(Subject.lft > sub_left).all() for l in llist: l.lft -= 2 config.db.session.add(l) config.db.session.commit() self.treestore.remove(iter)
def stringToDate(dateString): dateString = convertToLatin(dateString) delim = share.config.datedelims[share.config.datedelim] dateList = dateString.split(delim) if len(dateList) == 3: if dateList[0] != '' and dateList[1] != '' and dateList[2] != '': dy = int(dateList[share.config.datefields["year"]]) dm = int(dateList[share.config.datefields["month"]]) dd = int(dateList[share.config.datefields["day"]]) d = (dy, dm, dd) de = DateEntry(d) try: dateObj = de.getDateObject() except: return return dateObj
def addRow(self, sender): dialog = self.builder.get_object("dialog1") dialog.set_title(_("Add new row")) self.code.set_text("") desc = self.builder.get_object("desc") result = dialog.run() if result == 1: type = not (self.builder.get_object("debtor").get_active() == True) code = self.code.get_text() amount = self.amount.get_text() if code != '' and amount != '': self.saveRow(utility.convertToLatin(code), int(unicode(amount)), type, desc.get_text()) dialog.hide()
def editPay(self, sender=0): model = self.bankCombo.get_model() if self.sellFlag: # other's cheque banks = self.bankaccounts_class.get_bank_names() else: banks = self.bankaccounts_class.get_all_accounts() for item in banks: iter = model.append() name = item.Name if self.sellFlag else item.accName model.set(iter, 0, name) iter = self.cheqTreeView.get_selection().get_selected()[1] if iter == None: return else: number = utility.convertToLatin(self.cheqListStore.get(iter, 1)[0]) number = utility.getInt(number) cheque = self.chequesList[ number - 1] # reads from cheques list that holds temporary changes in cheque table. for adding or edditing without effect on database before submiting factor form if cheque.chqStatus == 5: return self.editid = cheque.chqId #payer_id = cheque.chqCust amount = utility.LN(cheque.chqAmount, False) serial = cheque.chqSerial wrtDate = cheque.chqWrtDate dueDate = cheque.chqDueDate desc = cheque.chqDesc self.chequeStatusLbl.set_text(self.chequeStatus[cheque.chqStatus]) self.bankCombo.set_active(cheque.chqAccount - 1) self.edtPymntFlg = True self.edititer = iter self.addPymntDlg.set_title(_("Edit Non-Cash Payment")) self.builder.get_object("submitBtn").set_label(_("Save Changes...")) self.builder.get_object("paymentsStatusBar").push(1, "") self.pymntAmntEntry.set_text(amount) self.serialNoEntry.set_text(serial) self.writeDateEntry.showDateObject(wrtDate) self.dueDateEntry.showDateObject(dueDate) self.pymntDescEntry.set_text(desc) self.addPymntDlg.show_all()
def editPermission(self, sender): dialog = self.builder.get_object("permissionWindow") dialog.set_title(_("Edit Permission")) selection = self.groupTreeview.get_selection() iter = selection.get_selected()[1] id = convertToLatin(self.groupTreestore.get(iter, 0)[0]) permissionName = self.groupTreestore.get(iter, 1)[0] permissionId = config.db.session.query( Permissions.id).filter(Permissions.name == permissionName).first() self.groupId = permissionId[0] self.setPermission(id) self.window = self.builder.get_object("permissionWindow") self.builder.connect_signals(self) entry = self.builder.get_object("nameEntry") entry.set_text(permissionName) okButton = self.builder.get_object("okButton") okButton.connect("clicked", self.saveEditPermission) self.window.show_all()
def editRow(self, sender): dialog = self.builder.get_object("dialog1") dialog.set_title(_("Edit row")) selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None : code = self.liststore.get(iter, 1)[0] debt = self.liststore.get(iter, 3)[0].replace(",", "") credit = self.liststore.get(iter, 4)[0].replace(",", "") desctxt = self.liststore.get(iter, 5)[0] if int(unicode(debt)) != 0: self.builder.get_object("debtor").set_active(True) self.amount.set_text(debt) else: self.builder.get_object("creditor").set_active(True) self.amount.set_text(credit) self.code.set_text(code) desc = self.builder.get_object("desc") desc.set_text(desctxt) result = dialog.run() if result == 1: type = not (self.builder.get_object("debtor").get_active() == True) if int(unicode(debt)) != 0: self.debt_sum -= int(unicode(debt)) else: self.credit_sum -= int(unicode(credit)) code = self.code.get_text() amount = self.amount.get_text() if code != '' and amount != '': self.saveRow(utility.convertToLatin(code), int(unicode(amount)), int(type), desc.get_text(), iter) dialog.hide()
def editUser(self, sender): self.editUserFlag = True self.window = self.builder.get_object("editUserWindow") self.builder.connect_signals(self) self.window.show_all() self.window.set_title(_("Edit User")) selection = self.userTreeview.get_selection() iter = selection.get_selected()[1] id = convertToLatin(self.userTreestore.get(iter, 0)[0]) self.idEdit = id name = self.userTreestore.get(iter, 1)[0] username = self.userTreestore.get(iter, 2)[0] permission = self.userTreestore.get(iter, 3)[0] entry = self.builder.get_object("nameEdit") entry.set_text(name) entry = self.builder.get_object("usernameEdit") entry.set_text(username) entry = self.builder.get_object("permissionEdit") entry.set_text(permission)
def addRow(self, sender): selection = self.treeview.get_selection() iter = selection.get_selected()[1] if iter != None: code = self.liststore.get(iter, 1)[0] dialog = self.builder.get_object("dialog1") dialog.set_title(_("Add new row")) self.code.set_text("") desc = self.builder.get_object("desc") desc.set_text("") self.amount.set_text(utility.readNumber(0)) result = dialog.run() if result == 1: type = not (self.builder.get_object("debtor").get_active() == True) code = self.code.get_text() amount = self.amount.get_float() if code != '' and amount != '': self.saveRow(utility.convertToLatin(code), amount, type, desc.get_text()) dialog.hide()
def saveDocument(self, sender): sender.grab_focus() if self.numrows == 0: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Document should not be empty")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() return iter = self.liststore.get_iter_first() debt_sum = 0 credit_sum = 0 while iter != None : value = unicode(self.liststore.get(iter, 3)[0].replace(",", "")) debt_sum += int(value) value = unicode(self.liststore.get(iter, 4)[0].replace(",", "")) credit_sum += int(value) iter = self.liststore.iter_next(iter) if debt_sum != credit_sum: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Debt sum and Credit sum should be equal")) msgbox.set_title(_("Can not save document")) msgbox.run() msgbox.destroy() return else: #number = 0 today = date.today() if self.docid > 0 : query = config.db.session.query(Bill).select_from(Bill) bill = query.filter(Bill.id == self.docid).first() bill.lastedit_date = today bill.date = self.date.getDateObject() #number = bill.number query = config.db.session.query(Notebook).filter(Notebook.bill_id == bill.id).delete() else : if self.docnumber == 0: number = 0 query = config.db.session.query(Bill.number).select_from(Bill) lastnumbert = query.order_by(Bill.number.desc()).first() if lastnumbert != None: number = lastnumbert[0] self.docnumber = number + 1 #TODO if number is not equal to the maximum BigInteger value, prevent bill registration. bill = Bill (self.docnumber, today, today, self.date.getDateObject(), False) config.db.session.add(bill) config.db.session.commit() self.docid = bill.id iter = self.liststore.get_iter_first() while iter != None : code = utility.convertToLatin(self.liststore.get(iter, 1)[0]) debt = unicode(self.liststore.get(iter, 3)[0].replace(",", "")) value = -(int(debt)) if value == 0 : credit = unicode(self.liststore.get(iter, 4)[0].replace(",", "")) value = int(credit) desctxt = unicode(self.liststore.get(iter, 5)[0]) query = config.db.session.query(Subject).select_from(Subject) query = query.filter(Subject.code == code) sub = query.first().id row = Notebook (sub, self.docid, value, desctxt) config.db.session.add(row) iter = self.liststore.iter_next(iter) config.db.session.commit() docnum = str(self.docnumber) if config.digittype == 1: docnum = utility.convertToPersian(docnum) self.builder.get_object("docnumber").set_text (docnum) msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, _("Document saved with number %s.") % docnum) msgbox.set_title(_("Successfully saved")) msgbox.run() msgbox.destroy()
def saveProductGroup(self, code, name, buy_code, sell_code, edititer=None): msg = "" if code == "": msg += _("Group code should not be empty.\n") if name == "": msg = _("Group name should not be empty.\n") #TODO set default values for buyid & sellid if empty if msg != "": msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, msg) msgbox.set_title(_("Empty fields")) msgbox.run() msgbox.destroy() return False if edititer != None: pcode = unicode(self.treestore.get_value(edititer, 0)) #pcode = utility.convertToLatin(pcode) query = config.db.session.query(ProductGroups).select_from(ProductGroups) group = query.filter(ProductGroups.code == pcode).first() gid = group.id #code = utility.convertToLatin(code) buy_code = utility.convertToLatin(buy_code) sell_code = utility.convertToLatin(sell_code) #Checks if the group name or code is repeated. query = config.db.session.query(ProductGroups).select_from(ProductGroups) query = query.filter(or_(ProductGroups.code == code, ProductGroups.name == name)) if edititer != None: query = query.filter(ProductGroups.id != gid) result = query.all() msg = "" for grp in result: if grp.code == code: msg += _("A group with this code already exists.\n") break elif grp.name == name: msg += _("A group with this name already exists.\n") break #Check if buy_code & sell_code are valid #TODO Check if buying subject is creditor/debtor, and so for selling one. query = config.db.session.query(Subject).select_from(Subject) buy_sub = query.filter(Subject.code == buy_code).first() if buy_sub == None: msg += _("Buying code is not valid.\n") query = config.db.session.query(Subject).select_from(Subject) sell_sub = query.filter(Subject.code == sell_code).first() if sell_sub == None: msg += _("Selling code is not valid.\n") if msg != "": msgbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, msg) msgbox.set_title(_("Invalid group properties")) msgbox.run() msgbox.destroy() return False if edititer == None: group = ProductGroups(code, name, buy_sub.id, sell_sub.id) edititer = self.treestore.append(None) path = self.treestore.get_path(edititer) self.treeview.scroll_to_cell(path, None, False, 0, 0) self.treeview.set_cursor(path, None, False) else: group.code = code group.name = name group.buyId = buy_sub.id group.sellId = sell_sub.id config.db.session.add(group) config.db.session.commit() if config.digittype == 1: #code = utility.convertToPersian(code) buy_code = utility.convertToPersian(buy_code) sell_code = utility.convertToPersian(sell_code) self.saveRow(edititer, (code, name, buy_code, sell_code)) return True
def createReport(self): report_header = [] report_data = [] col_width = [] remaining = 1 query1 = config.db.session.query(Notebook, Subject.code, Bill) query1 = query1.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) query2 = config.db.session.query(sum(Notebook.value)) query2 = query2.select_from(outerjoin(outerjoin(Notebook, Subject, Notebook.subject_id == Subject.id), Bill, Notebook.bill_id == Bill.id)) # Check if the subject code is valid in ledger and subledger reports if self.type != self.__class__.DAILY: code = utility.convertToLatin(self.code.get_text()) query3 = config.db.session.query(Subject.name) query3 = query3.select_from(Subject).filter(Subject.code == code) names = query3.first() if names == None: errorstr = _("No subject is registered with the code: %s") % self.code.get_text() msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, errorstr) msgbox.set_title(_("No subjects found")) msgbox.run() msgbox.destroy() return else: self.subname = names[0] self.subcode = code query1 = query1.filter(Subject.code.startswith(code)) query2 = query2.filter(Subject.code.startswith(code)) searchkey = unicode(self.builder.get_object("searchentry").get_text()) if searchkey != "": try: value = int(utility.convertToLatin(searchkey)) except (UnicodeEncodeError, ValueError): #search key is not a number query1 = query1.filter(Notebook.desc.like("%"+searchkey+"%")) else: query1 = query1.filter(or_(Notebook.desc.like("%"+searchkey+"%"), Notebook.value == value, Notebook.value == -value)) # Check the report parameters if self.builder.get_object("allcontent").get_active() == True: query1 = query1.order_by(Bill.date.asc(), Bill.number.asc()) remaining = 0 else: if self.builder.get_object("atdate").get_active() == True: date = self.date.getDateObject() query1 = query1.filter(Bill.date == date).order_by(Bill.number.asc()) query2 = query2.filter(Bill.date < date) else: if self.builder.get_object("betweendates").get_active() == True: fdate = self.fdate.getDateObject() tdate = self.tdate.getDateObject() if tdate < fdate: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second date value shouldn't precede the first one.")) msgbox.set_title(_("Invalid date order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.date.between(fdate, tdate)).order_by(Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.date < fdate) else: if unicode(self.fnum.get_text()) == '' or unicode(self.tnum.get_text()) == '': msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("One of document numbers are empty.")) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return fnumber = int(unicode(self.fnum.get_text())) tnumber = int(unicode(self.tnum.get_text())) if tnumber < fnumber: msgbox = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("Second document number shouldn't be greater than the first one.")) msgbox.set_title(_("Invalid document order")) msgbox.run() msgbox.destroy() return query1 = query1.filter(Bill.number.between(fnumber, tnumber)).order_by(Bill.date.asc(), Bill.number.asc()) query2 = query2.filter(Bill.number < fnumber) #Prepare report data for PrintReport class res = query1.all() if self.type == self.__class__.DAILY: report_header = [_("Doc. Number"), _("Date"), _("Subject Code"), _("Description"), _("Debt"), _("Credit")] #define the percentage of table width that each column needs col_width = [10, 10, 11, 43, 13, 13 ] for n, code, b in res: desc = n.desc if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") desc = " " + desc billnumber = str(b.number) if config.digittype == 1: code = utility.convertToPersian(code) billnumber = utility.convertToPersian(billnumber) report_data.append((billnumber, dateToString(b.date), code, desc, debt, credit)) else: diagnose = "" if remaining != 0: remaining = query2.first()[0] #if self.type == self.__class__.LEDGER: report_header = [_("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining")] #define the percentage of table width that each column needs col_width = [10, 10, 37, 13, 13, 4, 13] for n, code, b in res: if n.value < 0: credit = utility.showNumber("0") debt = utility.showNumber(-(n.value)) else: credit = utility.showNumber(n.value) debt = utility.showNumber("0") remaining += n.value billnumber = str(b.number) if config.digittype == 1: billnumber = utility.convertToPersian(billnumber) if remaining < 0: diagnose = _("deb") report_data.append((billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) else: if remaining == 0: diagnose = _("equ") else: diagnose = _("cre") report_data.append((billnumber, dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) # else: # if self.type == self.__class__.SUBLEDGER: # report_header = [_("Doc. Number"), _("Date"), _("Description"), _("Debt"), _("Credit"), _("Diagnosis"), _("Remaining")] # col_width = [55, 64, 174, 70, 70, 20, 70] # for n, code, b in res: # if n.value < 0: # credit = "0" # debt = utility.showNumber(-(n.value)) # else: # credit = utility.showNumber(n.value) # debt = "0" # # remaining += n.value # if remaining < 0: # diagnose = _("deb") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(-(remaining)))) # else: # if remaining == 0: # diagnose = _("equ") # else: # diagnose = _("cre") # report_data.append((str(b.number), dateToString(b.date), n.desc, debt, credit, diagnose, utility.showNumber(remaining))) return {"data":report_data, "col-width":col_width ,"heading":report_header}
def correctDate(self, sender, event): text = self.get_text() datelist = string.split(text, share.config.datedelims[share.config.datedelim]) try: tyear = datelist[share.config.datefields["year"]] tyear = convertToLatin(tyear) except IndexError: tyear = "" try: tmonth = datelist[share.config.datefields["month"]] tmonth = convertToLatin(tmonth) except IndexError: tmonth = "" try: tday = datelist[share.config.datefields["day"]] tday = convertToLatin(tday) except IndexError: tday = "" if share.config.datetypes[share.config.datetype] == "jalali": minyear = 1349 baseyear = "1300" else: minyear = 1970 baseyear = "2000" try: if len(tyear) > 4: year = self.year else: year = int(baseyear[:4-len(tyear)] + tyear) if year < minyear: year = minyear except ValueError: year = minyear try: month = int(tmonth) if month > 12: month = 12 else: if month < 1: month = 1 except ValueError: month = 1 try: day = int(tday) if day > 31: day = 31 else: if day < 1: day = 1 except ValueError: day = 1 if share.config.datetypes[share.config.datetype] == "jalali": jd = self.cal.jalali_to_jd(year, month, day) (gyear, gmonth, gday) = self.cal.jd_to_gregorian(jd) else: (gyear, gmonth, gday) = (year, month, day) correct = 0 while correct == 0: try: testdate = date(gyear, gmonth, gday) correct = 1 except ValueError: gday -= 1 day -= 1 self.showDate(year, month, day) self.year = year self.month = month self.day = day
def editPay(self, sender=0): iter = self.paysTreeView.get_selection().get_selected()[1] if iter == None: iter = self.cheqTreeView.get_selection().get_selected()[1] if iter == None: return else: number = utility.convertToLatin(self.cheqListStore.get(iter, 0)[0]) query = self.session.query(Cheque).select_from(Cheque) query = query.filter(and_(Cheque.chqTransId == self.transId, Cheque.chqBillId == self.billId, Cheque.chqOrder == number)) cheque = query.first() self.editid = cheque.chqId payer_id = cheque.chqCust amount = utility.LN(cheque.chqAmount, False) serial = cheque.chqSerial wrtDate = cheque.chqWrtDate dueDate = cheque.chqDueDate desc = cheque.chqDesc self.isCheque.set_active(True) self.isCheque.set_sensitive(True) self.isRecpt.set_sensitive(False) self.cheqStatusList.set_active(cheque.chqStatus) self.trackingCodeEntry.set_text("") else: number = utility.convertToLatin(self.paysListStore.get(iter, 0)[0]) query = self.session.query(Payment).select_from(Payment) query = query.filter(and_(Payment.paymntTransId == self.transId, Payment.paymntBillId == self.billId, Payment.paymntOrder == number)) payment = query.first() self.editid = payment.paymntId payer_id = payment.paymntNamePayer amount = utility.LN(payment.paymntAmount, False) serial = payment.paymntSerial wrtDate = payment.paymntWrtDate dueDate = payment.paymntDueDate desc = payment.paymntDesc self.isRecpt.set_active(True) self.isRecpt.set_sensitive(True) self.isCheque.set_sensitive(False) self.trackingCodeEntry.set_text(payment.paymntTrckCode) #self.bankEntry.set_text(payment.paymntBank) #self.bankCombo.set_text(payment.paymntBank) self.edtPymntFlg = True self.edititer = iter self.addPymntDlg = self.builder.get_object("addPaymentDlg") self.addPymntDlg.set_title(_("Edit Non-Cash Payment")) self.builder.get_object("submitBtn").set_label(_("Save Changes...")) self.builder.get_object("paymentsStatusBar").push(1,"") query = self.session.query(Customers).select_from(Customers) self.payer = query.filter(Customers.custId == payer_id).first() #self.payerEntry.set_text(self.payer.custCode) #self.builder.get_object("chqPayerLbl").set_text(self.payer.custName) self.pymntAmntEntry.set_text(amount) self.serialNoEntry.set_text(serial) self.writeDateEntry.showDateObject(wrtDate) self.dueDateEntry.showDateObject(dueDate) self.pymntDescEntry.set_text(desc) self.addPymntDlg.show_all()
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 = utility.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 lastcode = utility.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 if config.digittype == 1: basecode = utility.convertToPersian(lastcode) else: basecode = lastcode 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.__class__.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() if config.digittype == 1: lastcode = utility.convertToPersian(lastcode) child = self.treestore.append(iter, (lastcode, name, _(self.__class__.subjecttypes[type]), utility.showNumber("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)