예제 #1
0
def test_is_compatible_project_type(
    dbsession,
    project,
    customer,
    user,
    company,
    other_project_type,
    default_business_type,
    mk_business_type,
):
    from autonomie.models.task.estimation import Estimation
    estimation = Estimation(
        company=company,
        project=project,
        customer=customer,
        user=user,
        business_type=other_project_type.default_business_type,
    )
    dbsession.add(estimation)
    dbsession.flush()

    from autonomie.forms.project import _is_compatible_project_type
    assert _is_compatible_project_type(project, other_project_type)

    new_estimation = Estimation(
        company=company,
        project=project,
        customer=customer,
        user=user,
        business_type=default_business_type,
    )
    dbsession.add(new_estimation)
    dbsession.flush()
    assert not _is_compatible_project_type(project, other_project_type)
예제 #2
0
def estimation(
    dbsession,
    tva,
    unity,
    project,
    customer,
    company,
    user,
    phase,
):
    from autonomie.models.task.estimation import Estimation
    estimation = Estimation(
        company=company,
        project=project,
        customer=customer,
        user=user,
        phase=phase,
    )
    dbsession.add(estimation)
    dbsession.flush()
    return estimation
예제 #3
0
    def add_estimation(cls, business, user):
        """
        Add a new estimation to the current business

        :param obj business: The current business instance this service is
        attached to
        :returns: A new Estimation instance
        """
        from autonomie.models.task.estimation import Estimation
        estimation = Estimation(
            user=user,
            company=business.project.company,
            project=business.project,
            customer_id=cls._get_customer_id(business),
            business_id=business.id,
            business_type_id=business.business_type_id,
        )
        estimation.add_default_payment_line()
        estimation.initialize_business_datas()
        DBSESSION().add(estimation)
        DBSESSION().flush()
        return estimation
예제 #4
0
    def submit_success(self, appstruct):
        log.debug("Submitting estimation add")
        appstruct = get_estimation_dbdatas(appstruct)
        # Next estimation number for current project
        snumber = self.context.get_next_estimation_number()

        estimation = Estimation()
        estimation.project = self.context
        estimation.owner = self.request.user
        estimation = merge_session_with_post(estimation,
                                             appstruct["estimation"])
        estimation.set_sequence_number(snumber)
        estimation.set_number()
        estimation.set_name()
        try:
            estimation = self.set_task_status(estimation)
            # Line handling
            estimation = add_lines_to_estimation(estimation, appstruct)
            self.dbsession.add(estimation)
            self.dbsession.flush()
            self.session.flash(u"Le devis a bien été ajoutée.")
        except Forbidden, err:
            self.request.session.flash(err.message, queue='error')