示例#1
0
def create_custom_treasury_modules(session, logger):
    logger.warn("Adding custom treasury modules")
    from autonomie.models.config import Config
    from autonomie.models.treasury import CustomInvoiceBookEntryModule

    organic_keys = (
        u"Contribution à l'organic",
        'compte_cg_organic',
        'compte_cg_debiteur_organic',
        'taux_contribution_organic',
        'sage_organic',
        u'Contribution Organic {client.name} {entreprise.name}'
    )

    cgscop_keys = (
        u"Contribution à la CGSCOP",
        'compte_cgscop',
        'compte_cg_debiteur',
        'taux_cgscop',
        'sage_cgscop',
        u'{client.name} {entreprise.name}'
    )

    assurance_keys = (
        u"Assurance",
        'compte_cg_assurance',
        'compte_cg_assurance',
        'taux_assurance',
        'sage_assurance',
        u'{client.name} {entreprise.name}',
    )

    for keys in (organic_keys, cgscop_keys, assurance_keys, ):
        (
            title,
            cg_debit,
            cg_credit,
            percentage_key,
            active_key,
            label_template
        ) = keys

        compte_cg_debit = Config.get(cg_debit)
        compte_cg_credit = Config.get(cg_credit)
        percentage = Config.get(percentage_key)
        enabled = Config.get(active_key, False)
        if compte_cg_debit and compte_cg_debit.value and compte_cg_credit and compte_cg_credit.value and percentage is not None:
            module = CustomInvoiceBookEntryModule(
                title=title,
                compte_cg_debit=compte_cg_debit.value,
                compte_cg_credit=compte_cg_credit.value,
                percentage=percentage.value,
                enabled=enabled.value,
                label_template=label_template,
            )
            session.add(module)
def create_custom_treasury_modules(session, logger):
    logger.warn("Adding custom treasury modules")
    from autonomie.models.config import Config
    from autonomie.models.treasury import CustomInvoiceBookEntryModule

    organic_keys = (
        u"Contribution à l'organic",
        'compte_cg_organic',
        'compte_cg_debiteur_organic',
        'taux_contribution_organic',
        'sage_organic',
        u'Contribution Organic {client.name} {entreprise.name}'
    )

    cgscop_keys = (
        u"Contribution à la CGSCOP",
        'compte_cgscop',
        'compte_cg_debiteur',
        'taux_cgscop',
        'sage_cgscop',
        u'{client.name} {entreprise.name}'
    )

    assurance_keys = (
        u"Assurance",
        'compte_cg_assurance',
        'compte_cg_assurance',
        'taux_assurance',
        'sage_assurance',
        u'{client.name} {entreprise.name}',
    )

    for keys in (organic_keys, cgscop_keys, assurance_keys, ):
        (
            title,
            cg_debit,
            cg_credit,
            percentage_key,
            active_key,
            label_template
        ) = keys

        compte_cg_debit = Config.get(cg_debit)
        compte_cg_credit = Config.get(cg_credit)
        percentage = Config.get(percentage_key)
        enabled = Config.get(active_key, False)
        if compte_cg_debit and compte_cg_debit.value and compte_cg_credit and compte_cg_credit.value and percentage is not None:
            module = CustomInvoiceBookEntryModule(
                title=title,
                compte_cg_debit=compte_cg_debit.value,
                compte_cg_credit=compte_cg_credit.value,
                percentage=percentage.value,
                enabled=enabled.value,
                label_template=label_template,
            )
            session.add(module)
示例#3
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        back_link = self.back_link
        if back_link is not None:
            result = HTTPFound(self.back_link)
        else:
            logger.error(u"This view %s is not able to provide a back_link "
                         u"after validation" % self)
            result = None
        return result
 def highlight_key(self):
     config_key = Config.get("treasury_measure_ui")
     if config_key is None:
         key = 1
     else:
         key = int(config_key.value)
     return key
