payments: replace PaymentWorkflowStatusItem.calculate_amount() using WorkflowStatusItem.compute()

This commit is contained in:
Benjamin Dauvergne 2012-10-05 11:19:34 +02:00
parent 5f8f0eae39
commit 403b921093
1 changed files with 1 additions and 13 deletions

View File

@ -216,18 +216,6 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
hint=_('Used only if the current status of the form does not contain any "Payment Validation" item'),
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status])
def calculate_amount(self, formdata):
if not self.amount:
return 0
if not self.amount.startswith('='):
return self.amount
vars = get_publisher().substitutions.get_context_variables()
vars['Decimal'] = Decimal
amount = eval(self.amount[1:], vars)
amount = Decimal(amount)
# XXX: catch and report the error somehow
return amount
def perform(self, formdata):
invoice = Invoice(regie_id=self.regie_id, formdef_id=formdata.formdef.id)
invoice.user_id = formdata.user_id
@ -241,7 +229,7 @@ class PaymentWorkflowStatusItem(WorkflowStatusItem):
'form_name': formdata.formdef.name,
'formdata_id': formdata.id }
invoice.details = template_on_formdata(formdata, self.compute(self.details))
invoice.amount = self.calculate_amount(formdata)
invoice.amount = Decimal(self.compute(self.amount))
invoice.date = dt.now()
invoice.store()
# add a message in formdata.evolution