def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            )
        )

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append(
                {
                    'tva_id': tva.id,
                    'amount': floor_to_precision(
                        value,
                        precision=2,
                        dialect_precision=5
                    )
                }
            )

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
def test_more_vars_called(get_csrf_request_with_db):
    req = get_csrf_request_with_db()
    form = BaseFormView(req)
    form.schema = DummySchema()
    form.add_template_vars = ('arg',)
    form.arg = u"Test arg"
    result = form.__call__()
    assert(result['arg'] == u"Test arg")
Exemple #3
0
    def submit_failure(self, e):
        errors = e.error.asdict()
        if 'month' in errors and 'year' in errors:
            appstruct = self.request.POST
            sheet = self._find_existing(appstruct)
            if sheet is not None:
                return self.redirect(sheet)

        BaseFormView.submit_failure(self, e)
Exemple #4
0
    def __init__(self, context, request):
        BaseFormView.__init__(self, request)
        self.model_type = self.request.GET['model_type']
        self.quotechar = self.request.GET['quotechar']
        self.delimiter = self.request.GET['delimiter']

        if self.model_type not in self.model_types:
            raise HTTPForbidden()

        # We first count the number of elements in the file
        self.filepath = get_current_csv_filepath(self.request)

        # We build a field - model attr associator
        self.associator = get_csv_import_associator(self.model_type)
        _csv_obj = get_current_csv(self.filepath, self.delimiter, self.quotechar)
        self.headers = [header for header in _csv_obj.fieldnames if header]
Exemple #5
0
    def submit_failure(self, e):
        errors = e.error.asdict()
        if 'month' in errors and 'year' in errors:
            appstruct = self.request.POST
            sheet = self._find_existing(appstruct)
            if sheet is not None:
                sheet = self.context
                self.request.session.flash(
                    u"Impossible de dupliquer cette note de dépenses."
                    u"Une note de dépense existe déjà pour la période "
                    u"de {0} {1}.".format(
                        strings.month_name(appstruct['month']),
                        appstruct['year'],
                    ), 'error')
                return self.redirect(self.context)

        BaseFormView.submit_failure(self, e)
    def submit_failure(self, e):
        errors = e.error.asdict()
        if 'month' in errors and 'year' in errors:
            appstruct = self.request.POST
            sheet = self._find_existing(appstruct)
            if sheet is not None:
                sheet = self.context
                self.request.session.flash(
                    u"Impossible de dupliquer cette note de dépenses."
                    u"Une note de dépense existe déjà pour la période "
                    u"de {0} {1}.".format(
                        strings.month_name(appstruct['month']),
                        appstruct['year'],
                    ),
                    'error'
                )
                return self.redirect(self.context)

        BaseFormView.submit_failure(self, e)
Exemple #7
0
 def _more_template_vars(self):
     """
     Add template vars to the response dict
     List the attributes configured in the add_template_vars attribute
     and add them
     """
     result = BaseFormView._more_template_vars(self)
     result['title'] = self.title
     result['company'] = self.company
     result['tvas'] = self.tvas
     result['load_options_url'] = self.load_options_url
     result['load_catalog_url'] = self.load_catalog_url
     return result
Exemple #8
0
 def _more_template_vars(self):
     """
     Add template vars to the response dict
     List the attributes configured in the add_template_vars attribute
     and add them
     """
     result = BaseFormView._more_template_vars(self)
     result['title'] = self.title
     result['company'] = self.company
     result['tvas'] = self.tvas
     result['load_options_url'] = self.load_options_url
     result['load_catalog_url'] = self.load_catalog_url
     return result
Exemple #9
0
def test_more_vars_called(get_csrf_request_with_db):
    req = get_csrf_request_with_db()
    form = BaseFormView(req)
    form.schema = DummySchema()
    form.add_template_vars = ('arg', )
    form.arg = u"Test arg"
    result = form.__call__()
    assert (result['arg'] == u"Test arg")
Exemple #10
0
    def before(self, form):
        BaseFormView.before(self, form)
        self.request.actionmenu.add(
            ViewLink(
                label=u"Revenir à la facture",
                path="/invoices/{id}.html",
                id=self.context.id,
                _anchor="payment",
            ))

        appstruct = []
        for tva_value, value in self.context.topay_by_tvas().items():
            tva = Tva.by_value(tva_value)
            appstruct.append({
                'tva_id':
                tva.id,
                'amount':
                floor_to_precision(value, precision=2, dialect_precision=5)
            })

        if len(appstruct) == 1:
            form.set_appstruct(appstruct[0])
        else:
            form.set_appstruct({'tvas': appstruct})
 def __init__(self, *args, **kwargs):
     BaseFormView.__init__(self, *args, **kwargs)
     ensure_doctypes_rel(self.current_userdatas.id, self.request)
Exemple #12
0
 def __init__(self, *args, **kwargs):
     BaseFormView.__init__(self, *args, **kwargs)
     self.form_config = UserFormConfigState(self.session)
Exemple #13
0
def test_init(get_csrf_request_with_db):
    req = get_csrf_request_with_db()
    form = BaseFormView(req)
    assert (form.dbsession == req.dbsession)
    assert (form.session == req.session)
Exemple #14
0
 def __init__(self, *args, **kwargs):
     BaseFormView.__init__(self, *args, **kwargs)
     self.form_config = UserFormConfigState(self.session)
Exemple #15
0
 def before(self, form):
     BaseFormView.before(self, form)
     populate_actionmenu(self.request)
     task_add_js.need()
Exemple #16
0
 def before(self, form):
     BaseFormView.before(self, form)
     task_add_js.need()
Exemple #17
0
 def before(self, form):
     BaseFormView.before(self, form)
     populate_actionmenu(self.request)
     task_add_js.need()
Exemple #18
0
 def __init__(self, *args, **kwargs):
     BaseFormView.__init__(self, *args, **kwargs)
     ensure_doctypes_rel(self.current_userdatas.id, self.request)
Exemple #19
0
 def before(self, form):
     BaseFormView.before(self, form)
     task_add_js.need()