def test_customer(self): from autonomie.models.customer import Customer print Customer.get(1) appstruct = {'name':u'Projéct&$', "code":"ABDC", "customers":["1"]} self.addOne(appstruct) project = self.getOne() self.assertEqual(len(project.customers), 1)
def test_customer_archive(customer, get_csrf_request_with_db): req = get_csrf_request_with_db() cid = customer.id from autonomie.views.customer import customer_archive req.context = customer req.referer = '/' customer_archive(req) req.dbsession.flush() assert Customer.get(cid).archived customer_archive(req) req.dbsession.flush() assert Customer.get(cid).archived is False
def submit_success(self, appstruct): if self.factory is None: raise Exception("Forgot to set the factory attribute") project_id = appstruct.pop('project_id') appstruct['project'] = Project.get(project_id) customer_id = appstruct.pop('customer_id') appstruct['customer'] = Customer.get(customer_id) new_object = self.factory( user=self.request.user, company=self.context.company, **appstruct ) if hasattr(self, "_more_init_attributes"): self._more_init_attributes(new_object, appstruct) self.dbsession.add(new_object) self.dbsession.flush() if hasattr(self, "_after_flush"): self._after_flush(new_object) url = self.request.route_path( "/%ss/{id}" % new_object.type_, id=new_object.id ) return HTTPFound(url)
def submit_success(self, appstruct): log.debug("Submitting cancelinvoice add") appstruct = get_cancel_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) cinvoice = CancelInvoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) cinvoice = merge_session_with_post( cinvoice, appstruct["task"] ) try: cinvoice = self.set_task_status(cinvoice) cinvoice.invoice.check_resulted(user_id=self.request.user.id) self.dbsession.merge(cinvoice.invoice) # Line handling cinvoice = add_lines_to_cancelinvoice(cinvoice, appstruct) self.dbsession.add(cinvoice) self.dbsession.flush() self.session.flash(u"L'avoir a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting estimation add") appstruct = get_estimation_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) estimation = Estimation( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) estimation = merge_session_with_post( estimation, appstruct['task'] ) try: # Line handling estimation = add_lines_to_estimation(estimation, appstruct) self.dbsession.add(estimation) self.dbsession.flush() estimation = self.set_task_status(estimation) self.session.flash(u"Le devis a bien été ajouté.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): log.debug("Submitting invoice add") appstruct = get_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) invoice = Invoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) invoice = merge_session_with_post( invoice, appstruct["task"] ) try: invoice = self.set_task_status(invoice) # Line handling invoice = add_lines_to_invoice(invoice, appstruct) self.dbsession.add(invoice) self.dbsession.flush() self.session.flash(u"La facture a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def submit_success(self, appstruct): if self.factory is None: raise Exception("Forgot to set the factory attribute") name = appstruct['name'] phase_id = appstruct['phase_id'] phase = Phase.get(phase_id) project_id = appstruct['project_id'] project = Project.get(project_id) customer_id = appstruct['customer_id'] customer = Customer.get(customer_id) new_object = self.factory( self.context.company, customer, project, phase, self.request.user, ) new_object.name = name if hasattr(self, "_more_init_attributes"): self._more_init_attributes(new_object, appstruct) self.dbsession.add(new_object) self.dbsession.flush() if hasattr(self, "_after_flush"): self._after_flush(new_object) url = self.request.route_path("/%ss/{id}" % new_object.type_, id=new_object.id) return HTTPFound(url)
def submit_success(self, appstruct): logger.debug("# Duplicating a document #") name = appstruct['name'] phase_id = appstruct['phase_id'] phase = Phase.get(phase_id) project_id = appstruct['project_id'] project = Project.get(project_id) customer_id = appstruct['customer_id'] customer = Customer.get(customer_id) task = self.context.duplicate( self.request.user, project, phase, customer, ) task.name = name task.course = appstruct['course'] self.dbsession.add(task) self.dbsession.flush() logger.debug( u"The {t.type_} {t.id} has been duplicated to {new_t.id}".format( t=self.context, new_t=task)) return HTTPFound( self.request.route_path('/%ss/{id}' % self.context.type_, id=task.id))
def submit_success(self, appstruct): logger.debug("# Duplicating a document #") project_id = appstruct.pop('project_id') appstruct['project'] = Project.get(project_id) customer_id = appstruct.pop('customer_id') appstruct['customer'] = Customer.get(customer_id) task = self.context.duplicate( user=self.request.user, **appstruct ) if hasattr(self, "_after_task_duplicate"): self._after_task_duplicate(task, appstruct) self.dbsession.add(task) self.dbsession.flush() logger.debug( u"The {t.type_} {t.id} has been duplicated to {new_t.id}".format( t=self.context, new_t=task ) ) return HTTPFound( self.request.route_path( '/%ss/{id}' % self.context.type_, id=task.id ) )
def submit_success(self, appstruct): log.debug("Submitting cancelinvoice add") appstruct = get_cancel_invoice_dbdatas(appstruct) customer_id = appstruct["task"]['customer_id'] customer = Customer.get(customer_id) cinvoice = CancelInvoice( self.context.company, customer, self.context, self.context.phases[0], self.request.user, ) cinvoice = merge_session_with_post(cinvoice, appstruct["task"]) try: cinvoice = self.set_task_status(cinvoice) cinvoice.invoice.check_resulted(user_id=self.request.user.id) self.dbsession.merge(cinvoice.invoice) # Line handling cinvoice = add_lines_to_cancelinvoice(cinvoice, appstruct) self.dbsession.add(cinvoice) self.dbsession.flush() self.session.flash(u"L'avoir a bien été ajoutée.") except Forbidden, err: self.request.session.flash(err.message, queue='error')
def customer_objectify(id_): """ Objectify the associated form node schema (an id schemanode) Return the customer object with the given id_ Note : colanderalchemy schemanode is to a model and provides a objectify method used to convert an appstruct to the appropriate model. For the project->customer relationship, we need to be able to configure only existing elements. Since we didn't found a clear way to do it with colanderalchemy, we add the node manually and fit the colanderalchemy way of working by implementing usefull methods (namely objectify and dictify) """ obj = Customer.get(id_) return obj
def submit_success(self, appstruct): """ Flush project edition to the database """ customer_ids = appstruct.pop("customers", []) project = merge_session_with_post(self.request.context, appstruct) project.customers = [] for customer_id in customer_ids: customer = Customer.get(customer_id) if customer is not None: project.customers.append(customer) self.dbsession.merge(project) self.dbsession.flush() message = u"Le projet <b>{0}</b> a été édité avec succès".format( project.name) self.request.session.flash(message) return HTTPFound(self.request.route_path('project', id=project.id))
def pre_duplicate_process(self, task, status, params): """ Common pre process method for document duplication """ form = get_duplicate_form(self.request) # if an error is raised here, it will be cached a level higher appstruct = form.validate(params.items()) logger.debug(u" * Form has been validated") customer_id = appstruct.get('customer') customer = Customer.get(customer_id) project_id = appstruct.get('project') project = Project.get(project_id) phase_id = appstruct.get('phase') phase = Phase.get(phase_id) logger.debug(u" * Phase : %s" % phase) logger.debug(u" * Project : %s" % project) appstruct['phase'] = phase appstruct['project'] = project appstruct['customer'] = customer appstruct['user'] = self.request.user return appstruct
def pre_duplicate_process(self, task, status, params): """ Common pre process method for document duplication """ form = get_duplicate_form(self.request) # if an error is raised here, it will be cached a level higher appstruct = form.validate(params.items()) log.debug(u" * Form has been validated") customer_id = appstruct.get('customer') customer = Customer.get(customer_id) project_id = appstruct.get('project') project = Project.get(project_id) phase_id = appstruct.get('phase') phase = Phase.get(phase_id) log.debug(u" * Phase : %s" % phase) log.debug(u" * Project : %s" % project) appstruct['phase'] = phase appstruct['project'] = project appstruct['customer'] = customer appstruct['user'] = self.request.user return appstruct
def submit_success(self, appstruct): """ Add a project with a default phase in the database """ project = Project() project.company_id = self.request.context.id customer_ids = appstruct.pop("customers", []) project = merge_session_with_post(project, appstruct) for customer_id in customer_ids: customer = Customer.get(customer_id) if customer: project.customers.append(customer) self.dbsession.add(project) self.dbsession.flush() # Add a default phase to the project default_phase = Phase() default_phase.project = project self.dbsession.add(default_phase) message = u"Le projet <b>{0}</b> a été ajouté avec succès".format( project.name) self.request.session.flash(message) return HTTPFound(self.request.route_path('project', id=project.id))