Changeset 3413 for pykota/trunk/bin/pkbcodes
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pkbcodes
r3411 r3413 9 9 # the Free Software Foundation, either version 3 of the License, or 10 10 # (at your option) any later version. 11 # 11 # 12 12 # This program is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 35 35 from pykota.storage import StorageBillingCode 36 36 37 class PKBcodes(PyKotaTool) : 37 class PKBcodes(PyKotaTool) : 38 38 """A class for a billing codes manager.""" 39 39 def modifyBillingCode(self, billingcode, reset, description) : 40 40 """Modifies a billing code.""" 41 41 if reset : 42 billingcode.reset() 42 billingcode.reset() 43 43 if description is not None : # NB : "" is allowed ! 44 44 billingcode.setDescription(description) 45 45 46 46 def main(self, names, options) : 47 47 """Manage billing codes.""" 48 48 if options.action != "list" : 49 49 self.adminOnly() 50 50 51 51 islist = (options.action == "list") 52 52 isadd = (options.action == "add") 53 53 isdelete = (options.action == "delete") 54 54 55 55 if not names : 56 56 if isdelete or isadd : 57 57 raise PyKotaCommandLineError, _("You must specify billing codes on the command line.") 58 names = [u"*"] 59 58 names = [u"*"] 59 60 60 if not islist : 61 61 percent = Percent(self) 62 62 63 63 if not isadd : 64 64 if not islist : … … 73 73 if not islist : 74 74 percent.setSize(len(billingcodes)) 75 75 76 76 if islist : 77 77 for billingcode in billingcodes : … … 83 83 billingcode.Balance, \ 84 84 _("credits"))) 85 elif isdelete : 85 elif isdelete : 86 86 percent.display("\n%s..." % _("Deletion")) 87 87 self.storage.deleteManyBillingCodes(billingcodes) … … 91 91 if description : 92 92 description = description.strip() 93 93 94 94 self.storage.beginTransaction() 95 95 try : 96 if isadd : 96 if isadd : 97 97 percent.display("%s...\n" % _("Creation")) 98 98 percent.setSize(len(names)) 99 99 for bname in names : 100 100 billingcode = StorageBillingCode(self.storage, bname) 101 self.modifyBillingCode(billingcode, 102 options.reset, 101 self.modifyBillingCode(billingcode, 102 options.reset, 103 103 description) 104 104 oldbillingcode = self.storage.addBillingCode(billingcode) … … 106 106 if options.skipexisting : 107 107 self.logdebug(_("Billing code '%(bname)s' already exists, skipping.") % locals()) 108 else : 108 else : 109 109 self.logdebug(_("Billing code '%(bname)s' already exists, will be modified.") % locals()) 110 self.modifyBillingCode(oldbillingcode, 111 options.reset, 110 self.modifyBillingCode(oldbillingcode, 111 options.reset, 112 112 description) 113 113 oldbillingcode.save() 114 114 percent.oneMore() 115 else : 115 else : 116 116 percent.display("\n%s...\n" % _("Modification")) 117 117 for billingcode in billingcodes : 118 self.modifyBillingCode(billingcode, 119 options.reset, 118 self.modifyBillingCode(billingcode, 119 options.reset, 120 120 description) 121 billingcode.save() 121 billingcode.save() 122 122 percent.oneMore() 123 except : 123 except : 124 124 self.storage.rollbackTransaction() 125 125 raise 126 else : 126 else : 127 127 self.storage.commitTransaction() 128 128 129 129 if not islist : 130 130 percent.done() 131 132 if __name__ == "__main__" : 131 132 if __name__ == "__main__" : 133 133 parser = PyKotaOptionParser(description=_("A billing codes manager for PyKota."), 134 134 usage="pkbcodes [options] code1 code2 ... codeN") … … 159 159 dest="skipexisting", 160 160 help=_("If --add is used, ensure that existing billing codes won't be modified.")) 161 161 162 162 parser.add_example('-D "Financial Department" financial', 163 163 _("Would create a billing code labelled 'financial' with the specified textual description.")) 164 parser.add_example('--delete "fin*"', 164 parser.add_example('--delete "fin*"', 165 165 _("Would delete all billing codes which label begins with 'fin'. Matching jobs in the printing history wouldn't be deleted though.")) 166 166 parser.add_example("--list", 167 167 _("Would display details about all existing billing codes.")) 168 168 169 169 (options, arguments) = parser.parse_args() 170 run(parser, PKBcodes) 170 run(parser, PKBcodes)