Beispiel #1
0
    def gen_companies(self):
        """
        Generate companies as expected
        """
        from autonomie.models.company import Company
        companies = []
        for data in self.activity_companydatas:
            # Try to retrieve an existing company (and avoid duplicates)
            company = Company.query().filter(
                Company.name == data.name
            ).first()

            if company is None:
                company = Company(
                    name=data.name,
                    goal=data.title,
                    email=self.coordonnees_email1,
                    phone=self.coordonnees_tel,
                    mobile=self.coordonnees_mobile,
                )
                if data.activity is not None:
                    company.activities.append(data.activity)

            company.employees.append(self.user)
            companies.append(company)
        return companies
Beispiel #2
0
def get_company_by_code(code_compta):
    """
    Return the company associated to this code_compta
    :param str code_compta: The analytic code of the company to find
    """
    query = Company.query().filter(Company.code_compta==code_compta)
    return query.first()
    def gen_companies(self):
        """
        Generate companies as expected
        """
        from autonomie.models.company import Company
        companies = []
        for data in self.activity_companydatas:
            # Try to retrieve an existing company (and avoid duplicates)
            company = Company.query().filter(
                Company.name == data.name
            ).first()

            if company is None:
                company = Company(
                    name=data.name,
                    goal=data.title,
                    email=self.coordonnees_email1,
                    phone=self.coordonnees_tel,
                    mobile=self.coordonnees_mobile,
                )
                if data.activity is not None:
                    company.activities.append(data.activity)

            company.employees.append(self.user)
            companies.append(company)
        return companies
Beispiel #4
0
    def submit_success(self, appstruct):
        """
            Insert config informations into database
        """
        # la table config étant un stockage clé valeur
        # le merge_session_with_post ne peut être utilisé
        dbdatas = Config.query().all()

        log.debug(u"Cae configuration submission")
        log.debug(appstruct)

        new_dbdatas = merge_config_datas(dbdatas, appstruct)
        for dbdata in new_dbdatas:
            log.debug(dbdata.name)
            if dbdata in dbdatas:
                self.dbsession.merge(dbdata)
            else:
                self.dbsession.add(dbdata)
            # If we set the contribution_cae value, we want it to be the default
            # for every company that has no contribution value set
            if dbdata.name == 'contribution_cae':
                for comp in Company.query():
                    if comp.contribution is None:
                        comp.contribution = dbdata.value
                        self.dbsession.merge(comp)
        self.dbsession.flush()
        self.request.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path("admin_cae"))
Beispiel #5
0
def get_company_by_code(code_compta):
    """
    Return the company associated to this code_compta
    :param str code_compta: The analytic code of the company to find
    """
    query = Company.query().filter(Company.code_compta == code_compta)
    return query.first()
Beispiel #6
0
    def submit_success(self, appstruct):
        """
            Insert config informations into database
        """
        # la table config étant un stockage clé valeur
        # le merge_session_with_post ne peut être utilisé
        dbdatas = Config.query().all()

        log.debug(u"Cae configuration submission")
        log.debug(appstruct)

        new_dbdatas = merge_config_datas(dbdatas, appstruct)
        for dbdata in new_dbdatas:
            log.debug(dbdata.name)
            if dbdata in dbdatas:
                self.dbsession.merge(dbdata)
            else:
                self.dbsession.add(dbdata)
            # If we set the contribution_cae value, we want it to be the default
            # for every company that has no contribution value set
            if dbdata.name == 'contribution_cae':
                for comp in Company.query():
                    if comp.contribution is None:
                        comp.contribution = dbdata.value
                        self.dbsession.merge(comp)
        self.dbsession.flush()
        self.request.session.flash(self.validation_msg)
        return HTTPFound(self.request.route_path("admin_cae"))
Beispiel #7
0
 def get_company(self, name, user):
     """
         Return a company object, create a new one if needed
     """
     company = Company.query().filter(Company.name==name).first()
     #avoid creating duplicate companies
     if company is None:
         company = self.add_company(name, user)
     return company
