def update_work(self, request): from koalixcrm.crm.reporting.work import Work if self.has_changed(): if self.cleaned_data['work_id']: work = Work.objects.get(id=self.cleaned_data['work_id']) else: work = Work() if self.cleaned_data['DELETE']: work.delete() else: work.task = self.cleaned_data['task'] work.reporting_period = ReportingPeriod.get_reporting_period(project=self.cleaned_data['task'].project, search_date=self.cleaned_data['date']) work.human_resource = HumanResource.objects.get(user=UserExtension.get_user_extension(request.user)) work.date = self.cleaned_data['date'] if bool(self.cleaned_data['start_time']) & bool(self.cleaned_data['stop_time']): work.start_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['start_time']) work.stop_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['stop_time']) else: work.worked_hours = self.cleaned_data['worked_hours'] work.description = self.cleaned_data['description'] work.short_description = limit_string_length(work.description, 100) work.save()
def update_work(self, request): from koalixcrm.crm.reporting.work import Work if self.has_changed(): if self.cleaned_data['work_id']: work = Work.objects.get(id=self.cleaned_data['work_id']) else: work = Work() if self.cleaned_data['DELETE']: work.delete() else: work.task = self.cleaned_data['task'] work.reporting_period = ReportingPeriod.get_reporting_period(project=self.cleaned_data['task'].project, search_date=self.cleaned_data['date']) work.employee = UserExtension.get_user_extension(request.user) work.date = self.cleaned_data['date'] if bool(self.cleaned_data['start_time']) & bool(self.cleaned_data['stop_time']): work.start_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['start_time']) work.stop_time = datetime.datetime.combine(self.cleaned_data['date'], self.cleaned_data['stop_time']) else: work.worked_hours = self.cleaned_data['worked_hours'] work.description = self.cleaned_data['description'] work.short_description = limit_string_length(work.description, 100) work.save()
def serialize_to_xml(self, **kwargs): reporting_period = kwargs.get('reporting_period', None) from koalixcrm.djangoUserExtension.models import UserExtension objects = [self, ] objects += UserExtension.objects_to_serialize(self, self.project_manager) main_xml = PDFExport.write_xml(objects) for task in Task.objects.filter(project=self.id): task_xml = task.serialize_to_xml(reporting_period=reporting_period) main_xml = PDFExport.merge_xml(main_xml, task_xml) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Effort_Overall", self.effective_costs(reporting_period=None)) if reporting_period: main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Effort_InPeriod", self.effective_costs(reporting_period=reporting_period)) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Planned_Effort", self.planned_costs()) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Duration", self.effective_duration()) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Planned_Duration", self.planned_duration()) return main_xml
def serialize_to_xml(self, **kwargs): reporting_period = kwargs.get('reporting_period', None) from koalixcrm.djangoUserExtension.models import UserExtension objects = [self, ] objects += UserExtension.objects_to_serialize(self, self.project_manager) main_xml = PDFExport.write_xml(objects) for task in Task.objects.filter(project=self.id): task_xml = task.serialize_to_xml(reporting_period=reporting_period) main_xml = PDFExport.merge_xml(main_xml, task_xml) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Effort_Overall", self.effective_costs(reporting_period=None)) if reporting_period: main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Effort_InPeriod", self.effective_costs(reporting_period=reporting_period)) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Planned_Effort", self.planned_costs()) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Effective_Duration", self.effective_duration()) main_xml = PDFExport.append_element_to_pattern(main_xml, "object/[@model='crm.project']", "Planned_Duration", self.planned_duration()) return main_xml
def serialize_to_xml(self): from koalixcrm.crm.contact.contact import PostalAddressForContact from koalixcrm.crm.contact.postaladdress import PostalAddress from koalixcrm.crm.product.currency import Currency from koalixcrm.crm.contact.contact import Contact from django.contrib import auth objects = [self, ] position_class = koalixcrm.crm.documents.salesdocumentposition.SalesDocumentPosition objects += list(koalixcrm.crm.documents.salesdocument.SalesDocument.objects.filter(id=self.id)) if isinstance(self, koalixcrm.crm.documents.purchaseorder.PurchaseOrder): objects += list(Contact.objects.filter(id=self.supplier.id)) objects += list(PostalAddressForContact.objects.filter(person=self.supplier.id)) for address in list(PostalAddressForContact.objects.filter(person=self.supplier.id)): objects += list(PostalAddress.objects.filter(id=address.id)) else: objects += list(Contact.objects.filter(id=self.customer.id)) objects += list(PostalAddressForContact.objects.filter(person=self.customer.id)) for address in list(PostalAddressForContact.objects.filter(person=self.customer.id)): objects += list(PostalAddress.objects.filter(id=address.id)) objects += list(TextParagraphInSalesDocument.objects.filter(sales_document=self.id)) objects += list(Currency.objects.filter(id=self.currency.id)) objects += SalesDocumentPosition.add_positions(position_class, self) objects += list(auth.models.User.objects.filter(id=self.staff.id)) objects += UserExtension.objects_to_serialize(self, self.staff) main_xml = PDFExport.write_xml(objects) return main_xml
def create_from_reference(self, calling_model, staff): staff_user_extension = UserExtension.get_user_extension(staff.id) self.default_customer = calling_model self.default_currency = staff_user_extension.defaultCurrency self.default_template_set = staff_user_extension.defaultTemplateSet self.last_modified_by = staff self.staff = staff self.save() return self
def create_from_reference(self, calling_model, staff): staff_user_extension = UserExtension.get_user_extension(staff.id) self.default_customer = calling_model self.default_currency = staff_user_extension.defaultCurrency self.default_template_set = staff_user_extension.defaultTemplateSet self.last_modified_by = staff self.staff = staff self.save() return self
def work_report(request): try: human_resource = HumanResource.objects.filter(user=UserExtension.get_user_extension(request.user)) if len(human_resource) == 0: error_message = "User "+request.user.__str__()+" is not registered as human resource" raise UserIsNoHumanResource(error_message) if request.POST.get('post'): if 'cancel' in request.POST: return HttpResponseRedirect('/admin/') elif 'save' in request.POST: range_selection_form = RangeSelectionForm(request.POST) if range_selection_form.is_valid(): formset = BaseWorkEntryFormset.load_formset(range_selection_form, request) if not formset.is_valid(): c = {'range_selection_form': range_selection_form, 'formset': formset} c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) else: for form in formset: form.update_work(request) messages.success(request, _('you have successfully updated your work')) formset = BaseWorkEntryFormset.create_updated_formset(range_selection_form, human_resource) range_selection_form.update_from_input() c = {'range_selection_form': range_selection_form, 'formset': formset} c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) return HttpResponseRedirect('/admin/') else: datetime_now = datetime.datetime.today() to_date = (datetime_now + datetime.timedelta(days=30)).date() from_date = datetime_now.date() range_selection_form = RangeSelectionForm.create_range_selection_form(from_date, to_date) formset = BaseWorkEntryFormset.create_new_formset(from_date, to_date, human_resource) c = {'formset': formset, 'range_selection_form': range_selection_form} c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) except (UserExtensionMissing, ReportingPeriodNotFound, TooManyUserExtensionsAvailable, UserIsNoHumanResource) as e: if isinstance(e, UserExtensionMissing): return HttpResponseRedirect(e.view) elif isinstance(e, ReportingPeriodNotFound): return HttpResponseRedirect(e.view) elif isinstance(e, TooManyUserExtensionsAvailable): return HttpResponseRedirect(e.view) elif isinstance(e, UserIsNoHumanResource): return HttpResponseRedirect(e.view) else: raise Http404
def create_new_formset(from_date, to_date, request): WorkEntryFormSet = forms.formset_factory(WorkEntry, extra=1, max_num=60, can_delete=True, formset=BaseWorkEntryFormset) employee = UserExtension.get_user_extension(request.user) initial_formset_data = generate_initial_data(from_date, to_date, employee) form_kwargs = compose_form_kwargs(from_date, to_date) formset = WorkEntryFormSet(initial=initial_formset_data, form_kwargs=form_kwargs) return formset
def create_updated_formset(range_selection_form, request): WorkEntryFormSet = forms.formset_factory(WorkEntry, extra=1, max_num=60, can_delete=True, formset=BaseWorkEntryFormset) employee = UserExtension.get_user_extension(request.user) from_date = range_selection_form.cleaned_data['from_date'] to_date = range_selection_form.cleaned_data['to_date'] initial_formset_data = generate_initial_data(from_date, to_date, employee) form_kwargs = compose_form_kwargs(from_date, to_date) formset = WorkEntryFormSet(initial=initial_formset_data, form_kwargs=form_kwargs) return formset
def update_work(form, request): from koalixcrm.crm.reporting.work import Work if form.has_changed(): if form.cleaned_data['work_id']: work = Work.objects.get(id=form.cleaned_data['work_id']) else: work = Work() if form.cleaned_data['DELETE']: work.delete() else: work.task = form.cleaned_data['task'] work.employee = UserExtension.get_user_extension(request.user) work.date = form.cleaned_data['date'] work.start_time = datetime.datetime.combine( form.cleaned_data['date'], form.cleaned_data['start_time']) work.stop_time = datetime.datetime.combine( form.cleaned_data['date'], form.cleaned_data['stop_time']) work.description = form.cleaned_data['description'] work.save()
def serialize_to_xml(self): from koalixcrm.djangoUserExtension.models import UserExtension objects = [ self, ] objects += UserExtension.objects_to_serialize(self, self.project_manager) main_xml = PDFExport.write_xml(objects) for task in Task.objects.filter(project=self.id): task_xml = task.serialize_to_xml() main_xml = PDFExport.merge_xml(main_xml, task_xml) main_xml = PDFExport.append_element_to_pattern( main_xml, "object/[@model='crm.project']", "Effective_Effort", self.effective_effort()) main_xml = PDFExport.append_element_to_pattern( main_xml, "object/[@model='crm.project']", "Planned_Effort", self.planned_effort()) main_xml = PDFExport.append_element_to_pattern( main_xml, "object/[@model='crm.project']", "Effective_Duration", self.effective_duration()) main_xml = PDFExport.append_element_to_pattern( main_xml, "object/[@model='crm.project']", "Planned_Duration", self.planned_duration()) return main_xml
def work_report(request): try: human_resource = HumanResource.objects.filter( user=UserExtension.get_user_extension(request.user)) if len(human_resource) == 0: error_message = "User " + request.user.__str__( ) + " is not registered as human resource" raise UserIsNoHumanResource(error_message) if request.POST.get('post'): if 'cancel' in request.POST: return HttpResponseRedirect('/admin/') elif 'save' in request.POST: range_selection_form = RangeSelectionForm(request.POST) if range_selection_form.is_valid(): formset = BaseWorkEntryFormset.load_formset( range_selection_form, request) if not formset.is_valid(): c = { 'range_selection_form': range_selection_form, 'formset': formset } c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) else: for form in formset: form.update_work(request) messages.success( request, _('you have successfully updated your work')) formset = BaseWorkEntryFormset.create_updated_formset( range_selection_form, human_resource) range_selection_form.update_from_input() c = { 'range_selection_form': range_selection_form, 'formset': formset } c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) return HttpResponseRedirect('/admin/') else: datetime_now = datetime.datetime.today() to_date = (datetime_now + datetime.timedelta(days=30)).date() from_date = datetime_now.date() range_selection_form = RangeSelectionForm.create_range_selection_form( from_date, to_date) formset = BaseWorkEntryFormset.create_new_formset( from_date, to_date, human_resource) c = { 'formset': formset, 'range_selection_form': range_selection_form } c.update(csrf(request)) return render(request, 'crm/admin/time_reporting.html', c) except (UserExtensionMissing, ReportingPeriodNotFound, TooManyUserExtensionsAvailable, UserIsNoHumanResource) as e: if isinstance(e, UserExtensionMissing): return HttpResponseRedirect(e.view) elif isinstance(e, ReportingPeriodNotFound): return HttpResponseRedirect(e.view) elif isinstance(e, TooManyUserExtensionsAvailable): return HttpResponseRedirect(e.view) elif isinstance(e, UserIsNoHumanResource): return HttpResponseRedirect(e.view) else: raise Http404