コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
1521 ビュー


I have website form to make visitor can register  there CV , 

and I want to make him apple to add unlimited qualification. 

I make the module in the back-end and it work fine but how to make this in the website form ?


 

アバター
破棄
最善の回答

Hi

In this case, you need to inherit the website form controller

class WebsiteFormInherit(WebsiteForm):
    def _handle_website_form(self, model_name, **kwargs):
        """Handle the form submission to generate form"""
        values = super()._handle_website_form(model_name)
        if model_name == 'your_model_name':
        //You can ad dyour custom model here
            id_value = json.loads(values)['id']
            document = request.env['model_name'].browse(id_value)
            keys_to_remove = ['name', 'phone', 'email', 'partner_name', 'subject',
                              'description', 'csrf_token']
            kwargs = {k: v for k, v in kwargs.items() if k not in keys_to_remove}
            form_data = list(kwargs.items())

            file_data = [(k, v) for k, v in form_data if "            other_data = [(k, v) for k, v in form_data if
                          "            web_form_attachments = request.env['ir.attachment'].search(
                [('res_model', '=', 'model_name'), ('res_id', '=', document.id)
                 ])
            image_attachments = [attachment for attachment in web_form_attachments
                                 if attachment.mimetype.startswith('image/')]

            # Generate the PDF report
            report_pdf, _ = request.env.ref(
                'website_form_pdf.action_report_pdf_document').with_context(
                data='form_pdfdata').sudo()._render_qweb_pdf(
                data={'data_values': other_data, 'data_length': len(other_data),
                      'record_id': document.id, 'attach': image_attachments})
            #
            # Create a PdfFileReader instance for the report PDF
            report_reader = PyPDF2.PdfFileReader(io.BytesIO(report_pdf))

            # Create a PdfFileMerger instance
            merger = PyPDF2.PdfFileMerger()

            # Append the report PDF to the merger
            merger.append(report_reader, import_bookmarks=False)

            # Append the existing attachments to the merger
            for attachment in web_form_attachments:
                if attachment.mimetype == 'application/pdf':
                    attachment_reader = PyPDF2.PdfFileReader(
                        io.BytesIO(base64.b64decode(attachment.datas)))
                    merger.append(attachment_reader)
            # Write the merged PDF to the output stream
            output_stream = io.BytesIO()
            merger.write(output_stream)
            merger.close()
            # Save the PDF as an attachment
            attachment = request.env['ir.attachment'].create({
                'name': "{}-{}".format(document.name, 'Online Form Report'),
                'type': 'binary',
                'datas': base64.encodebytes(output_stream.getvalue()),
                'res_model': 'pdf.document',
                'mimetype': 'application/pdf',
            })
           
            return values
        else:
            return values
           
           
      In this way, you can create your own form by adding the attachments( I added the attachment because you mentioned that the make visitor can register their CV )
      also, you can refer to the forum  for adding the many2one fields(https://www.odoo.com/es_ES/forum/ayuda-1/how-to-add-many2one-field-in-website-167725)

Hope it helps

アバター
破棄