Beispiel #8
0
 def _get_company(self, name, user):
     """
         Return a company object, create a new one if needed
     """
     query = Company.query()
     company = query.filter(Company.name == name).first()
     # avoid creating duplicate companies
     if company is None:
         company = self._add_company(name, user)
     return company
Beispiel #9
0
def get_companies(request):
    """
        Retrieve the companies the current user has access to
    """
    companies = []
    if request.has_permission('manage'):
        companies = Company.query().all()
    else:
        companies = request.user.active_companies
    return companies
Beispiel #10
0
def get_companies(request):
    """
        Retrieve the companies the current user has access to
    """
    companies = []
    if request.user.is_admin() or request.user.is_manager():
        companies = Company.query().all()
    else:
        companies = request.user.companies
    return companies
Beispiel #11
0
def customer(config, content, get_csrf_request_with_db):
    config.add_route('customer', '/')
    request = get_csrf_request_with_db()
    comp = Company.query().first()
    comp.__name__ = 'company'
    request.context = comp
    request.user = get_user()
    view = CustomerAdd(request)
    view.submit_success(APPSTRUCT)
    return getOne()
Beispiel #12
0
def customer(config, content, get_csrf_request_with_db):
    config.add_route('customer', '/')
    request = get_csrf_request_with_db()
    comp = Company.query().first()
    comp.__name__ = 'company'
    request.context = comp
    request.user = Dummy()
    view = CustomerAdd(request)
    view.submit_success(APPSTRUCT)
    return getOne()
Beispiel #13
0
def get_companies(request):
    """
        Retrieve the companies the current user has access to
    """
    companies = []
    if request.user.is_admin() or request.user.is_manager():
        companies = Company.query().all()
    else:
        companies = request.user.companies
    return companies
Beispiel #14
0
    def submit_success(self, appstruct):
        for name in appstruct.get('companies', []):
            company = Company.query().filter(Company.name == name).first()
            if company is not None:
                self.context.user.companies.append(company)
                self.request.dbsession.merge(self.context.user)

        url = self.request.route_path("userdata",
                                      id=self.context.id,
                                      _anchor="tab5")
        return HTTPFound(url)
Beispiel #15
0
def get_companies(request):
    """
        Retrieve the companies the current user has access to
    """
    companies = []
    if request.has_permission('manage'):
        print(u"Has the permission")
        companies = Company.query().all()
    else:
        companies = request.user.companies
    return companies
Beispiel #16
0
def project(config, get_csrf_request_with_db):
    from autonomie.views.project import ProjectAdd
    config.add_route('project', '/')
    req = get_csrf_request_with_db()
    company = Company.query().first()
    company.__name__ = 'company'
    req.context = company
    view = ProjectAdd(req)
    appstruct = APPSTRUCT.copy()
    view.submit_success(appstruct)
    return getone()
Beispiel #17
0
def project(config, get_csrf_request_with_db):
    from autonomie.views.project import ProjectAdd
    config.add_route('project', '/')
    req = get_csrf_request_with_db()
    company = Company.query().first()
    company.__name__ = 'company'
    req.context = company
    view = ProjectAdd(req)
    appstruct = APPSTRUCT.copy()
    view.submit_success(appstruct)
    return getone()
Beispiel #18
0
def belongs_to_company(filename):
    """
    Check if a file belongs to a company

    :param str filename: The filename we want to check
    """
    try:
        code_compta = get_code_compta(filename)
        result = Company.query().filter(Company.code_compta==code_compta).count() > 0
    except:
        result = False
    return result
Beispiel #19
0
def belongs_to_company(filename):
    """
    Check if a file belongs to a company

    :param str filename: The filename we want to check
    """
    try:
        code_compta = get_code_compta(filename)
        result = Company.query().filter(
            Company.code_compta == code_compta).count() > 0
    except:
        result = False
    return result
Beispiel #20
0
    def submit_success(self, appstruct):
        for name in appstruct.get('companies', []):
            company = Company.query().filter(Company.name == name).first()
            if company is not None and \
                    company not in self.current_user.companies:
                self.current_user.companies.append(company)
                self.request.dbsession.merge(self.current_user)

        url = self.request.route_path(
            "/users/{id}/companies",
            id=self.current_user.id,
        )
        return HTTPFound(url)
Beispiel #21
0
    def submit_success(self, appstruct):
        for name in appstruct.get('companies', []):
            company = Company.query().filter(Company.name == name).first()
            if company is not None and \
                    company not in self.current_user.companies:
                self.current_user.companies.append(company)
                self.request.dbsession.merge(self.current_user)

        url = self.request.route_path(
            "/users/{id}/companies",
            id=self.current_user.id,
        )
        return HTTPFound(url)
Beispiel #22
0
    def submit_success(self, appstruct):
        for name in appstruct.get('companies', []):
            company = Company.query().filter(Company.name == name).first()
            if company is not None:
                self.context.user.companies.append(company)
                self.request.dbsession.merge(self.context.user)

        url = self.request.route_path(
            "userdata",
            id=self.context.id,
            _anchor="tab5"
        )
        return HTTPFound(url)
Beispiel #23
0
    def test_add(self, config, get_csrf_request_with_db):
        from autonomie.views.company import CompanyAdd

        config.add_route('company', 'company')

        post = DATAS.copy()
        req = get_csrf_request_with_db(post=post)
        view = CompanyAdd(req)
        view.__call__()

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert company.goal == u"Be the best"
        assert company.contribution == 80
    def test_user_id(self, config, get_csrf_request_with_db, user):
        from autonomie.views.company import CompanyAdd

        post = DATAS.copy()
        post['user_id'] = str(user.id)
        req = get_csrf_request_with_db(post=post)
        req.referrer = "/test"

        view = CompanyAdd(req)
        view.__call__()

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert user in company.employees
Beispiel #25
0
    def test_user_id(self, config, get_csrf_request_with_db, user):
        from autonomie.views.company import CompanyAdd

        post = DATAS.copy()
        post['user_id'] = str(user.id)
        req = get_csrf_request_with_db(post=post)
        req.referrer = "/test"

        view = CompanyAdd(req)
        view.__call__()

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert user in company.employees
    def test_add(self, config, get_csrf_request_with_db):
        from autonomie.views.company import CompanyAdd

        config.add_route('company', 'company')

        post = DATAS.copy()
        req = get_csrf_request_with_db(post=post)
        view = CompanyAdd(req)
        view.__call__()

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert company.goal == u"Be the best"
        assert company.contribution == 80
Beispiel #27
0
 def __call__(self):
     """
         the stats view
     """
     ret_dict = dict(title=u"Statistiques")
     companies = Company.query([Company.id, Company.name]).all()
     ret_dict['companies'] = companies
     current_year = 2000
     years = range(2000, datetime.date.today().year + 1)
     ret_dict['years'] = years
     if self.request.context.__name__ == 'company':
         if 'year' in self.request.params:
             try:
                 year = int(self.request.params['year'])
                 if year not in years:
                     raise ValueError
             except:
                 year = 2000
             current_year = year
         company = self.request.context
         projects = company.projects
         customers = company.customers
         invoices = []
         estimations = []
         for proj in projects:
             invoices.extend(
                 [inv
                  for inv in proj.invoices
                  if inv.taskDate.year >= current_year]
             )
             estimations.extend(
                 [est
                  for est in proj.estimations
                  if est.taskDate.year >= current_year]
             )
         prospects = [cli
                      for cli in customers
                      if True not in [len(proj.invoices) > 0
                                      for proj in cli.projects]]
         #Return the stats
         ret_dict['current_company'] = company
         ret_dict['projects'] = projects
         ret_dict['customers'] = customers
         ret_dict['prospects'] = prospects
         ret_dict['invoices'] = invoices
         ret_dict['estimations'] = estimations
     ret_dict['current_year'] = current_year
     return ret_dict
