Bulk upload into Odoo (OpenERP) - javascript

I am having a small issue using Odoo,
I have more then 1000 file to upload into Odoo V11 (.pdf/.stp), each file in attached to a P/N, I managed to have the adresse link for every par number created in odoo, but still i dont know how to make a bulk upload,
Now i am trying to create a macro for upload file per file but i am stuck in the first part.
I never used JavaScript before :/
here is the the main page of the PN :11050-1-A
when i lunch chrome console to click automatically in "ajouter" (Add) with
var el = document.getElementsByClassName('input_file_XXXX');
el[0].click();
i got a files dialogbox
lets say that the file is stored in desktop and called "11050-1-A - Test.pdf"
How can I automatically select the file?
Do you have another idea to solve this problem ?

If you have let's say more than 100 of these that needs to be imported once, you will need to create a Python script that uses Odoo's XML-RPC to upload the files. The process will be:
Connect to the XML-RPC and authenticate
Search for a product with the name
Search for the file on your computer
Create a new ir.attachment that links to the product
XML-RPC link: https://www.odoo.com/documentation/12.0/webservices/odoo.html

Related

Adapt GAS script functions from a Spreadsheet to a Web Application

I'm new to GAS and JavaScript in general, so I'd like some help adapting a script from a spreadsheet to a Web App.
Based on some scripts I found, I developed a code to work the way I need in a Google Spreadsheet, but after making it work exactly the way I need it, I realized that a Web App could be a better alternative, mainly because of how it works on Mobile .
The point is that I didn't have a very linear JavaScript learning curve, my learning was solving specific needs, so I have difficulty with some basic concepts... and to be quite honest, deeply understanding JavaScript is not my main focus, but this knowledge is missing me now...
Let's get straight to the point
My current spreadsheet is this one:
Google Sheet - Stack Demonstration
In the GAS linked to this worksheet there are 2 .gs files and one HTML.
GAS files
1 - CSV.gs | Contains 2 scripts
CheckForFiles - Checks the amount of files in a given Google Drive folder before releasing the execution of other scripts.
SheetToCSV - Creates a .csv file of the sheet in the parent folder of that sheet.
This script is applied to the spreadsheet's Submit button.
2 - Upload.gs | Contains some functions responsible for uploading files through the spreadsheet.
ShowDialog0101 - Basically it's a script to call the upload page through an HTML alert in the spreadsheet.
GetParent - Basically it's a script that discovers the ID of the spreadsheet's parent folder and passes this information to the HTML file. I created this function because that way I can use this worksheet's folder as a model folder, simply duplicating the entire content without having to edit the code to update the worksheet's folder ID.
CreateOrGetFolder - This is the main function of the upload script, it checks if there is a child folder that has the name "Video" inside the parent folder, if it exists, it takes the ID of that folder so that the file is uploaded in that folder, if it does not exist, it creates a folder called "Video" and takes the ID of the created folder.
This is the Web App that launches when the Video File button is clicked:
Web App - Stack Demonstration
HTML file
Basically contains the client-side upload functions, I adapted this script based on this one.
What i would like to do
As I commented initially, I would like to adapt these scripts to work in a Web App.
My idea is that instead of the person filling out the worksheet, they fill out a form.
For this I need to adapt mainly the SheetToCSV script to link with a Submit button in the Web App, the idea is that as soon as the form is completed and the file upload is completed, this button is released and then when clicking on it the SheetToCSV script be triggered by creating a .csv file in the spreadsheet's parent folder with all the form responses.
My main difficulty is in linking the .csv generation script with the Submit button, I've been racking my brains over this for days.
I'm already having nightmares with this programming, literally... if anyone can help me with this, I'd be very grateful!
EDIT
I'll try to explain in a little more detail here.
Currently, I have this google spreadsheet here:
This worksheet contains modified versions of 2 scripts created by Tanaike.
Script 1 - Generates a .csv file with the worksheet fields in the same folder as the worksheet.
Script 2 - It is a modified version of Tanaike's Resumable Upload for Web Apps script, it is called in the spreadsheet via html alert.
Resumable Upload for Web Apps via HTML Alert
CSV file generated by the worksheet
Everything works as expected in this worksheet, but now I would like to convert it to a Web App, like this example:
The issue is that I don't know how to convert Tanaike's .csv generation script to generate the files through this html form, what I need is to integrate it with the Submit button of the Web App and collect the form fields in a .csv file.
The Spreadsheet and the Web App can be viewed at these links:
Google Sheet
Web App Form
Thank you for replying. Can I ask you about your expected values for the CSV data? In this case,
I confirmed your expected result in this question as follows.
You want to retrieve 2 text values of "name01", "description", and 2 values from dropdown lists of "Option1" and "Option2". The total values are 4 values.
When the HTML form is submitted, you want to create a new CSV file for every submission.
In this case, how about the following modification? Unfortunately, in your question, your script is not shown. So, in this answer, I would like to propose a simple modification.
When I saw your sample Spreadsheet including your script, when the submit button is clicked, it seems that the function submitForm() is run. In this answer, this is used.
Modified script:
Javascript side:
Please modify submitForm() as follows.
function submitForm() {
// Added the below script.
var name = $('#name01').val();
var description = $('#description').val();
var option1 = $('#Option1').val();
var option2 = $('#Option2').val();
var data = [name, description, option1, option2].join(",");
google.script.run.saveDataAsCSV(data, uploadParentFolderId);
if ($('#submit-btn.disabled')[0]) return; // short circuit
Google Apps Script side:
Please add the following function. Please modify the filename of "sample.csv" to your actual situation.
const saveDataAsCSV = (data, folderId) => DriveApp.getFolderById(folderId).createFile("sample.csv", data);
By this modification, 4 values in HTML form are retrieved and save it as a CSV file to the folder of uploadParentFolderId.
If you want to save the file to other folder, please modify uploadParentFolderId of google.script.run.saveDataAsCSV(data, uploadParentFolderId).

Amazon S3 "GetPreSignedUrl" issue with not being able to get correct image download

My application has a table that uses ListObjects from AmazonS3, I then have some simple JS that uses the GetPreSignedUrl that is an attempt to allow the user to click on a row and download the file.
This sort of works, but the file name returned is not able to be downloaded and seems strange, an example here of the format it presents.
gray_logo.ai_X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAQCB2YU2GJH4QXTJH%2F20221117%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20221117T171806Z&X-Amz-Expires=60&X-Amz-SignedHeaders=accept%3Bhost&X-Amz-Signature=cbd4d86f9045cb12dab52adc
I have seen several posts on here, but none seem dully relevant.
How can i return the acutally file name and correct extention ?

How to get the path of a pdf report downloaded in a browser in Odoo 13?

I have a method which prints a pdf report and downloads it to the OS in Odoo 13 upon clicking a button. Now, I need to get (access) the path (where it is downloaded) of this report (file) and store it in ir_attachment table of Odoo. After storing the file (report) path then I want to have a button which fetch this report from it's the path stored in database and shows it in browser for a portal user in website module. I searched a lot but could not find anyway to do it. Can anyone help me if is it possible and if yes how?
Have you check with this method get_portal_url(report_type='pdf', download=True)?

How can I test file downloads with Behat 3 when using FileSaver.js?

I'm developing some Behat 3 (with Selenium 2) tests for a site that uses FileSaver.js to convert some DOM elements into an XML file for download. (I can't change that bit, so don't ask.)
When I click a button, JavaScript fires that passes the data blob into FileSaver.js, which converts that to an actual file and activates your browser's usual file download dialog. From there, the user clicks ok and says where to save the file.
I would like to test this process, but I can't figure out how to actually click that OK button or select where to save the file.
I'm fairly new to Behat, but the closest I could find to this is another SO question that deals with a file download (How to test file download in Behat), but because this blob file is created on the fly, I can't just use Guzzle to pull the file from the server.
Any suggestions?

Filepicker Implementation Meteor

I am currently trying to use filepicker on my Meteor project. I have been able to successfully show the pick a file button via front end, click, load the filepicker widget and upload a file. I am using the free storage with 5000 images. Filpicker confirms I have uploaded 30 files already. I am not sure how to get the URL and store it on my mongo DB. I am very new to development. I am using Coffee script. This is what I have:
Initializing:
Template.MyTemplate.rendered = () ->
filepicker.setKey("AouIUs8H6RnuPwHB5gqOyz")
filepicker.constructWidget(document.getElementById('attachment'))
Event Handler:
Template.MyTemplate.events
'change #attachment': () ->
console.log "attachment changed"
HTML
<div class="dataEntry">
Your File <input type="filepicker" id="attachment"/>
</div>
Not sure how to see the returned URL for the file and how to store it. I would much appreciate your support. As I mentioned I am new to this so if possible when in doubt don't assume I know. Thanks! - M

Categories