示例#5
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        back_link = self.back_link
        if back_link is not None:
            result = HTTPFound(self.back_link)
        else:
            logger.error(u"This view %s is not able to provide a back_link "
                         u"after validation" % self)
            result = None
        return result
示例#6
0
 def highlight_key(self):
     config_key = Config.get("treasury_measure_ui")
     if config_key is None:
         key = 1
     else:
         key = int(config_key.value)
     return key
示例#7
0
def test_base_config_view(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin.tools import BaseConfigView
    from autonomie.forms.admin import get_config_schema

    class TestView(BaseConfigView):
        title = u"Test",
        keys = ('test_key1', 'test_key2')
        schema = get_config_schema(keys)
        validation_msg = u"Ok"
        redirect_path = "test"

    config.add_route(TestView.redirect_path, '/')

    appstruct = {'test_key1': 'test1', 'test_wrong_key': 'test error'}

    view = TestView(get_csrf_request_with_db())
    view.submit_success(appstruct)

    assert Config.get('test_key1').value == 'test1'
    assert Config.get('test_wrong_key') == None
示例#8
0
def test_base_config_view(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin.tools import BaseConfigView
    from autonomie.forms.admin import get_config_schema

    class TestView(BaseConfigView):
        title = u"Test",
        keys = ('test_key1', 'test_key2')
        schema = get_config_schema(keys)
        validation_msg = u"Ok"
        redirect_path = "test"

    config.add_route(TestView.redirect_path, '/')

    appstruct = {'test_key1': 'test1', 'test_wrong_key': 'test error'}

    view = TestView(get_csrf_request_with_db())
    view.submit_success(appstruct)

    assert Config.get('test_key1').value == 'test1'
    assert Config.get('test_wrong_key') == None
示例#9
0
def test_expense_config_success(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin.main import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {
            "code_journal": "JOURNAL01",
            'compte_cg': "DOE548",
            'expenses':[
{'label':u"Restauration", "code":u"0001", "id":None, 'compte_tva':"CTVA" },

{'label':u"Déplacement", "code":u"0002", "id":None, 'code_tva':"TVA"}
        ],
                'expenseskm':[
{'label':u"Scooter", "code":u"0003", "amount":"0.852", "id":None,
    'code_tva':"TVA1"}],
                'expensestel':[
{'label':u"Adsl-Téléphone", "code":u"0004", "percentage":"80",
    "id":None, "code_tva": "TVA2", 'contribution': True}]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    assert "DOE548" == Config.get('compte_cg_ndf').value
    assert "JOURNAL01" == Config.get('code_journal_ndf').value

    form = DummyForm()
    view.before(form)
    assert len(form.appstruct['expenses']) == 2
    assert form.appstruct['expenses'][0]['label'] == u"Restauration"
    assert form.appstruct['expenses'][0]['code'] == u"0001"
    assert form.appstruct['expenses'][0]['compte_tva'] == "CTVA"
    assert form.appstruct['expenses'][1]['code_tva'] == "TVA"

    assert form.appstruct['expenseskm'][0]['label'] == u"Scooter"
    assert form.appstruct['expenseskm'][0]['amount'] == 0.852
    assert form.appstruct['expenseskm'][0]['code_tva'] == 'TVA1'
    assert form.appstruct['expensestel'][0]['percentage'] == 80
    assert form.appstruct['expensestel'][0]['code_tva'] == 'TVA2'
    assert form.appstruct['expensestel'][0]['contribution'] == True
示例#10
0
def test_expense_config_success(config, dbsession, get_csrf_request_with_db):
    from autonomie.views.admin import AdminExpense
    config.add_route('admin_expense', '/')
    appstruct = {
            "code_journal": "JOURNAL01",
            'compte_cg': "DOE548",
            'expenses':[
{'label':u"Restauration", "code":u"0001", "id":None, 'compte_tva':"CTVA" },

{'label':u"Déplacement", "code":u"0002", "id":None, 'code_tva':"TVA"}
        ],
                'expenseskm':[
{'label':u"Scooter", "code":u"0003", "amount":"0.852", "id":None,
    'code_tva':"TVA1"}],
                'expensestel':[
{'label':u"Adsl-Téléphone", "code":u"0004", "percentage":"80",
    "id":None, "code_tva": "TVA2", 'contribution': True}]}
    view = AdminExpense(get_csrf_request_with_db())
    view.submit_success(appstruct)

    assert "DOE548" == Config.get('compte_cg_ndf').value
    assert "JOURNAL01" == Config.get('code_journal_ndf').value

    form = DummyForm()
    view.before(form)
    assert len(form.appstruct['expenses']) == 2
    assert form.appstruct['expenses'][0]['label'] == u"Restauration"
    assert form.appstruct['expenses'][0]['code'] == u"0001"
    assert form.appstruct['expenses'][0]['compte_tva'] == "CTVA"
    assert form.appstruct['expenses'][1]['code_tva'] == "TVA"

    assert form.appstruct['expenseskm'][0]['label'] == u"Scooter"
    assert form.appstruct['expenseskm'][0]['amount'] == 0.852
    assert form.appstruct['expenseskm'][0]['code_tva'] == 'TVA1'
    assert form.appstruct['expensestel'][0]['percentage'] == 80
    assert form.appstruct['expensestel'][0]['code_tva'] == 'TVA2'
    assert form.appstruct['expensestel'][0]['contribution'] == True
示例#11
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        if self.redirect_path is not None:
            return HTTPFound(self.request.route_path(self.redirect_path))
        else:
            return HTTPFound(self.request.current_route_path())
示例#12
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        if self.redirect_path is not None:
            return HTTPFound(self.request.route_path(self.redirect_path))
        else:
            return HTTPFound(self.request.current_route_path())
示例#13
0
 def _get_actual_config_obj(self, config_key):
     """
     Return the actual configured compte_cg object
     """
     return Config.get(config_key)
示例#14
0
def get_preferences_obj():
    """
    Return the config object used to store prefereces
    """
    return Config.get('csv_import') or Config(name='csv_import')
def upgrade():
    from autonomie_base.models.base import DBSESSION
    from autonomie.models.workshop import WorkshopAction
    from alembic.context import get_bind
    session = DBSESSION()
    conn = get_bind()

    col = sa.Column('activity_id', sa.Integer(),
                    sa.ForeignKey('company_activity.id'))
    op.add_column('company_datas', col)
    col = sa.Column('archived',
                    sa.Boolean(),
                    default=False,
                    server_default="0")
    op.add_column('customer', col)

    # Migration de accompagnement_header.png en activity_header.png
    op.execute(
        'update config_files set config_files.key="activity_header_img.png" where \
config_files.key="accompagnement_header.png";')

    # Le bas de page des pdfs est celui par defaut pour les ateliers et rdv
    from autonomie.models.config import Config
    val = Config.get('coop_pdffootertext').value
    if val:
        for key in ('activity', 'workshop'):
            config_key = '%s_footer' % key
            config = Config.set(config_key, val)

    # Migration de la taille des libelles pour les actions des rendez-vous
    op.execute("alter table activity_action modify label VARCHAR(255)")
    # Migration des intitules des ateliers
    # 1- Ajout des nouvelles foreignkey
    for name in 'info1_id', 'info2_id', 'info3_id':
        col = sa.Column(name, sa.Integer, sa.ForeignKey("workshop_action.id"))
        op.add_column("workshop", col)

    # 2- création des options en fonction des valeurs en durs
    request = "select id, info1, info2, info3 from workshop"
    result = conn.execute(request)

    already_added = {}

    for id, info1, info2, info3 in result:
        info1 = info1.lower()
        info2 = info2.lower()
        info3 = info3.lower()
        info1_id = info2_id = info3_id = None
        if (info1, info2, info3) not in already_added.keys():

            for key, value in already_added.items():
                if key[0] == info1 and info1:
                    info1_id = value[0]
                    if key[1] == info2 and info2:
                        info2_id = value[1]

            if info1_id is None and info1:
                w = WorkshopAction(label=info1)
                session.add(w)
                session.flush()
                info1_id = w.id

            if info2_id is None and info2:
                w = WorkshopAction(label=info2, parent_id=info1_id)
                session.add(w)
                session.flush()
                info2_id = w.id

            if info3:
                w = WorkshopAction(label=info3, parent_id=info2_id)
                session.add(w)
                session.flush()
                info3_id = w.id
            already_added[(info1, info2, info3)] = (
                info1_id,
                info2_id,
                info3_id,
            )
        else:
            info1_id, info2_id, info3_id = already_added[(info1, info2, info3)]

        request = "update workshop "
        if info1_id:
            request += "set info1_id={0}".format(info1_id)
            if info2_id:
                request += ", info2_id={0}".format(info2_id)
                if info3_id:
                    request += ", info3_id={0}".format(info3_id)
            request += " where id={0}".format(id)
            op.execute(request)
示例#16
0
 def _get_actual_config_obj(self, config_key):
     """
     Return the actual configured compte_cg object
     """
     return Config.get(config_key)
def upgrade():
    from autonomie.models import DBSESSION
    from autonomie.models.workshop import WorkshopAction
    from alembic.context import get_bind

    session = DBSESSION()
    conn = get_bind()

    col = sa.Column("activity_id", sa.Integer(), sa.ForeignKey("company_activity.id"))
    op.add_column("company_datas", col)
    col = sa.Column("archived", sa.Boolean(), default=False, server_default="0")
    op.add_column("customer", col)

    # Migration de accompagnement_header.png en activity_header.png
    op.execute(
        'update config_files set config_files.key="activity_header_img.png" where \
config_files.key="accompagnement_header.png";'
    )

    # Le bas de page des pdfs est celui par defaut pour les ateliers et rdv
    from autonomie.models.config import Config

    val = Config.get("coop_pdffootertext").value
    if val:
        for key in ("activity", "workshop"):
            config_key = "%s_footer" % key
            config = Config.set(config_key, val)

    # Migration de la taille des libelles pour les actions des rendez-vous
    op.execute("alter table activity_action modify label VARCHAR(255)")
    # Migration des intitules des ateliers
    # 1- Ajout des nouvelles foreignkey
    for name in "info1_id", "info2_id", "info3_id":
        col = sa.Column(name, sa.Integer, sa.ForeignKey("workshop_action.id"))
        op.add_column("workshop", col)

    # 2- création des options en fonction des valeurs en durs
    request = "select id, info1, info2, info3 from workshop"
    result = conn.execute(request)

    already_added = {}

    for id, info1, info2, info3 in result:
        info1 = info1.lower()
        info2 = info2.lower()
        info3 = info3.lower()
        info1_id = info2_id = info3_id = None
        if (info1, info2, info3) not in already_added.keys():

            for key, value in already_added.items():
                if key[0] == info1 and info1:
                    info1_id = value[0]
                    if key[1] == info2 and info2:
                        info2_id = value[1]

            if info1_id is None and info1:
                w = WorkshopAction(label=info1)
                session.add(w)
                session.flush()
                info1_id = w.id

            if info2_id is None and info2:
                w = WorkshopAction(label=info2, parent_id=info1_id)
                session.add(w)
                session.flush()
                info2_id = w.id

            if info3:
                w = WorkshopAction(label=info3, parent_id=info2_id)
                session.add(w)
                session.flush()
                info3_id = w.id
            already_added[(info1, info2, info3)] = (info1_id, info2_id, info3_id)
        else:
            info1_id, info2_id, info3_id = already_added[(info1, info2, info3)]

        request = "update workshop "
        if info1_id:
            request += "set info1_id={0}".format(info1_id)
            if info2_id:
                request += ", info2_id={0}".format(info2_id)
                if info3_id:
                    request += ", info3_id={0}".format(info3_id)
            request += " where id={0}".format(id)
            op.execute(request)