Plus de frais dans les factures
This commit is contained in:
parent
9498e06024
commit
666bd33085
1 changed files with 1 additions and 40 deletions
41
objets.py
41
objets.py
|
@ -1507,7 +1507,7 @@ class switchCrans(machine):
|
|||
|
||||
@crans_object
|
||||
class facture(CransLdapObject):
|
||||
__slots__ = ("_proprio", "_has_frais", "_recuPaiement", "_article_frais")
|
||||
__slots__ = ("_proprio", "_recuPaiement")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
|
@ -1521,54 +1521,16 @@ class facture(CransLdapObject):
|
|||
def __repr__(self):
|
||||
return str(self.__class__.__name__) + " : fid=" + str(self['fid'][0])
|
||||
|
||||
#### GROS HACK pour rester comptatible avec ldap_crans où l'article representant les frais n'est ajouté qu'une fois le paiement reçu
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._proprio = None
|
||||
super(facture, self).__init__(*args, **kwargs)
|
||||
self._has_frais = True if [art for art in self.attrs.get('article', []) if art['code'] != 'FRAIS'] else False
|
||||
self._recuPaiement = True if self['recuPaiement'] else False
|
||||
self._article_frais = None
|
||||
|
||||
def __getitem__(self,attr, default=None):
|
||||
ret = super(facture, self).__getitem__(attr, default)
|
||||
if attr == 'article' and self.mode == 'ro' and not self._has_frais:
|
||||
return ret + ([self._article_frais] if self._article_frais else [])
|
||||
else:
|
||||
return ret
|
||||
#### FIN DU GROS HACK
|
||||
|
||||
def __setitem__(self, attr, value):
|
||||
if self._recuPaiement and attr in ['article', 'modePaiement', 'recuPaiement']:
|
||||
raise EnvironmentError("Paiement déjà effectué pour cette facture, impossible de modifier son contenu")
|
||||
return super(facture, self).__setitem__(attr, value)
|
||||
|
||||
def _frais(self, mode=None):
|
||||
if mode is None:
|
||||
mode = self['modePaiement'][0]
|
||||
if self._recuPaiement:
|
||||
return
|
||||
frais = {'code':'FRAIS', 'designation':'Frais de tansaction', 'nombre':1, 'pu':0.0}
|
||||
if mode == 'paypal':
|
||||
# 25 centimes pour le paiement paypal
|
||||
s = 0.25
|
||||
# et on ajoute 3.5% du montant
|
||||
for art in self['article']:
|
||||
s += 0.035 * int(art['nombre']) * float(art['pu'])
|
||||
# arrondissage-tronquage
|
||||
s = float(int(s*100)/100.0)
|
||||
# ajoute à la liste d'articles de frais
|
||||
frais['pu']=round(s, 2)
|
||||
self._article_frais = dict(frais)
|
||||
|
||||
def _add_frais(self):
|
||||
self._frais()
|
||||
if not self._recuPaiement:
|
||||
articles = [art for art in self['article'] if art['code'] != 'FRAIS']
|
||||
if self._article_frais:
|
||||
articles.append(self._article_frais)
|
||||
self['article'] = articles
|
||||
self._has_frais = True
|
||||
|
||||
def total(self):
|
||||
total=0
|
||||
for article in self["article"]:
|
||||
|
@ -1595,7 +1557,6 @@ class facture(CransLdapObject):
|
|||
return proprio_save
|
||||
|
||||
if not self._recuPaiement:
|
||||
self._add_frais()
|
||||
with self.proprio() as proprio:
|
||||
proprio_save = credite_arts(proprio)
|
||||
# On vient de créditer, le paiement a été reçu
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue