コード例 #1
0
    def __init__(self, school_id, program_id, existing_annex: Contract = None):
        self.program_id = program_id
        self.program = DatabaseManager.get_program(program_id)
        self.school = DatabaseManager.get_school(school_id)
        if not existing_annex:
            self.contract = DatabaseManager.get_contract(
                school_id, self.program_id)
            self.contract_no = "{0}_{1}".format(
                self.contract.contract_no,
                DatabaseManager.get_next_annex_no(school_id, self.program_id))
            self.contract_year = self.contract.contract_year
            self.contract_date = None
            self.validity_date = None
            self.fruitVeg_products = None
            self.dairy_products = None
        else:
            self.contract = existing_annex
            self.contract_no = existing_annex.contract_no
            self.contract_year = existing_annex.contract_year
            self.contract_date = existing_annex.contract_date
            self.validity_date = existing_annex.validity_date
            self.fruitVeg_products = existing_annex.fruitVeg_products
            self.dairy_products = existing_annex.dairy_products

        output_directory = self.school.generate_directory_name(
            config_parser.get('Directories', 'annex'))
        DocumentCreator.__init__(self,
                                 config_parser.get('DocTemplates', 'annex'),
                                 output_directory)
        DatabaseManager.__init__(self)
コード例 #2
0
    def _generate_5a(self):
        DocumentCreator.__init__(self, self.template_document_va,
                                 self.output_directory)

        self.document.merge_rows('date_vegFruit',
                                 self.records_to_merge_vegFruit)
        self.document.merge_rows('date_milk', self.records_to_merge_milk)
        data_to_merge = dict()
        data_to_merge.update(self.default_data.get())
        data_to_merge['weeks'] = DatabaseManager.str_from_weeks(
            DatabaseManager.get_weeks(self.program_id), self.summary.weeks)
        data_to_merge['sum_vegFruit'] = str(self.sum_product_vegFruit)
        data_to_merge['sum_kids_vegFruit'] = str(self.sum_product_vegFruit)
        data_to_merge['sum_milk'] = str(self.sum_product_milk)
        data_to_merge['sum_kids_milk'] = str(self.sum_product_milk)

        self.document.merge(**data_to_merge)

        doc_5a_name = "Ewidencja_VA_Wniosek_{}_{}.docx".format(
            self.summary.no, self.summary.year)
        doc_5a_name_copy = path.join(
            self.main_app_dir,
            "{0}_EwidencjaVa_{1}_{2}.docx".format(self.school.nick,
                                                  self.summary.no,
                                                  self.summary.year))
        DocumentCreator.generate(self, doc_5a_name, False)
        if path.exists(doc_5a_name_copy):
            remove(doc_5a_name_copy)
        copyfile(path.join(self.output_directory, doc_5a_name),
                 doc_5a_name_copy)
コード例 #3
0
 def generate(self, new_doc_name, gen_pdf=True):
     self._prepare_school_data()
     self.document.merge_rows('no', self.records_to_merge)
     self.document.merge(semester_no=self.program_semester,
                         school_year=self.year,
                         date=self.date)
     DocumentCreator.generate(self, new_doc_name, False)
     generated_file = path.join(self.output_directory, new_doc_name)
     RegisterCreator._merge_cells(generated_file,
                                  RegisterCreator.CELL_TO_MERGE_MARK)
     DocumentCreator.generate_pdf(generated_file, self.output_directory)
コード例 #4
0
 def __init__(self, program_id):
     self.date = datetime.today().strftime('%d-%m-%Y')
     self.program = DatabaseManager.get_program(program_id)
     self.contracts = DatabaseManager.get_contracts(program_id)
     self.program_semester = self.program.get_current_semester()
     self.year = self.program.school_year
     self.records_to_merge = []
     output_directory = config_parser.get('Directories', 'current_program')
     DocumentCreator.__init__(self,
                              config_parser.get('DocTemplates', 'register'),
                              output_directory)
コード例 #5
0
 def __init__(self, program_id, weeks: Set[int], no=None):
     self.summary: Summary = None
     self.program_id = program_id
     self.weeks = weeks
     if no:
         self.summary = DatabaseManager.get_summary(self.program_id, no)
         self.summary.weeks = weeks
         DatabaseManager.modify()
     self.school_no = 0
     output_directory = config_parser.get('Directories', 'current_program')
     DocumentCreator.__init__(self, config_parser.get('DocTemplates', 'summary'), output_directory)
     DatabaseManager.__init__(self)
コード例 #6
0
 def generate(self):
     self.document.merge(city=self.doc_data['city'],
                         current_date=self.doc_data['current_date'],
                         name=self.doc_data['name'],
                         address=self.doc_data['address'],
                         nip=self.doc_data['nip'],
                         regon=self.doc_data['regon'],
                         email=self.doc_data['email'],
                         kids_no=self.doc_data['kids_no'],
                         product_name=self.doc_data['product_name'],
                         record_title=self.doc_data['record_title'])
     DocumentCreator.generate(self,
                              "WZ_{0}_{1}.docx".format(
                                  DateConverter.to_string(self.date),
                                  self.product.get_type_mapping()),
                              gen_pdf=True)
コード例 #7
0
    def generate_many(records_to_merge, file_prefix=None):
        if not records_to_merge:
            return

        out_dir = config_parser.get('Directories', 'record_all')
        doc = DocumentCreator.start_doc_gen(
            config_parser.get('DocTemplates', 'record'), out_dir)
        records_to_merge_list = [
            record.doc_data for record in records_to_merge
            if (isinstance(record, RecordCreator) and record.doc_data)
        ]
        if not records_to_merge_list:
            return

        date = records_to_merge[0].date
        if not isinstance(date, datetime.date):
            date = DateConverter.to_date(date)

        gen_date = records_to_merge[0].generation_date
        if not isinstance(gen_date, datetime.date):
            gen_date = DateConverter.to_date(gen_date)

        assert (gen_date and date)  # @TODO remove later
        if not gen_date or not date:
            return

        out_dir = path.join(out_dir,
                            DateConverter.to_string(gen_date, '%Y_%m_%d'),
                            DateConverter.to_string(date))
        if not path.exists(out_dir):
            makedirs(out_dir)

        out_file_name = ALL_RECORDS_DOC_NAME
        if file_prefix and file_prefix != ALL_RECORDS_DOC_NAME:
            counter = 1
            for filename in listdir(out_dir):
                if file_prefix in filename:
                    counter += 1
            out_file_name = "{}_{}{}".format(out_file_name, file_prefix,
                                             counter)

        out_doc = path.join(out_dir, "{}.docx".format(out_file_name))
        doc.merge_pages(records_to_merge_list)
        app.logger.info("[%s] Created merge docx of records in dir: [%s]",
                        RecordCreator.__qualname__, out_doc)
        DocumentCreator.end_doc_gen(doc, out_doc, out_dir, gen_pdf=True)
コード例 #8
0
    def __init__(self, school, program_id, ommit_representat=True):
        self.main_contract_dir = config_parser.get('Directories',
                                                   'contract_all')
        if not path.exists(self.main_contract_dir):
            makedirs(self.main_contract_dir)

        self.program = DatabaseManager.get_program(program_id)
        self.school = school
        self.contract_no = None
        self.contract_year = None
        self.contract_date = None
        self.ommit_representat = ommit_representat
        output_directory = self.school.generate_directory_name(
            config_parser.get('Directories', 'contract'))
        DocumentCreator.__init__(self,
                                 config_parser.get('DocTemplates', 'contract'),
                                 output_directory)
        DatabaseManager.__init__(self)
コード例 #9
0
    def generate(self):
        self.document.merge(
            city=self.school.city,
            date=DateConverter.to_string(self.contract_date, "%d.%m.%Y"),
            no=str(self.contract_no),
            year=str(self.contract_year),
            semester=self.program.get_current_semester(),
            name=self.school.name,
            address=self.school.address,
            nip=self.school.nip,
            regon=self.school.regon,
            representant=self.school.responsible_person
            if not self.ommit_representat else FILL_BY_SCHOOL,
            email=self.school.email,
            program_start_date=DateConverter.to_string(self.program.start_date,
                                                       "%d.%m.%Y"),
            program_end_date=DateConverter.to_string(self.program.end_date,
                                                     "%d.%m.%Y"),
            nip_additional=self.school.representative_nip
            if self.school.representative_nip else "-",
            name_additional=self.school.representative
            if self.school.representative else "-",
            regon_additional=self.school.representative_regon
            if self.school.representative_regon else "-",
            giving_weeks=ContractCreator._preapre_str_from_weeks(
                DatabaseManager.get_weeks(self.program.id)))
        doc_contract_name = "Umowa_{0}_{1}.docx".format(
            self.contract_no, self.contract_year)
        created_doc_name = DocumentCreator.generate(self, doc_contract_name)

        doc_contract_name_copy = path.join(
            self.main_contract_dir,
            "{0}_Umowa_{1}_{2}.docx".format(self.school.nick, self.contract_no,
                                            self.contract_year))

        try:
            DocumentCreator.copy_to_path(created_doc_name,
                                         doc_contract_name_copy)
            # DocumentCreator.copy_to_path(created_doc_name.replace("docx", "pdf"), doc_contract_name_copy.replace("docx", "pdf")) #TODO problem with generating pdf numbering is wrong
        except:
            app.logger.error("Could not copy files [%s]", created_doc_name)
コード例 #10
0
    def _generate_5(self):
        DocumentCreator.__init__(self, self.template_document_v,
                                 self.output_directory)
        data_to_merge = dict()
        data_to_merge['application_no'] = self.summary.get_application_no()

        data_to_merge.update({
            k: ApplicationCreator.convert_to_str(v)
            for k, v in self.default_data.get().items()
        })
        data_to_merge.update({
            k: ApplicationCreator.convert_to_str(v)
            for k, v in self.common_data.get().items()
        })
        data_to_merge.update({
            k: ApplicationCreator.convert_to_str(v)
            for k, v in self.frutiVeg.get().items()
        })
        data_to_merge.update({
            k: ApplicationCreator.convert_to_str(v)
            for k, v in self.dairySummary.get().items()
        })
        data_to_merge.update({
            k: ApplicationCreator.convert_to_str(v)
            for k, v in self.product_data.items()
        })

        self.document.merge(**data_to_merge)

        doc_5_name = "Oswiadczenie_V_Wniosek_{}_{}.docx".format(
            self.summary.no, self.summary.year)
        doc_5_name_copy = path.join(
            self.main_app_dir,
            "{0}_OswiadczenieV_{1}_{2}.docx".format(self.school.nick,
                                                    self.summary.no,
                                                    self.summary.year))
        DocumentCreator.generate(self, doc_5_name, False)
        if path.exists(doc_5_name_copy):
            remove(doc_5_name_copy)
        copyfile(path.join(self.output_directory, doc_5_name), doc_5_name_copy)
コード例 #11
0
 def generate(self):
     self.document.merge(
         city=self.school.city,
         current_date=self.contract_date.strftime("%d.%m.%Y"),
         contract_no=str(self.contract_no.split("_")[0]),
         contract_year=str(self.contract_year),
         semester_no=self.program.get_current_semester(),
         school_year=self.program.school_year,
         name=self.school.name,
         address=self.school.address,
         nip=self.school.nip,
         regon=self.school.regon,
         responsible_person=self.school.responsible_person,
         fruitveg_products=str(self.fruitVeg_products),
         dairy_products=str(self.dairy_products),
         validity_date=self.validity_date.strftime("%d.%m.%Y"))
     created_annex = DocumentCreator.generate(
         self, "Aneks_" + self.contract_date.strftime("%d_%m_%Y") + ".docx")
     new_annex_dst = path.join(
         config_parser.get('Directories', 'annex_all'),
         "{0}_Aneks_{1}_{2}.docx".format(self.school.nick, self.contract_no,
                                         self.contract_year))
     DocumentCreator.copy_to_path(created_annex, new_annex_dst)
コード例 #12
0
 def __init__(self,
              program_id,
              current_date,
              school_id,
              product_id,
              generation_date=""):
     self.program_id = program_id
     self.date = DateConverter.to_date(current_date,
                                       pattern=DATABASE_DATE_PATTERN)
     self.state = RecordState.NOT_DELIVERED
     self.contract = DatabaseManager.get_current_contract(
         school_id, self.program_id, self.date)
     self.product = DatabaseManager.get_product(product_id)
     self.doc_data = dict()
     self.generation_date = DateConverter.to_date(
         generation_date) if generation_date else datetime.date.today()
     output_directory = self.contract.school.generate_directory_name(
         config_parser.get('Directories', 'record'))
     DocumentCreator.__init__(self,
                              config_parser.get('DocTemplates', 'record'),
                              output_directory)
     DatabaseManager.__init__(self)
     self._prepare_data_for_doc()
コード例 #13
0
def test_pdf_is_properly_created():
    DocumentCreator.generate_pdf('helper_files\\aneks_test.docx', 'helper_files')
    assert (path.exists('helper_files\\aneks_test.pdf'))
コード例 #14
0
    def generate(self):
        if not self.summary:
            app.logger.error("Summary does not exists")
            return

        if not self.__base_check():
            app.logger.error("Summary Base Check failed")
            return

        assert(int(self.summary.get_veg_income() + self.summary.get_fruit_income()) == int(self.summary.get_fruit_veg_income()))
        #TODO refactor based on idea in Application Creator
        self.document.merge(
                application_no=self.summary.get_application_no(),
                city="Zielona Góra",
                wn=str(self.summary.number_of_weeks),
                kids_no_fruitVeg=str(self.summary.kids_no),
                kids_no_milk=str(self.summary.kids_no_milk),
                weeks=DatabaseManager.str_from_weeks(DatabaseManager.get_weeks(self.program_id), self.summary.weeks),
                apple=str(self.summary.get_from_fruit_list(ProductName.APPLE).amount),
                applewn=str(self.summary.get_from_fruit_list(ProductName.APPLE).calculate_netto()),
                applevat=str(self.summary.get_from_fruit_list(ProductName.APPLE).calculate_vat()),
                applewb=str(self.summary.get_from_fruit_list(ProductName.APPLE).calculate_brutto()),
                plum=str(self.summary.get_from_fruit_list(ProductName.PLUM).amount),
                plumwn=str(self.summary.get_from_fruit_list(ProductName.PLUM).calculate_netto()),
                plumvat=str(self.summary.get_from_fruit_list(ProductName.PLUM).calculate_vat()),
                plumwb=str(self.summary.get_from_fruit_list(ProductName.PLUM).calculate_brutto()),
                pear=str(self.summary.get_from_fruit_list(ProductName.PEAR).amount),
                pearwn=str(self.summary.get_from_fruit_list(ProductName.PEAR).calculate_netto()),
                pearvat=str(self.summary.get_from_fruit_list(ProductName.PEAR).calculate_vat()),
                pearwb=str(self.summary.get_from_fruit_list(ProductName.PEAR).calculate_brutto()),
                strawberry=str(self.summary.get_from_fruit_list(ProductName.STRAWBERRY).amount),
                strawberrywn=str(self.summary.get_from_fruit_list(ProductName.STRAWBERRY).calculate_netto()),
                strawberryvat=str(self.summary.get_from_fruit_list(ProductName.STRAWBERRY).calculate_vat()),
                strawberrywb=str(self.summary.get_from_fruit_list(ProductName.STRAWBERRY).calculate_brutto()),
                juice=str(self.summary.get_from_fruit_list(ProductName.JUICE).amount),
                juicewn=str(self.summary.get_from_fruit_list(ProductName.JUICE).calculate_netto()),
                juicevat=str(self.summary.get_from_fruit_list(ProductName.JUICE).calculate_vat()),
                juicewb=str(self.summary.get_from_fruit_list(ProductName.JUICE).calculate_brutto()),
                fruitall=str(self.summary.get_fruit_amount()),
                fruitalln="{0:.2f}".format(self.summary.get_fruit_netto()),
                fruitallvat="{0:.2f}".format(self.summary.get_fruit_vat()),
                fruitallwb="{0:.2f}".format(self.summary.get_fruit_income()),
                carrot=str(self.summary.get_from_fruit_list(ProductName.CARROT).amount),
                carrotwn=str(self.summary.get_from_fruit_list(ProductName.CARROT).calculate_netto()),
                carrotvat=str(self.summary.get_from_fruit_list(ProductName.CARROT).calculate_vat()),
                carrotwb=str(self.summary.get_from_fruit_list(ProductName.CARROT).calculate_brutto()),
                tomato=str(self.summary.get_from_fruit_list(ProductName.TOMATO).amount),
                tomatown=str(self.summary.get_from_fruit_list(ProductName.TOMATO).calculate_netto()),
                tomatovat=str(self.summary.get_from_fruit_list(ProductName.TOMATO).calculate_vat()),
                tomatowb=str(self.summary.get_from_fruit_list(ProductName.TOMATO).calculate_brutto()),
                pepper=str(self.summary.get_from_fruit_list(ProductName.PEPPER).amount),
                pepperwn=str(self.summary.get_from_fruit_list(ProductName.PEPPER).calculate_netto()),
                peppervat=str(self.summary.get_from_fruit_list(ProductName.PEPPER).calculate_vat()),
                pepperwb=str(self.summary.get_from_fruit_list(ProductName.PEPPER).calculate_brutto()),
                radish=str(self.summary.get_from_fruit_list(ProductName.RADISH).amount),
                radishwn=str(self.summary.get_from_fruit_list(ProductName.RADISH).calculate_netto()),
                radishvat=str(self.summary.get_from_fruit_list(ProductName.RADISH).calculate_vat()),
                radishwb=str(self.summary.get_from_fruit_list(ProductName.RADISH).calculate_brutto()),
                kohlrabi=str(self.summary.get_from_fruit_list(ProductName.KOHLRABI).amount),
                kohlrabiwn=str(self.summary.get_from_fruit_list(ProductName.KOHLRABI).calculate_netto()),
                kohlrabivat=str(self.summary.get_from_fruit_list(ProductName.KOHLRABI).calculate_vat()),
                kohlrabiwb=str(self.summary.get_from_fruit_list(ProductName.KOHLRABI).calculate_brutto()),
                veg_all=str(self.summary.get_veg_amount()),
                veg_alln="{0:.2f}".format(self.summary.get_veg_netto()),
                veg_allvat="{0:.2f}".format(self.summary.get_veg_vat()),
                veg_allwb="{0:.2f}".format(self.summary.get_veg_income()),

                fruitVeg_income="{0:.2f}".format(self.summary.fruitVeg_income),

                milk=str(self.summary.get_from_diary_list(ProductName.MILK).amount),
                milkwn=str(self.summary.get_from_diary_list(ProductName.MILK).calculate_netto()),
                milkvat=str(self.summary.get_from_diary_list(ProductName.MILK).calculate_vat()),
                milkwb=str(self.summary.get_from_diary_list(ProductName.MILK).calculate_brutto()),
                yoghurt=str(self.summary.get_from_diary_list(ProductName.YOGHURT).amount),
                yoghurtwn=str(self.summary.get_from_diary_list(ProductName.YOGHURT).calculate_netto()),
                yoghurtvat=str(self.summary.get_from_diary_list(ProductName.YOGHURT).calculate_vat()),
                yoghurtwb=str(self.summary.get_from_diary_list(ProductName.YOGHURT).calculate_brutto()),
                kefir=str(self.summary.get_from_diary_list(ProductName.KEFIR).amount),
                kefirwn=str(self.summary.get_from_diary_list(ProductName.KEFIR).calculate_netto()),
                kefirvat=str(self.summary.get_from_diary_list(ProductName.KEFIR).calculate_vat()),
                kefirwb=str(self.summary.get_from_diary_list(ProductName.KEFIR).calculate_brutto()),
                cheese=str(self.summary.get_from_diary_list(ProductName.CHEESE).amount),
                cheesewn=str(self.summary.get_from_diary_list(ProductName.CHEESE).calculate_netto()),
                cheesevat=str(self.summary.get_from_diary_list(ProductName.CHEESE).calculate_vat()),
                cheesewb=str(self.summary.get_from_diary_list(ProductName.CHEESE).calculate_brutto()),

                dairy_all=str(self.summary.get_dairy_amount()),
                dairy_wn="{0:.2f}".format(self.summary.get_dairy_netto()),
                dairy_vat="{0:.2f}".format(self.summary.get_dairy_vat()),
                dairy_wb="{0:.2f}".format(self.summary.get_dairy_income()),
                dairy_income="{0:.2f}".format(self.summary.milk_income),

                school_no_fruitVeg=str(self.summary.school_no),
                school_no_milk=str(self.summary.school_no_milk),
                app_school_no=str(self.school_no)
        )
        DocumentCreator.generate(self, f"Wniosek_{self.summary.no}.docx", False)