310 | | if description is not None : # NB : "" is allowed ! |
311 | | entry.setDescription(description) |
312 | | if limitby : |
313 | | entry.setLimitBy(limitby) |
| 310 | |
| 311 | # We need a transaction because we may have to create a record |
| 312 | # in the payments' table at the same time we modify the user's balance. |
| 313 | self.storage.beginTransaction() |
| 314 | try : |
| 315 | if description is not None : # NB : "" is allowed ! |
| 316 | entry.setDescription(description) |
| 317 | if limitby : |
| 318 | entry.setLimitBy(limitby) |
| 319 | |
| 320 | if suffix == "User" : |
| 321 | if overcharge is not None : # NB : 0 is allowed ! |
| 322 | entry.setOverChargeFactor(overcharge) |
315 | | if suffix == "User" : |
316 | | if overcharge is not None : # NB : 0 is allowed ! |
317 | | entry.setOverChargeFactor(overcharge) |
318 | | |
319 | | entry.save() |
320 | | |
321 | | if suffix == "User" : |
322 | | if balance : |
323 | | if balance.startswith("+") or balance.startswith("-") : |
324 | | newbalance = float(entry.AccountBalance or 0.0) + balancevalue |
325 | | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue |
326 | | entry.setAccountBalance(newbalance, newlifetimepaid, comment) |
327 | | else : |
328 | | diff = balancevalue - float(entry.AccountBalance or 0.0) |
329 | | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff |
330 | | entry.setAccountBalance(balancevalue, newlifetimepaid, comment) |
331 | | |
332 | | for ugroup in usersgroups : |
333 | | if options["remove"] : |
334 | | ugroup.delUserFromGroup(entry) |
335 | | else : |
336 | | ugroup.addUserToGroup(entry) |
337 | | |
| 324 | if suffix == "User" : |
| 325 | if balance : |
| 326 | if balance.startswith("+") or balance.startswith("-") : |
| 327 | newbalance = float(entry.AccountBalance or 0.0) + balancevalue |
| 328 | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + balancevalue |
| 329 | entry.setAccountBalance(newbalance, newlifetimepaid, comment) |
| 330 | else : |
| 331 | diff = balancevalue - float(entry.AccountBalance or 0.0) |
| 332 | newlifetimepaid = float(entry.LifeTimePaid or 0.0) + diff |
| 333 | entry.setAccountBalance(balancevalue, newlifetimepaid, comment) |
| 334 | |
| 335 | for ugroup in usersgroups : |
| 336 | if options["remove"] : |
| 337 | ugroup.delUserFromGroup(entry) |
| 338 | else : |
| 339 | ugroup.addUserToGroup(entry) |
| 340 | entry.save() |
| 341 | except : |
| 342 | self.storage.rollbackTransaction() |
| 343 | raise |
| 344 | else : |
| 345 | self.storage.commitTransaction() |
| 346 | |