Example #1
0
    def test_success_id_preservation(self):
        self.config.add_route('admin_expense', '/')
        appstruct = {'expenses':[
            {'label':u"Restauration", "code":u"0001", "id":None}],
                    'expenseskm':[],
                    'expensestel':[]}
        view = AdminExpense(self.get_csrf_request())
        view.submit_success(appstruct)

        expense = ExpenseType.query().filter(ExpenseType.code=="0001").first()
        appstruct['expenses'][0]['id'] = expense.id
        appstruct['expenses'][0]['code'] = u"00002"
        view = AdminExpense(self.get_csrf_request())
        view.submit_success(appstruct)
        expense = ExpenseType.query().filter(ExpenseType.id==expense.id).first()
        self.assertEqual(expense.code, u"00002")
Example #2
0
    def get_columns(self):
        """
            Retrieve all columns and define a global column attribute
            :param internal: are we asking columns for internal expenses
        """
        columns = []
        # Add the two first columns
        columns.append(StaticColumn(label='Date', key='date'))
        columns.append(
            StaticColumn(label='Description', key='description', nb_col=3))

        # Telephonic fees are only available as internal expenses
        tel_column = self.get_tel_column()
        if tel_column is not None:
            columns.append(tel_column)

        km_column = self.get_km_column()
        if km_column:
            columns.append(km_column)
            kmtype_code = km_column.code
        else:
            kmtype_code = None

        commontypes = ExpenseType.query()\
                .filter(ExpenseType.type=="expense")\
                .filter(ExpenseType.active==True)
        for type_ in commontypes:
            # Here's a hack to allow to group km fee types and displacement fees
            if kmtype_code is not None and \
               type_.code != kmtype_code:
                columns.append(TypedColumn(type_))

        columns.extend(self.get_disabled_types_columns())

        # Add the last columns
        columns.append(
            StaticColumn(label='Tva', key='tva', formatter=integer_to_amount))
        columns.append(
            StaticColumn(
                label="Total",
                key="total",
                formatter=integer_to_amount,
                style=NUMBER_CELL,
            ))

        # We set the appropriate letter to each column
        index = 0
        for col in columns:
            letter = ASCII_UPPERCASE[index]
            additional_cell_nb = col.additional_cell_nb
            if additional_cell_nb:
                last_letter = ASCII_UPPERCASE[index + additional_cell_nb]
                index += additional_cell_nb + 1
            else:
                last_letter = letter
                index += 1
            col.set_letter(letter, last_letter)
        return columns
Example #3
0
def test_success_id_preservation(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin.main import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {'expenses':[
        {'label':u"Restauration", "code":u"0001", "id":None}],
                'expenseskm':[],
                'expensestel':[]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    expense = ExpenseType.query().filter(ExpenseType.code=="0001").first()

    appstruct['expenses'][0]['id'] = expense.id
    appstruct['expenses'][0]['code'] = u"00002"
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)
    expense = ExpenseType.query().filter(ExpenseType.id==expense.id).first()
    assert expense.code == u"00002"
Example #4
0
def test_success_id_preservation(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {'expenses':[
        {'label':u"Restauration", "code":u"0001", "id":None}],
                'expenseskm':[],
                'expensestel':[]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    expense = ExpenseType.query().filter(ExpenseType.code=="0001").first()

    appstruct['expenses'][0]['id'] = expense.id
    appstruct['expenses'][0]['code'] = u"00002"
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)
    expense = ExpenseType.query().filter(ExpenseType.id==expense.id).first()
    assert expense.code == u"00002"
Example #5
0
    def get_columns(self, internal=True):
        """
            Retrieve all columns and define a global column attribute
            :param internal: are we asking columns for internal expenses
        """
        columns = []
        # Add the two first columns
        columns.append({'label':'Date', 'key':'date'})
        columns.append({
            'label':'Description',
            'key':'description',
            'additional_cell_nb':3})
        # Telephonic fees are only available as internal expenses
        if internal:
            columns.extend(self.get_tel_column())
        km_columns = self.get_km_column()
        columns.extend(km_columns)

        if len(km_columns) > 0:
            kmtype_code = km_columns[0]['code']
        else:
            kmtype_code = None

        commontypes = ExpenseType.query()\
                .filter(ExpenseType.type=="expense")\
                .filter(ExpenseType.active==True)
        for type_ in commontypes:
            # Here's a hack to allow to group km fee types and displacement fees
            if kmtype_code is not None and type_.code != kmtype_code:
                columns.append({'label':type_.label, 'code':type_.code})

        columns.extend(self.get_disabled_types_columns())

        # Add the last columns
        columns.append({'label':'Tva', 'key':'tva',
            'formatter':integer_to_amount})
        columns.append({'label':'Total', 'key':'total',
            'formatter':integer_to_amount, 'number_format':'0.00'})

        # We set the appropriate letter to each column
        index = 0
        for col in columns:
            letter = ASCII_UPPERCASE[index]
            additional_cell_nb = col.get('additional_cell_nb')
            if additional_cell_nb:
                last_letter = ASCII_UPPERCASE[index + additional_cell_nb]
                index += additional_cell_nb + 1
            else:
                last_letter = letter
                index += 1
            col['letter'] = letter
            col['last_letter'] = last_letter
        return columns
Example #6
0
    def check_config(self, config):
        """
        Check all configuration values are set for export

        :param config: The application configuration dict
        """
        contribution_is_active = False
        for type_ in ExpenseType.query().filter(ExpenseType.active==True):
            if not type_.code: # or not type_.compte_tva or not type_.code_tva:
                return False
            if type_.contribution:
                contribution_is_active = True

        for key in self.config_keys:
            if not config.get(key):
                return False
            if contribution_is_active:
                for key in self.contribution_config_keys:
                    if not config.get(key):
                        return False
        return True
Example #7
0
    def check_config(self, config):
        """
        Check all configuration values are set for export

        :param config: The application configuration dict
        """
        contribution_is_active = False
        for type_ in ExpenseType.query().filter(ExpenseType.active == True):
            if not type_.code:  # or not type_.compte_tva or not type_.code_tva:
                return False
            if type_.contribution:
                contribution_is_active = True

        for key in self.config_keys:
            if not config.get(key):
                return False
            if contribution_is_active:
                for key in self.contribution_config_keys:
                    if not config.get(key):
                        return False
        return True
Example #8
0
def expense_options(request):
    """
    Return options related to the expense configuration
    """
    # Load types already used in this expense
    current_expenses_used_types = load_type_ids_from_expense(request.context)

    options = {
        "expense_types": [],
        "expensekm_types": [],
        "expensetel_types": [],
    }
    for etype in ExpenseType.query():
        if etype.id in current_expenses_used_types or etype.active:
            key = "%s_types" % etype.type
            options[key].append(etype)

    options['categories'] = [
        {
            'value':'1',
            "label": u"Frais",
            'description':u"Frais liés au fonctionnement de l'entreprise"
        },
        {
            'value':'2',
            "label": u"Achats",
            'description':u"Frais concernant directement votre activité auprès \
de vos clients"
        }]

    options['bookmarks'] = get_bookmarks(request)

    expense_sheet = request.context
    month = expense_sheet.month
    year = expense_sheet.year

    date = datetime.date(year, month, 1)
    options['today'] = date

    return options
Example #9
0
def deferred_type_id_validator(node, kw):
    """
        Return a validator for the expensetype
    """
    ids = [t.id for t in ExpenseType.query()]
    return colander.OneOf(ids)
Example #10
0
def deferred_type_id_validator(node, kw):
    """
        Return a validator for the expensetype
    """
    ids = [t.id for t in ExpenseType.query()]
    return colander.OneOf(ids)
Example #11
0
    def get_columns(self):
        """
            Retrieve all columns and define a global column attribute
            :param internal: are we asking columns for internal expenses
        """
        columns = []
        # Add the two first columns
        columns.append(StaticColumn(label='Date', key='date'))
        columns.append(
            StaticColumn(
                label='Description',
                key='description',
                nb_col=3
            )
        )

        # Telephonic fees are only available as internal expenses
        tel_column = self.get_tel_column()
        if tel_column is not None:
            columns.append(tel_column)

        km_column = self.get_km_column()
        if km_column:
            columns.append(km_column)
            kmtype_code = km_column.code
        else:
            kmtype_code = None

        commontypes = ExpenseType.query()\
                .filter(ExpenseType.type=="expense")\
                .filter(ExpenseType.active==True)
        for type_ in commontypes:
            # Here's a hack to allow to group km fee types and displacement fees
            if kmtype_code is not None and \
               type_.code != kmtype_code:
                columns.append(TypedColumn(type_))

        columns.extend(self.get_disabled_types_columns())

        # Add the last columns
        columns.append(
            StaticColumn(
                label='Tva',
                key='tva',
                formatter=integer_to_amount
            )
        )
        columns.append(
            StaticColumn(
                label="Total",
                key="total",
                formatter=integer_to_amount,
                style=NUMBER_CELL,
            )
        )

        # We set the appropriate letter to each column
        index = 0
        for col in columns:
            letter = ASCII_UPPERCASE[index]
            additional_cell_nb = col.additional_cell_nb
            if additional_cell_nb:
                last_letter = ASCII_UPPERCASE[index + additional_cell_nb]
                index += additional_cell_nb + 1
            else:
                last_letter = letter
                index += 1
            col.set_letter(letter, last_letter)
        return columns