[payments] add method to Invoice for getting at the user and username

This commit is contained in:
Benjamin Dauvergne 2012-10-01 17:11:26 +02:00
parent 40733e9867
commit bc4e32b106
1 changed files with 11 additions and 0 deletions

View File

@ -27,6 +27,7 @@ from qommon.form import htmltext, StringWidget, TextWidget, SingleSelectWidget
from wcs.formdef import FormDef
from wcs.formdata import Evolution
from wcs.workflows import WorkflowStatusItem, register_item_class, template_on_formdata
from wcs.users import User
def is_payment_supported():
if not eopayment:
@ -77,6 +78,16 @@ class Invoice(StorableObject):
if get_publisher() and not self.id:
self.id = self.get_new_id()
def get_user(self):
if self.user_id:
return User.get(self.user_id, ignore_errors=True)
return None
@property
def username(self):
user = self.get_user()
return user.name if user else ''
def get_new_id(self, create=False):
# format : date-regie-formdef-alea-check
r = random.SystemRandom()