96 | | entry = todelete[i] |
97 | | if entry.Exists : |
98 | | entry.delete() |
| 121 | bname = names[i] |
| 122 | billingcode = StorageBillingCode(self.storage, bname) |
| 123 | self.modifyBillingCode(billingcode, reset, description) |
| 124 | oldbillingcode = self.storage.addBillingCode(billingcode) |
| 125 | if oldbillingcode is not None : |
| 126 | if options["skipexisting"] : |
| 127 | self.printInfo(_("Billing code [%s] already exists, skipping.") % bname) |
| 128 | else : |
| 129 | self.printInfo(_("Billing code [%s] already exists, will be modified.") % bname) |
| 130 | self.modifyBillingCode(oldbillingcode, reset, description) |
| 131 | oldbillingcode.save() |
101 | | else : |
102 | | if options["add"] : |
103 | | self.display("%s...\n" % _("Creation")) |
104 | | billingcodes = [] |
105 | | nbtotal = len(names) |
106 | | for i in range(nbtotal) : |
107 | | bname = names[i] |
108 | | billingcode = self.storage.getBillingCode(bname) |
109 | | if billingcode.Exists : |
110 | | if options["skipexisting"] : |
111 | | self.printInfo(_("Billing code [%s] already exists, skipping.") % billingcode.BillingCode) |
112 | | else : |
113 | | self.printInfo(_("Billing code [%s] already exists, will be modified.") % billingcode.BillingCode) |
114 | | billingcodes.append(billingcode) |
115 | | else : |
116 | | billingcode = self.storage.addBillingCode(bname) |
117 | | if not billingcode.Exists : |
118 | | raise PyKotaToolError, _("Impossible to add billingcode %s") % bname |
119 | | else : |
120 | | billingcodes.append(billingcode) |
121 | | percent = 100.0 * float(i) / float(nbtotal) |
122 | | self.display("\r%.02f%%" % percent) |
123 | | self.display("\r100.00%%\r \r%s\n" % _("Done.")) |
124 | | else : |
125 | | if not names : |
126 | | names = ["*"] |
127 | | billingcodes = self.storage.getMatchingBillingCodes(",".join(names)) |
128 | | if not billingcodes : |
129 | | raise PyKotaCommandLineError, _("There's no billingcode matching %s") % " ".join(names) |
130 | | |
| 134 | else : |
142 | | self.display("%s...\n" % _("Modification")) |
143 | | reset = options["reset"] |
144 | | if reset or options["description"] : # optimize when nothing to do |
145 | | if options["description"] : |
146 | | description = options["description"].strip() |
147 | | nbtotal = len(billingcodes) |
148 | | for i in range(nbtotal) : |
149 | | billingcode = billingcodes[i] |
150 | | if reset : |
151 | | billingcode.reset() |
152 | | if description is not None : # NB : "" is allowed ! |
153 | | billingcode.setDescription(description) |
154 | | billingcode.save() |
155 | | percent = 100.0 * float(i) / float(nbtotal) |
156 | | self.display("\r%.02f%%" % percent) |
157 | | |
| 146 | self.display("\n%s...\n" % _("Modification")) |
| 147 | nbtotal = len(billingcodes) |
| 148 | for i in range(nbtotal) : |
| 149 | billingcode = billingcodes[i] |
| 150 | self.modifyBillingCode(billingcode, reset, description) |
| 151 | billingcode.save() |
| 152 | percent = 100.0 * float(i) / float(nbtotal) |
| 153 | self.display("\r%.02f%%" % percent) |
| 154 | |