Beispiel #1
0
 def serialize_to_xml(self):
     objects = [
         self,
     ]
     main_xml = PDFExport.write_xml(objects)
     project_xml = self.project.serialize_to_xml(reporting_period=self)
     main_xml = PDFExport.merge_xml(main_xml, project_xml)
     return main_xml
Beispiel #2
0
 def serialize_to_xml(self, **kwargs):
     date_from = kwargs.get('date_from', datetime.date.today()-datetime.timedelta(days=60))
     date_to = kwargs.get('date_to', datetime.date.today())
     objects = [self, ]
     main_xml = PDFExport.write_xml(objects)
     date = date_from
     days = dict()
     weeks = dict()
     months = dict()
     while date < date_to:
         days[date] = 0
         month_key = str(date.month)+"/"+str(date.year)
         week_key = str(date.isocalendar()[1])+"/"+str(date.year)
         if not (week_key in weeks):
             weeks[week_key] = 0
         if not (month_key in months):
             months[month_key] = 0
         date += datetime.timedelta(days=1)
     works = Work.objects.filter(employee=self, date__range=(date_from, date_to))
     for work in works:
         days[work.date] += work.effort_hours()
         month_key = str(work.date.month)+"/"+str(work.date.year)
         week_key = str(work.date.isocalendar()[1])+"/"+str(work.date.year)
         weeks[week_key] += work.effort_hours()
         months[month_key] += work.effort_hours()
     for day_key in days.keys():
         main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                        "object/[@model='djangoUserExtension.userextension']",
                                                        "Day_Work_Hours",
                                                        str(days[day_key]),
                                                        attributes={"day": str(day_key.day),
                                                                    "week": str(day_key.isocalendar()[1]),
                                                                    "week_day": str(day_key.isoweekday()),
                                                                    "month": str(day_key.month),
                                                                    "year": str(day_key.year)})
     for week_key in weeks.keys():
         main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                        "object/[@model='djangoUserExtension.userextension']",
                                                        "Week_Work_Hours",
                                                        str(weeks[week_key]),
                                                        attributes={"week": str(week_key)})
     for month_key in months.keys():
         main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                        "object/[@model='djangoUserExtension.userextension']",
                                                        "Month_Work_Hours",
                                                        str(months[month_key]),
                                                        attributes={"week": str(month_key)})
     return main_xml
Beispiel #3
0
 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
Beispiel #4
0
 def serialize_to_xml(self, reporting_period):
     objects = [self, ]
     main_xml = PDFExport.write_xml(objects)
     if reporting_period:
         works = koalixcrm.crm.reporting.work.Work.objects.filter(task=self.id,
                                                                  reporting_period=reporting_period)
     else:
         works = koalixcrm.crm.reporting.work.Work.objects.filter(task=self.id)
     for work in works:
         work_xml = work.serialize_to_xml()
         main_xml = PDFExport.merge_xml(main_xml, work_xml)
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Effective_Effort_Overall",
                                                    self.effective_effort(reporting_period=None))
     if reporting_period:
         main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                        "object/[@model='crm.task']",
                                                        "Effective_Effort_InPeriod",
                                                        self.effective_effort(reporting_period=reporting_period))
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Planned_Effort",
                                                    self.planned_effort())
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Effective_Duration",
                                                    self.effective_duration())
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Planned_Duration",
                                                    self.planned_duration())
     return main_xml
Beispiel #5
0
 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_effort(reporting_period=None))
     if reporting_period:
         main_xml = PDFExport.append_element_to_pattern(
             main_xml, "object/[@model='crm.project']",
             "Effective_Effort_InPeriod",
             self.effective_effort(reporting_period=reporting_period))
     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
Beispiel #6
0
 def serialize_to_xml(self, accounting_period):
     objects = [
         self,
     ]
     main_xml = PDFExport.write_xml(objects)
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.account']",
         "sum_of_all_bookings_within_accounting_period",
         self.sum_of_all_bookings_within_accounting_period(
             accounting_period))
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.account']",
         "sum_of_all_bookings_through_now",
         self.sum_of_all_bookings_through_now(accounting_period))
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.account']",
         "sum_of_all_bookings_before_accounting_period",
         self.sum_of_all_bookings_before_accounting_period(
             accounting_period))
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.account']",
         "sum_of_all_bookings_through_now", self.sum_of_all_bookings())
     return main_xml
 def test_serialize_to_xml(self):
     accounting_period_2025 = AccountingPeriod.objects.get(title="Fiscal year 2025")
     xml = accounting_period_2025.serialize_to_xml()
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']", 'Earnings')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']", 'Spendings')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']", 'Investment capital')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']", 'Shortterm bankloans')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']",'Cash')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.account']/field[@name='title']",'Bank Account')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.accountingperiod']/Overall_Spendings", '1000.00')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.accountingperiod']/Overall_Earnings", '500.00')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.accountingperiod']/Overall_Assets", '494500.00')
     self.assertEqual(result, 1)
     result=PDFExport.find_element_in_xml(xml,"object/[@model='accounting.accountingperiod']/Overall_Liabilities", '495000.00')
     self.assertEqual(result, 1)
