class ExpenseList(BaseListView): """ expenses list payment_form The payment form is added as a popup and handled through javascript to set the expense id """ title = u"Liste des notes de dépense de la CAE" schema = get_list_schema() sort_columns = dict( id_=ExpenseSheet.id, month=ExpenseSheet.month, name=User.lastname, ) default_sort = 'month' default_direction = 'desc' add_template_vars = ('title', 'payment_formname', 'legends') legends = ( ('status-wait justified-False', u"Notes de dépense en attente de validation"), ('', u"Notes de dépense validées"), ("status justified-True", u"Justificatifs reçus"), ("paid-status-paid", u"Notes de dépense partiellement payées"), ("paid-status-resulted", u"Notes de dépense payées"), ) @property def payment_formname(self): """ Return a payment form name, add the form to the page popups as well """ admin_expense_js.need() form_name = "payment_form" form = get_payment_form(self.request) form.set_appstruct({'come_from': self.request.current_route_path()}) popup = PopUp(form_name, u"Saisir un paiement", form.render()) self.request.popups[popup.name] = popup return form_name def query(self): query = DBSESSION().query(distinct(ExpenseSheet.id), ExpenseSheet) query = query.outerjoin(ExpenseSheet.user) return query def filter_search(self, query, appstruct): search = appstruct['search'] if search and search != colander.null: query = query.filter(ExpenseSheet.id == search) return query def filter_year(self, query, appstruct): year = appstruct['year'] if year and year not in (-1, colander.null): query = query.filter(ExpenseSheet.year == year) return query def filter_month(self, query, appstruct): month = appstruct['month'] if month and month not in (-1, colander.null, '-1'): query = query.filter(ExpenseSheet.month == month) return query def filter_owner(self, query, appstruct): user_id = appstruct.get('owner_id', None) if user_id and user_id not in ('', -1, colander.null): query = query.filter(ExpenseSheet.user_id == user_id) return query def filter_status(self, query, appstruct): status = appstruct['status'] if status in ('wait', 'valid'): query = query.filter(ExpenseSheet.status == status) elif status in ('paid', 'resulted'): query = query.filter(ExpenseSheet.status == 'valid') query = query.filter(ExpenseSheet.paid_status == status) elif status == 'justified': query = query.filter(ExpenseSheet.justified == True) else: query = query.filter(ExpenseSheet.status.in_(('valid', 'wait'))) return query
class ExpenseList(BaseListView): """ expenses list payment_form The payment form is added as a popup and handled through javascript to set the expense id """ title = u"Liste des notes de dépense de la CAE" schema = get_list_schema() sort_columns = dict( id_=ExpenseSheet.id, month=ExpenseSheet.month, name=User.lastname, ) default_sort = 'month' default_direction = 'desc' add_template_vars = ( 'title', 'payment_formname', ) @property def payment_formname(self): """ Return a payment form name, add the form to the page popups as well """ admin_expense_js.need() form_name = "payment_form" form = get_payment_form(self.request) form.set_appstruct({'come_from': self.request.current_route_path()}) popup = PopUp(form_name, u"Saisir un paiement", form.render()) self.request.popups[popup.name] = popup return form_name def query(self): return ExpenseSheet.query().outerjoin(ExpenseSheet.user) def filter_search(self, query, appstruct): search = appstruct['search'] if search: query = query.filter(ExpenseSheet.id == search) return query def filter_year(self, query, appstruct): year = appstruct['year'] if year and year != -1: query = query.filter(ExpenseSheet.year == year) return query def filter_month(self, query, appstruct): month = appstruct['month'] if month and month != -1: query = query.filter(ExpenseSheet.month == month) return query def filter_owner(self, query, appstruct): user_id = appstruct['owner_id'] if user_id and user_id != -1: query = query.filter(ExpenseSheet.user_id == user_id) return query def filter_status(self, query, appstruct): status = appstruct['status'] if status != 'all': query = query.filter(ExpenseSheet.status == status) else: interesting_status = [i[0] for i in STATUS_OPTIONS] query = query.filter(ExpenseSheet.status.in_(interesting_status)) return query