@ -0,0 +1,42 @@ |
|||||
|
.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg |
||||
|
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html |
||||
|
:alt: License: LGPL-3 |
||||
|
|
||||
|
File Upload In Survey |
||||
|
===================== |
||||
|
This module is used for attachment of files in Survey Form |
||||
|
|
||||
|
Company |
||||
|
------- |
||||
|
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
||||
|
|
||||
|
License |
||||
|
------- |
||||
|
General Public License v3.0 (LGPL v3) |
||||
|
(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) |
||||
|
|
||||
|
Credits |
||||
|
------- |
||||
|
Developer: (V17) Mohammed Dilshad Tk@ Cybrosys, Contact: odoo@cybrosys.com |
||||
|
|
||||
|
Contacts |
||||
|
-------- |
||||
|
* Mail Contact : odoo@cybrosys.com |
||||
|
* Website : https://cybrosys.com |
||||
|
|
||||
|
Bug Tracker |
||||
|
----------- |
||||
|
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
||||
|
|
||||
|
Maintainer |
||||
|
========== |
||||
|
.. image:: https://cybrosys.com/images/logo.png |
||||
|
:target: https://cybrosys.com |
||||
|
|
||||
|
This module is maintained by Cybrosys Technologies. |
||||
|
|
||||
|
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
||||
|
|
||||
|
Further information |
||||
|
=================== |
||||
|
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import models |
@ -0,0 +1,50 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
'name': "File Upload In Survey", |
||||
|
'version': "18.0.1.0.0", |
||||
|
'category': 'Extra Tools', |
||||
|
'summary': 'Attachment of File in Survey Form', |
||||
|
'description': 'This module is used for attachments of file in Survey Form,' |
||||
|
'You can also add multiple file attachment to Survey Form .', |
||||
|
'author': 'Cybrosys Techno Solutions', |
||||
|
'company': 'Cybrosys Techno Solutions', |
||||
|
'maintainer': 'Cybrosys Techno Solutions', |
||||
|
'website': 'https://www.cybrosys.com', |
||||
|
'depends': ['survey'], |
||||
|
'assets': { |
||||
|
'survey.survey_assets': [ |
||||
|
'survey_upload_file/static/src/js/survey_form_attachment.js', |
||||
|
'survey_upload_file/static/src/js/SurveyFormWidget.js', |
||||
|
], |
||||
|
}, |
||||
|
'data': [ |
||||
|
'views/survey_question_views.xml', |
||||
|
'views/survey_user_views.xml', |
||||
|
'views/survey_templates.xml', |
||||
|
], |
||||
|
'images': ['static/description/banner.png'], |
||||
|
'license': 'LGPL-3', |
||||
|
'installable': True, |
||||
|
'auto_install': False, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
## Module <survey_upload_file> |
||||
|
|
||||
|
#### 05.11.2024 |
||||
|
#### Version 18.0.1.0.0 |
||||
|
#### ADD |
||||
|
|
||||
|
- Initial Commit for File Upload In Survey |
@ -0,0 +1,24 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from . import survey_question |
||||
|
from . import survey_user_input_line |
||||
|
from . import survey_user_input |
@ -0,0 +1,38 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from odoo import fields, models |
||||
|
|
||||
|
|
||||
|
class SurveyQuestion(models.Model): |
||||
|
""" |
||||
|
This class extends the 'survey.question' model to add new functionality |
||||
|
for file uploads. |
||||
|
""" |
||||
|
_inherit = 'survey.question' |
||||
|
|
||||
|
question_type = fields.Selection( |
||||
|
selection_add=[('upload_file', 'Upload File')], |
||||
|
help='Select the type of question to create.') |
||||
|
upload_multiple_file = fields.Boolean(string='Upload Multiple File', |
||||
|
help='Check this box if you want to ' |
||||
|
'allow users to upload ' |
||||
|
'multiple files') |
@ -0,0 +1,85 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from odoo import models |
||||
|
|
||||
|
|
||||
|
class SurveyUserInput(models.Model): |
||||
|
""" |
||||
|
This class extends the 'survey.user_input' model to add custom |
||||
|
functionality for saving user answers. |
||||
|
|
||||
|
Methods: |
||||
|
_save_lines: Save the user's answer for the given question |
||||
|
_save_line_file:Save the user's file upload answer for the given |
||||
|
question |
||||
|
_get_line_answer_file_upload_values: |
||||
|
Get the values to use when creating or updating a user input line |
||||
|
for a file upload answer |
||||
|
""" |
||||
|
_inherit = "survey.user_input" |
||||
|
|
||||
|
def _save_lines(self, question, answer, comment=None, |
||||
|
overwrite_existing=False): |
||||
|
"""Save the user's answer for the given question.""" |
||||
|
old_answers = self.env['survey.user_input.line'].search([ |
||||
|
('user_input_id', '=', self.id), |
||||
|
('question_id', '=', question.id), ]) |
||||
|
if question.question_type in 'upload_file': |
||||
|
res = self._save_line_simple_answer(question, old_answers, answer) |
||||
|
else: |
||||
|
res = super()._save_lines(question, answer, comment, |
||||
|
overwrite_existing) |
||||
|
return res |
||||
|
|
||||
|
def _save_line_simple_answer(self, question, old_answers, answer): |
||||
|
""" Save the user's file upload answer for the given question.""" |
||||
|
vals = self._get_line_answer_file_upload_values(question, |
||||
|
'upload_file', answer) |
||||
|
if old_answers: |
||||
|
old_answers.write(vals) |
||||
|
return old_answers |
||||
|
else: |
||||
|
return self.env['survey.user_input.line'].create(vals) |
||||
|
|
||||
|
def _get_line_answer_file_upload_values(self, question, answer_type, |
||||
|
answer): |
||||
|
"""Get the values to use when creating or updating a user input line |
||||
|
for a file upload answer.""" |
||||
|
vals = { |
||||
|
'user_input_id': self.id, |
||||
|
'question_id': question.id, |
||||
|
'skipped': False, |
||||
|
'answer_type': answer_type, |
||||
|
} |
||||
|
if answer_type == 'upload_file': |
||||
|
file_data = answer[0] |
||||
|
file_name = answer[1] |
||||
|
attachment_ids = [] |
||||
|
for file in range(len(answer[1])): |
||||
|
attachment = self.env['ir.attachment'].create({ |
||||
|
'name': file_name[file], |
||||
|
'type': 'binary', |
||||
|
'datas': file_data[file], |
||||
|
}) |
||||
|
attachment_ids.append(attachment.id) |
||||
|
vals['value_file_data_ids'] = attachment_ids |
||||
|
return vals |
@ -0,0 +1,50 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Cybrosys Technologies Pvt. Ltd. |
||||
|
# |
||||
|
# Copyright (C) 2025-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
||||
|
# Author: Mohammed Dilshad Tk (odoo@cybrosys.com) |
||||
|
# |
||||
|
# You can modify it under the terms of the GNU LESSER |
||||
|
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE |
||||
|
# (LGPL v3) along with this program. |
||||
|
# If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
from odoo import api, fields, models |
||||
|
|
||||
|
|
||||
|
class SurveyUserInputLine(models.Model): |
||||
|
""" |
||||
|
This class extends the 'survey.user_input.line' model to add additional |
||||
|
fields and constraints for file uploads. |
||||
|
Methods: |
||||
|
_check_answer_type_skipped:Check that a line's answer type is |
||||
|
not set to 'upload_file' if the line is skipped |
||||
|
""" |
||||
|
_inherit = "survey.user_input.line" |
||||
|
|
||||
|
answer_type = fields.Selection( |
||||
|
selection_add=[('upload_file', 'Upload File')], |
||||
|
help="The type of answer for this question (upload_file if the user " |
||||
|
"is uploading a file).") |
||||
|
value_file_data_ids = fields.Many2many('ir.attachment', |
||||
|
help="The attachments " |
||||
|
"corresponding to the user's " |
||||
|
"file upload answer, if any.") |
||||
|
|
||||
|
@api.constrains('skipped', 'answer_type') |
||||
|
def _check_answer_type_skipped(self): |
||||
|
""" Check that a line's answer type is not set to 'upload_file' if |
||||
|
the line is skipped.""" |
||||
|
for line in self: |
||||
|
if line.answer_type != 'upload_file': |
||||
|
super(SurveyUserInputLine, line)._check_answer_type_skipped() |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 912 KiB |
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 268 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 105 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 92 KiB |
After Width: | Height: | Size: 94 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 85 KiB |
After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,13 @@ |
|||||
|
/** @odoo-module */ |
||||
|
import SurveyFormWidget from '@survey/js/survey_form'; |
||||
|
SurveyFormWidget.include({ |
||||
|
/** Get all question answers by question type */ |
||||
|
_prepareSubmitValues(formData, params) { |
||||
|
this._super(...arguments); |
||||
|
this.$('[data-question-type]').each(function () { |
||||
|
if ($(this).data('questionType') === 'upload_file'){ |
||||
|
params[this.name] = [$(this).data('oe-data'), $(this).data('oe-file_name')]; |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
}); |
@ -0,0 +1,61 @@ |
|||||
|
/** @odoo-module */ |
||||
|
import publicWidget from "@web/legacy/js/public/public_widget"; |
||||
|
import SurveyFormWidget from '@survey/js/survey_form'; |
||||
|
import SurveyPreloadImageMixin from "@survey/js/survey_preload_image_mixin"; |
||||
|
/** Extends publicWidget to create "SurveyFormUpload" */ |
||||
|
publicWidget.registry.SurveyFormUpload = publicWidget.Widget.extend(SurveyPreloadImageMixin, { |
||||
|
selector: '.o_survey_form', |
||||
|
events: { |
||||
|
'change .o_survey_upload_file': '_onFileChange', |
||||
|
}, |
||||
|
init() { |
||||
|
this._super(...arguments); |
||||
|
// this.rpc = this.bindService("rpc");
|
||||
|
}, |
||||
|
/** On adding file function */ |
||||
|
_onFileChange: function(event) { |
||||
|
var self = this; |
||||
|
var files = event.target.files; |
||||
|
var fileNames = []; |
||||
|
var dataURLs = []; |
||||
|
for (let i = 0; i < files.length; i++) { |
||||
|
var reader = new FileReader(); |
||||
|
reader.readAsDataURL(files[i]); |
||||
|
reader.onload = function(e) { |
||||
|
var file = files[i]; |
||||
|
var filename = file.name; |
||||
|
var dataURL = e.target.result.split(',')[1]; /** split base64 data */ |
||||
|
fileNames.push(filename); |
||||
|
dataURLs.push(dataURL); |
||||
|
/** Set the data-oe-data and data-oe-file_name attributes of the input element self call el */ |
||||
|
var $input = self.$el.find('input.o_survey_upload_file'); |
||||
|
$input.attr('data-oe-data', JSON.stringify(dataURLs)); |
||||
|
$input.attr('data-oe-file_name', JSON.stringify(fileNames)); |
||||
|
// Create file list elements
|
||||
|
var fileList = document.getElementById('fileList'); |
||||
|
fileList.innerHTML = ''; // clear previous contents of file list
|
||||
|
var ul = document.createElement('ul'); |
||||
|
fileNames.forEach(function(fileName) { |
||||
|
var li = document.createElement('li'); |
||||
|
li.textContent = fileName; |
||||
|
ul.appendChild(li); |
||||
|
}); |
||||
|
// Create delete button
|
||||
|
var deleteBtn = document.createElement('button'); |
||||
|
deleteBtn.textContent = 'Delete All'; |
||||
|
deleteBtn.addEventListener('click', function() { |
||||
|
// Clear file list
|
||||
|
fileList.innerHTML = ''; |
||||
|
// Clear input field attributes
|
||||
|
$input.attr('data-oe-data', ''); |
||||
|
$input.attr('data-oe-file_name', ''); |
||||
|
self.$el.find('input[type="file"]').val(''); |
||||
|
}); |
||||
|
// Append file list and delete button to file input container
|
||||
|
fileList.appendChild(ul); |
||||
|
fileList.appendChild(deleteBtn); |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
}); |
||||
|
export default publicWidget.registry.SurveyFormUpload; |