def validator(node, value): query = BusinessType.query().filter_by(project_type_id=value) if isinstance(context, BusinessType): query = query.filter(not_(BusinessType.id == context.id)) if query.count() > 0: raise colander.Invalid( node, u"Ce type de projet a déjà un type d'affaire par défaut")
def __call__(self): return dict( business_types=BusinessType.query().all(), mentions=TaskMention.query().all(), items=self._collect_items(), breadcrumb=self.breadcrumb, back_link=self.back_link, help_message=self.help_message, )
def validator(node, value): query = BusinessType.query().filter_by(project_type_id=value) if isinstance(context, BusinessType): query = query.filter(not_(BusinessType.id == context.id)) if query.count() > 0: raise colander.Invalid( node, u"Ce type de projet a déjà un type d'affaire par défaut" )
def migrate_datas(): from autonomie_base.models.base import DBSESSION session = DBSESSION() from autonomie.models.populate import populate_project_types populate_project_types(session) from autonomie.models.project.types import ( ProjectType, BusinessType, ) from autonomie.models.populate import populate_project_types populate_project_types(session) default_ptype_id = ProjectType.get_default().id default_btype_id = BusinessType.get_default().id course_ptype_id = ProjectType.query().filter_by(name='training').first().id course_btype_id = BusinessType.query().filter_by( name='training').first().id op.execute("update project set project_type_id=%s" % default_ptype_id) op.execute("update task set version='4.1'") for typ_ in ('estimation', 'invoice'): query = "update task join {type_} on {type_}.id=task.id set \ business_type_id={btype_id} where {type_}.course={course}" op.execute( query.format(type_=typ_, btype_id=default_btype_id, course=0)) op.execute(query.format(type_=typ_, btype_id=course_btype_id, course=1)) query2 = "update project set project_type_id={ptype_id} where \ (select count(task.id) from task join {type_} on {type_}.id=task.id \ where {type_}.course=1 and task.project_id=project.id ) > 0;" op.execute(query2.format( type_=typ_, ptype_id=course_ptype_id, )) query = "update task join cancelinvoice on cancelinvoice.id=task.id set \ business_type_id={btype_id}".format(btype_id=default_btype_id) op.execute(query) query = "update task join cancelinvoice on cancelinvoice.id=task.id join \ task as task2 on cancelinvoice.invoice_id=task2.id set \ task.business_type_id={btype_id} where task2.business_type_id=4".format( btype_id=course_btype_id) op.execute(query) _add_business_to_all_invoices(session)
def populate_project_types(session): from autonomie.models.project.types import ( ProjectType, BusinessType, ) for name, label, subtype_label, private, default in ( ( "default", u"Projet classique", "Affaire simple", False, True, ), ("training", u"Convention de formation", "Formation", True, False), ("construction", u"Chantiers", u"Chantier", True, False), ): ptype = ProjectType.query().filter_by(name=name).first() if ptype is None: ptype = ProjectType( name=name, label=label, editable=False, private=private, default=default, ) session.add(ptype) session.flush() if name is not 'default': default_btype = BusinessType.query().filter_by( name='default').first() default_btype.other_project_types.append(ptype) session.merge(default_btype) session.flush() if session.query(BusinessType.id).filter_by(name=name).count() == 0: session.add( BusinessType( name=name, label=subtype_label, editable=False, private=private, project_type_id=ptype.id, )) session.flush()
def populate_project_types(session): from autonomie.models.project.types import ( ProjectType, BusinessType, ) for name, label, subtype_label, private, default in ( ("default", u"Projet classique", "Affaire simple", False, True,), ("training", u"Convention de formation", "Formation", True, False), ("construction", u"Chantiers", u"Chantier", True, False), ): ptype = ProjectType.query().filter_by(name=name).first() if ptype is None: ptype = ProjectType( name=name, label=label, editable=False, private=private, default=default, ) session.add(ptype) session.flush() if name is not 'default': default_btype = BusinessType.query().filter_by( name='default').first() default_btype.other_project_types.append(ptype) session.merge(default_btype) session.flush() if session.query(BusinessType.id).filter_by(name=name).count() == 0: session.add( BusinessType( name=name, label=subtype_label, editable=False, private=private, project_type_id=ptype.id, ) ) session.flush()
def load_items(self): items = BusinessType.query() items = items.order_by(self.factory.name) return items