[attributs] typage des articles comme des dict
This commit is contained in:
parent
7b8cfaea67
commit
27af8f31c0
1 changed files with 14 additions and 3 deletions
17
attributs.py
17
attributs.py
|
@ -1459,10 +1459,21 @@ class article(Attr):
|
|||
category = 'facture'
|
||||
can_modify = [cableur, nounou, tresorier]
|
||||
ldap_name = "article"
|
||||
python_type = dict
|
||||
|
||||
python_type_keys = ['code', 'designation', 'nombre', 'pu']
|
||||
|
||||
def parse_value(self, article):
|
||||
art_code, art_designation, art_nombre, art_pu = article.split('~~')
|
||||
now = time.time()
|
||||
if isinstance(article, self.python_type):
|
||||
for key in self.python_type_keys:
|
||||
if key not in article:
|
||||
raise ValueError("Un article devrait avoir '%s'" % key)
|
||||
art_code = article['code']
|
||||
art_designation = article['designation']
|
||||
art_nombre = article['nombre']
|
||||
art_pu = article['pu']
|
||||
else:
|
||||
art_code, art_designation, art_nombre, art_pu = article.split('~~')
|
||||
self.value = { 'code' : art_code, # code de l'article (SOLDE, FRAIS, ...)
|
||||
'designation' : art_designation,
|
||||
'nombre' : art_nombre,# nombre d'article
|
||||
|
@ -1476,7 +1487,7 @@ class article(Attr):
|
|||
return self.value.__getitem__(attr)
|
||||
|
||||
def __setitem__(self, attr, values):
|
||||
if attr in ['code', 'designation', 'nombre', 'pu']:
|
||||
if attr in self.python_type_keys:
|
||||
ret = self.value.__setitem__(attr, values)
|
||||
self.parse_value(unicode(self))
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue