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)
 def __init__(self, common_app_info: CommonData):
     super().__init__(common_app_info)
     self.product_type = ProductType.DAIRY
     self.base_name = "milk"
     self.contract_kids_no = DatabaseManager.get_contract(
         self.common_app_info.school_id,
         self.common_app_info.program_id).dairy_products
Example #3
0
    def create(self, contract_date=None):
        self.contract_date = DateConverter.to_date(contract_date, "%d.%m.%Y")

        contract = DatabaseManager.get_contract(self.school.id,
                                                self.program.id)
        if contract:
            self.contract_no = contract.contract_no
            self.contract_year = contract.contract_year

            app.logger.warning(
                "[%s] Contract already exists [%s, %s]. Only update contract date and regenerate",
                __class__.__name__, self.school.nick, self.program.id)
            contract.update(self.contract_date)
            self.generate()
        else:
            self.contract_no = str(
                DatabaseManager.get_next_contract_no(self.program.id))
            self.contract_year = DateConverter.get_year()

            app.logger.info(
                "[%s] Adding new contract: school_nick %s: city %s | current_date %s, | contract_no %s"
                "| contract_year %s", __class__.__name__, self.school.nick,
                self.school.city, self.contract_date, self.contract_no,
                self.contract_year)

            if self.create_new():
                self.generate()
            else:
                app.logger.error(
                    "[%s]  Something went wrong when creating a contract",
                    __class__.__name__)
 def __init__(self, common_app_info: CommonData):
     super().__init__(common_app_info)
     self.product_type = ProductType.FRUIT_VEG
     self.base_name = "fruitVeg"
     self.contract_kids_no = DatabaseManager.get_contract(
         self.common_app_info.school_id,
         self.common_app_info.program_id).fruitVeg_products
Example #5
0
def school_form_add_contract(school_id=INVALID_ID):
    if not session.get('program_id'):
        return redirect(url_for('program'))
    school = DatabaseManager.get_school(school_id)
    school_contract = DatabaseManager.get_contract(school_id, session.get('program_id'))
    if request.method == 'POST':
        date = DateConverter.to_date(request.form['contract_date'])
        fruitVeg_products = request.form['fruitVeg_products']
        dairy_products = request.form['dairy_products']

        if not school_contract:
            if not date:
                flash('Uzupełnij datę zawarcia umowy', 'error')
            else:
                new_contract = ContractCreator(school, session.get('program_id'))
                new_contract.create(date)
                return redirect(url_for('school_form', school_id=school_id))

        if school_contract:
            school_contract.update(date, date, fruitVeg_products, dairy_products)
            return redirect(url_for('school_form', school_id=school_id))
    return render_template("add_contract_form.html", school=school, contract=school_contract)