Beispiel #28
0
    def test_come_from(self, config, get_csrf_request_with_db, user):
        from autonomie.views.company import CompanyAdd

        post = DATAS.copy()
        post['come_from'] = "/test"
        req = get_csrf_request_with_db(post=post)
        req.referrer = "/test"

        view = CompanyAdd(req)
        result = view.__call__()

        assert result.location == "/test"

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert company.goal == u"Be the best"
        assert company.contribution == 80
    def test_come_from(self, config, get_csrf_request_with_db, user):
        from autonomie.views.company import CompanyAdd

        post = DATAS.copy()
        post['come_from'] = "/test"
        req = get_csrf_request_with_db(post=post)
        req.referrer = "/test"

        view = CompanyAdd(req)
        result = view.__call__()

        assert result.location == "/test"

        company = Company.query().filter_by(name=u"Compané $& test").first()
        assert company is not None
        assert company.goal == u"Be the best"
        assert company.contribution == 80
Beispiel #30
0
    def deferred_customer_widget(node, kw):
        if is_admin:
            # All customers, grouped by Company
            for comp in Company.query().options(load_only("id", "name")):
                customers = Customer.label_query().filter_by(
                    company_id=comp.id, )
                values.append(
                    deform.widget.OptGroup(comp.name,
                                           *build_customer_values(customers)))
        else:
            # Company customers only
            company = kw['request'].context
            for cust in company.customers:
                values.append((cust.id, u"%s (%s)" % (cust.name, cust.code)))

        return deform.widget.Select2Widget(values=values,
                                           **(widget_options or {}))
def test_unique_ccode(dbsession, content):
    # A IMDD exists in the database for the company with id 1
    company = Company.query().first()
    company.__name__ = 'company'
    validator = makeOne(company)
    with pytest.raises(colander.Invalid):
        validator('nutt', u'C001')
    validator('nutt', u'C002')

    company = Company(
        name="company2",
        goal="Company of user2",
        phone='0457858586',
    )
    company.__name__ = 'company'
    validator = makeOne(company)
    validator('nutt', u'C001')

    # In edit mode, no error is raised for the current_customer
    customer = dbsession.query(Customer).first()
    customer.__name__ = 'customer'
    validator = makeOne(customer)
    validator('nutt', u'C001')
Beispiel #32
0
def getOne():
    return Company.query().filter(Company.name == APPSTRUCT['name']).first()
Beispiel #33
0
def get_company(code_compta):
    """
    Return the company associated to this code_compta
    """
    return Company.query().filter(Company.code_compta == code_compta).first()
 def default_form_values(self, appstruct):
     values = super(GlobalInvoicesList, self).default_form_values(appstruct)
     values['companies'] = Company.query().all()
     return values
Beispiel #35
0
 def query(self):
     return Company.query(active=False)
Beispiel #36
0
def get_companies_choices():
    """
        Return companies choices for autocomplete
    """
    return [comp.name for comp in Company.query([Company.name]).all()]
Beispiel #37
0
 def query(self):
     return Company.query(active=False)
Beispiel #38
0
def get_companies_choices():
    """
        Return companies choices for autocomplete
    """
    return [comp.name for comp in Company.query([Company.name]).all()]
Beispiel #39
0
def getOne():
    return Company.query().filter(Company.name==APPSTRUCT['name']).first()
def company(content):
    return Company.query().first()
Beispiel #41
0
def company(content):
    return Company.query().first()
Beispiel #42
0
 def company(self):
     return Company.query().first()
Beispiel #43
0
def get_company(code_compta):
    """
    Return the company associated to this code_compta
    """
    return Company.query().filter(Company.code_compta == code_compta).first()