Beispiel #8
0
 def serialize_to_xml(self):
     objects = [
         self,
     ]
     main_xml = PDFExport.write_xml(objects)
     accounts = Account.objects.all()
     for account in accounts:
         account_xml = account.serialize_to_xml(self)
         main_xml = PDFExport.merge_xml(main_xml, account_xml)
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.accountingperiod']",
         "Overall_Earnings", self.overall_earnings())
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.accountingperiod']",
         "Overall_Spendings", self.overall_spendings())
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.accountingperiod']",
         "Overall_Assets", self.overall_assets())
     main_xml = PDFExport.append_element_to_pattern(
         main_xml, "object/[@model='accounting.accountingperiod']",
         "Overall_Liabilities", self.overall_liabilities())
     return main_xml
Beispiel #9
0
 def serialize_to_xml(self):
     objects = [self, ]
     main_xml = PDFExport.write_xml(objects)
     for work in koalixcrm.crm.reporting.work.Work.objects.filter(task=self.id):
         work_xml = work.serialize_to_xml()
         main_xml = PDFExport.merge_xml(main_xml, work_xml)
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Effective_Effort",
                                                    self.effective_effort())
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Planned_Effort",
                                                    self.planned_effort())
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Effective_Duration",
                                                    self.effective_duration())
     main_xml = PDFExport.append_element_to_pattern(main_xml,
                                                    "object/[@model='crm.task']",
                                                    "Planned_Duration",
                                                    self.planned_duration())
     return main_xml
Beispiel #10
0
 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
Beispiel #11
0
 def create_pdf(self, template_set, printed_by):
     self.last_print_date = datetime.now()
     self.save()
     return PDFExport.create_pdf(self, template_set, printed_by)
Beispiel #12
0
 def serialize_to_xml(self):
     objects = [
         self,
     ]
     main_xml = PDFExport.write_xml(objects)
     return main_xml
Beispiel #13
0
 def create_pdf(self, template_set, printed_by):
     return PDFExport.create_pdf(self, template_set, printed_by)
Beispiel #14
0
 def serialize_to_xml(self, **kwargs):
     date_from = kwargs.get(
         'date_from',
         datetime.date.today() - datetime.timedelta(days=60))
     date_to = kwargs.get('date_to', datetime.date.today())
     date_first_of_the_month = date_from.replace(day=1)
     date_to_month = date_to.month
     date_end_of_the_month = date_from.replace(day=1).replace(
         month=date_to_month + 1) - datetime.timedelta(days=1)
     date = date_first_of_the_month
     days = dict()
     weeks = dict()
     months = dict()
     projects = self.user_contribution_project(date_from, date_to)
     objects = [self, self.user]
     objects.extend(projects)
     main_xml = PDFExport.write_xml(objects)
     while date < date_from:
         project_efforts = dict()
         for project in projects:
             project_efforts[project] = {
                 'effort': "-",
                 'project': project.id.__str__()
             }
         days[date] = {
             'effort': "-",
             "day": str(date.day),
             "week": str(date.isocalendar()[1]),
             "week_day": str(date.isoweekday()),
             "month": str(date.month),
             "year": str(date.year),
             "project_efforts": project_efforts
         }
         date += datetime.timedelta(days=1)
     while date <= date_to:
         project_efforts_day = dict()
         project_efforts_week = dict()
         project_efforts_month = dict()
         for project in projects:
             project_efforts_day[project] = {
                 'effort': 0,
                 'project': project.id.__str__()
             }
             project_efforts_week[project] = {
                 'effort': 0,
                 'project': project.id.__str__()
             }
             project_efforts_month[project] = {
                 'effort': 0,
                 'project': project.id.__str__()
             }
         days[date] = {
             'effort': 0,
             "day": str(date.day),
             "week": str(date.isocalendar()[1]),
             "week_day": str(date.isoweekday()),
             "month": str(date.month),
             "year": str(date.year),
             "project_efforts": project_efforts_day
         }
         month_key = str(date.month) + "/" + str(date.year)
         week_key = str(date.isocalendar()[1]) + "/" + str(date.year)
         if not (week_key in weeks):
             weeks[week_key] = {
                 'effort': 0,
                 'week': str(date.isocalendar()[1]),
                 'year': str(date.year),
                 "project_efforts": project_efforts_week
             }
         if not (month_key in months):
             months[month_key] = {
                 'effort': 0,
                 'month': str(date.month),
                 'year': str(date.year),
                 "project_efforts": project_efforts_month
             }
         date += datetime.timedelta(days=1)
     while date < date_end_of_the_month:
         project_efforts = dict()
         for project in projects:
             project_efforts[project] = {
                 'effort': "-",
                 'project': project.id.__str__()
             }
         days[date] = {
             'effort': "-",
             "day": str(date.day),
             "week": str(date.isocalendar()[1]),
             "week_day": str(date.isoweekday()),
             "month": str(date.month),
             "year": str(date.year),
             "project_efforts": project_efforts
         }
         date += datetime.timedelta(days=1)
     main_xml = PDFExport.append_element_to_pattern(
         main_xml,
         ".",
         "range_from",
         date_from.__str__(),
         attributes={
             "day": str(date_from.day),
             "week": str(date_from.isocalendar()[1]),
             "week_day": str(date_from.isoweekday()),
             "month": str(date_from.month),
             "year": str(date_from.year)
         })
     main_xml = PDFExport.append_element_to_pattern(
         main_xml,
         ".",
         "range_to",
         date_to.__str__(),
         attributes={
             "day": str(date_to.day),
             "week": str(date_to.isocalendar()[1]),
             "week_day": str(date_to.isoweekday()),
             "month": str(date_to.month),
             "year": str(date_to.year)
         })
     works = Work.objects.filter(employee=self,
                                 date__range=(date_from, date_to))
     for work in works:
         days[work.date]['effort'] += work.effort_hours()
         days[work.date]['project_efforts'][
             work.task.project]['effort'] += work.effort_hours()
         month_key = str(work.date.month) + "/" + str(work.date.year)
         week_key = str(work.date.isocalendar()[1]) + "/" + str(
             work.date.year)
         weeks[week_key]['effort'] += work.effort_hours()
         weeks[week_key]['project_efforts'][
             work.task.project]['effort'] += work.effort_hours()
         months[month_key]['effort'] += work.effort_hours()
         months[month_key]['project_efforts'][
             work.task.project]['effort'] += work.effort_hours()
         work_xml = work.serialize_to_xml()
         main_xml = PDFExport.merge_xml(main_xml, work_xml)
     for day_key in days.keys():
         main_xml = PDFExport.append_element_to_pattern(
             main_xml,
             "object/[@model='djangoUserExtension.userextension']",
             "Day_Work_Hours",
             str(days[day_key]['effort']),
             attributes={
                 "day": days[day_key]['day'],
                 "week": days[day_key]['week'],
                 "week_day": days[day_key]['week_day'],
                 "month": days[day_key]['month'],
                 "year": days[day_key]['year']
             })
         for project_key in days[day_key]['project_efforts'].keys():
             main_xml = PDFExport.append_element_to_pattern(
                 main_xml,
                 "object/[@model='djangoUserExtension.userextension']",
                 "Day_Project_Work_Hours",
                 str(days[day_key]['project_efforts'][project_key]
                     ['effort']),
                 attributes={
                     "day":
                     days[day_key]['day'],
                     "week":
                     days[day_key]['week'],
                     "week_day":
                     days[day_key]['week_day'],
                     "month":
                     days[day_key]['month'],
                     "year":
                     days[day_key]['year'],
                     "project":
                     days[day_key]['project_efforts'][project_key]
                     ['project']
                 })
     for week_key in weeks.keys():
         main_xml = PDFExport.append_element_to_pattern(
             main_xml,
             "object/[@model='djangoUserExtension.userextension']",
             "Week_Work_Hours",
             str(weeks[week_key]['effort']),
             attributes={
                 "week": weeks[week_key]['week'],
                 "year": weeks[week_key]['year']
             })
         for project_key in weeks[week_key]['project_efforts'].keys():
             main_xml = PDFExport.append_element_to_pattern(
                 main_xml,
                 "object/[@model='djangoUserExtension.userextension']",
                 "Week_Project_Work_Hours",
                 str(weeks[week_key]['project_efforts'][project_key]
                     ['effort']),
                 attributes={
                     "week":
                     weeks[week_key]['week'],
                     "year":
                     weeks[week_key]['year'],
                     "project":
                     weeks[week_key]['project_efforts'][project_key]
                     ['project']
                 })
     for month_key in months.keys():
         main_xml = PDFExport.append_element_to_pattern(
             main_xml,
             "object/[@model='djangoUserExtension.userextension']",
             "Month_Work_Hours",
             str(months[month_key]['effort']),
             attributes={
                 "month": months[month_key]['month'],
                 "year": months[month_key]['year']
             })
         for project_key in months[month_key]['project_efforts'].keys():
             main_xml = PDFExport.append_element_to_pattern(
                 main_xml,
                 "object/[@model='djangoUserExtension.userextension']",
                 "Month_Project_Work_Hours",
                 str(months[month_key]['project_efforts'][project_key]
                     ['effort']),
                 attributes={
                     "month":
                     months[month_key]['month'],
                     "year":
                     months[month_key]['year'],
                     "project":
                     months[month_key]['project_efforts'][project_key]
                     ['project']
                 })
     return main_xml
Beispiel #15
0
 def create_pdf(self, template_set, printed_by, *args, **kwargs):
     return PDFExport.create_pdf(self, template_set, printed_by, *args,
                                 **kwargs)