-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] spreadsheet_oca: Allow to import XLSX Files
- Loading branch information
Showing
6 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
spreadsheet_oca/static/src/spreadsheet_tree/spreadsheet_tree_view.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** @odoo-module **/ | ||
import {Component} from "@odoo/owl"; | ||
import {FileUploader} from "@web/views/fields/file_handler"; | ||
import {ListController} from "@web/views/list/list_controller"; | ||
import {listView} from "@web/views/list/list_view"; | ||
|
||
import {registry} from "@web/core/registry"; | ||
import {standardWidgetProps} from "@web/views/widgets/standard_widget_props"; | ||
import {useService} from "@web/core/utils/hooks"; | ||
|
||
class SpreadsheetFileUploader extends Component { | ||
setup() { | ||
this.orm = useService("orm"); | ||
this.attachmentIdsToProcess = []; | ||
this.action = useService("action"); | ||
} | ||
async onFileUploaded(file) { | ||
const att_data = { | ||
name: file.name, | ||
mimetype: file.type, | ||
datas: file.data, | ||
}; | ||
const att_id = await this.orm.create("ir.attachment", [att_data], { | ||
context: this.env.searchModel.context, | ||
}); | ||
this.attachmentIdsToProcess.push(att_id); | ||
} | ||
async onUploadComplete() { | ||
let action = {}; | ||
try { | ||
action = await this.orm.call( | ||
"spreadsheet.spreadsheet", | ||
"create_document_from_attachment", | ||
["", this.attachmentIdsToProcess], | ||
{context: this.env.searchModel.context} | ||
); | ||
} finally { | ||
// Ensures attachments are cleared on success as well as on error | ||
this.attachmentIdsToProcess = []; | ||
} | ||
if (action.context && action.context.notifications) { | ||
for (const [file, msg] of Object.entries(action.context.notifications)) { | ||
this.notification.add(msg, { | ||
title: file, | ||
type: "info", | ||
sticky: true, | ||
}); | ||
} | ||
delete action.context.notifications; | ||
} | ||
this.action.doAction(action); | ||
} | ||
} | ||
SpreadsheetFileUploader.components = { | ||
FileUploader, | ||
}; | ||
SpreadsheetFileUploader.template = "spreadsheet_oca.SpreadsheetFileUploader"; | ||
SpreadsheetFileUploader.props = { | ||
...standardWidgetProps, | ||
acceptedFileExtensions: {type: String, optional: true}, | ||
record: {type: Object, optional: true}, | ||
togglerTemplate: {type: String, optional: true}, | ||
slots: {type: Object, optional: true}, | ||
}; | ||
SpreadsheetFileUploader.defaultProps = { | ||
acceptedFileExtensions: | ||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | ||
}; | ||
export class SpreadsheetListController extends ListController {} | ||
SpreadsheetListController.components = { | ||
...ListController.components, | ||
SpreadsheetFileUploader, | ||
}; | ||
export const SpreadsheetListView = { | ||
...listView, | ||
Controller: SpreadsheetListController, | ||
buttonTemplate: "spreadsheet_oca.ListView.Buttons", | ||
}; | ||
|
||
registry.category("views").add("spreadsheet_tree", SpreadsheetListView); |
44 changes: 44 additions & 0 deletions
44
spreadsheet_oca/static/src/spreadsheet_tree/spreadsheet_tree_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
<t t-name="spreadsheet_oca.SpreadsheetFileUploader" owl="1"> | ||
<div | ||
t-att-class="props.record and props.record.data ? 'oe_kanban_color_' + props.record.data.color : ''" | ||
> | ||
<FileUploader | ||
acceptedFileExtensions="props.acceptedFileExtensions" | ||
fileUploadClass="'spreadsheet_file_uploader'" | ||
multiUpload="true" | ||
onUploaded.bind="onFileUploaded" | ||
onUploadComplete.bind="onUploadComplete" | ||
> | ||
<t t-set-slot="toggler"> | ||
<t | ||
t-if="props.togglerTemplate" | ||
t-call="{{ props.togglerTemplate }}" | ||
/> | ||
<t t-else="" t-slot="default" /> | ||
</t> | ||
<t t-slot="extra" /> | ||
</FileUploader> | ||
</div> | ||
</t> | ||
<t | ||
t-name="spreadsheet_oca.ListView.Buttons" | ||
t-inherit="web.ListView.Buttons" | ||
t-inherit-mode="primary" | ||
owl="1" | ||
> | ||
<xpath expr="//*[@class='btn btn-primary o_list_button_add']" position="after"> | ||
<SpreadsheetFileUploader> | ||
<t t-set-slot="default"> | ||
<button | ||
type="button" | ||
class="btn btn-secondary o_button_upload_bill" | ||
> | ||
Upload XLSX | ||
</button> | ||
</t> | ||
</SpreadsheetFileUploader> | ||
</xpath> | ||
</t> | ||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters