[IMP] excel_import_export: black, isort, prettier

pull/2505/head
Kitti U 2021-02-13 14:08:54 +07:00 committed by Aungkokolin1997
parent 7162b84404
commit 354890e57a
8 changed files with 41 additions and 34 deletions

View File

@ -7,7 +7,7 @@
"version": "13.0.1.0.0", "version": "13.0.1.0.0",
"author": "Ecosoft,Odoo Community Association (OCA)", "author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"website": "https://github.com/OCA/server-tools/", "website": "https://github.com/OCA/server-tools",
"category": "Tools", "category": "Tools",
"depends": ["mail"], "depends": ["mail"],
"external_dependencies": {"python": ["xlrd", "xlwt", "openpyxl"]}, "external_dependencies": {"python": ["xlrd", "xlwt", "openpyxl"]},

View File

@ -68,12 +68,12 @@ def get_field_condition(field):
def get_field_style(field): def get_field_style(field):
""" """
Available styles Available styles
- font = bold, bold_red - font = bold, bold_red
- fill = red, blue, yellow, green, grey - fill = red, blue, yellow, green, grey
- align = left, center, right - align = left, center, right
- number = true, false - number = true, false
i.e., 'field#{font=bold;fill=red;align=center;style=number}' i.e., 'field#{font=bold;fill=red;align=center;style=number}'
""" """
if field and "#{" in field and "}" in field: if field and "#{" in field and "}" in field:
i = field.index("#{") i = field.index("#{")
@ -267,8 +267,8 @@ def pos2idx(pos):
def _get_cell_value(cell, field_type=False): def _get_cell_value(cell, field_type=False):
""" If Odoo's field type is known, convert to valid string for import, """If Odoo's field type is known, convert to valid string for import,
if not know, just get value as is """ if not know, just get value as is"""
value = False value = False
datemode = 0 # From book.datemode, but we fix it for simplicity datemode = 0 # From book.datemode, but we fix it for simplicity
if field_type in ["date", "datetime"]: if field_type in ["date", "datetime"]:

View File

@ -8,7 +8,7 @@ from odoo import api, models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
from openpyxl.styles import PatternFill, Alignment, Font from openpyxl.styles import Alignment, Font, PatternFill
except ImportError: except ImportError:
_logger.debug('Cannot import "openpyxl". Please make sure it is installed.') _logger.debug('Cannot import "openpyxl". Please make sure it is installed.')

View File

@ -44,10 +44,10 @@ class XLSXExport(models.AbstractModel):
@api.model @api.model
def _get_line_vals(self, record, line_field, fields): def _get_line_vals(self, record, line_field, fields):
""" Get values of this field from record set and return as dict of vals """Get values of this field from record set and return as dict of vals
- record: main object - record: main object
- line_field: rows object, i.e., line_ids - line_field: rows object, i.e., line_ids
- fields: fields in line_ids, i.e., partner_id.display_name - fields: fields in line_ids, i.e., partner_id.display_name
""" """
line_field, max_row = co.get_line_max(line_field) line_field, max_row = co.get_line_max(line_field)
line_field = line_field.replace("_CONT_", "") # Remove _CONT_ if any line_field = line_field.replace("_CONT_", "") # Remove _CONT_ if any

View File

@ -14,7 +14,7 @@ from . import common as co
class XLSXTemplate(models.Model): class XLSXTemplate(models.Model):
""" Master Data for XLSX Templates """Master Data for XLSX Templates
- Excel Template - Excel Template
- Import/Export Meta Data (dict text) - Import/Export Meta Data (dict text)
- Default values, etc. - Default values, etc.
@ -95,10 +95,12 @@ class XLSXTemplate(models.Model):
) )
# Utilities # Utilities
export_action_id = fields.Many2one( export_action_id = fields.Many2one(
comodel_name="ir.actions.act_window", ondelete="set null", comodel_name="ir.actions.act_window",
ondelete="set null",
) )
import_action_id = fields.Many2one( import_action_id = fields.Many2one(
comodel_name="ir.actions.act_window", ondelete="set null", comodel_name="ir.actions.act_window",
ondelete="set null",
) )
use_report_wizard = fields.Boolean( use_report_wizard = fields.Boolean(
string="Easy Reporting", string="Easy Reporting",
@ -109,12 +111,17 @@ class XLSXTemplate(models.Model):
string="Report Model", string="Report Model",
help="When use commone wizard, choose the result model", help="When use commone wizard, choose the result model",
) )
result_field = fields.Char(compute="_compute_result_field",) result_field = fields.Char(
compute="_compute_result_field",
)
report_menu_id = fields.Many2one( report_menu_id = fields.Many2one(
comodel_name="ir.ui.menu", string="Report Menu", readonly=True, comodel_name="ir.ui.menu",
string="Report Menu",
readonly=True,
) )
report_action_id = fields.Many2one( report_action_id = fields.Many2one(
comodel_name="ir.actions.report", string="Report Action", comodel_name="ir.actions.report",
string="Report Action",
) )
def _compute_result_field(self): def _compute_result_field(self):
@ -208,8 +215,8 @@ class XLSXTemplate(models.Model):
_field.ensure_one() _field.ensure_one()
_field.write({"relation": self.result_model_id.model}) _field.write({"relation": self.result_model_id.model})
_field.compute = """ _field.compute = """
self['%s'] = self.env['%s'].search(self.safe_domain(self.domain)) self['{}'] = self.env['{}'].search(self.safe_domain(self.domain))
""" % ( """.format(
self.result_field, self.result_field,
self.result_model_id.model, self.result_model_id.model,
) )

View File

@ -1,6 +1,6 @@
// © 2017 Creu Blanca // © 2017 Creu Blanca
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html). // License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
odoo.define("excel_import_export.report", function(require) { odoo.define("excel_import_export.report", function (require) {
"use strict"; "use strict";
var core = require("web.core"); var core = require("web.core");
@ -10,7 +10,7 @@ odoo.define("excel_import_export.report", function(require) {
var _t = core._t; var _t = core._t;
ActionManager.include({ ActionManager.include({
_downloadReportExcel: function(url, actions) { _downloadReportExcel: function (url, actions) {
var self = this; var self = this;
framework.blockUI(); framework.blockUI();
var type = "excel"; var type = "excel";
@ -34,14 +34,14 @@ odoo.define("excel_import_export.report", function(require) {
encodeURIComponent(JSON.stringify(cloned_action.context)); encodeURIComponent(JSON.stringify(cloned_action.context));
} }
return new Promise(function(resolve, reject) { return new Promise(function (resolve, reject) {
var blocked = !session.get_file({ var blocked = !session.get_file({
url: new_url, url: new_url,
data: { data: {
data: JSON.stringify([new_url, type]), data: JSON.stringify([new_url, type]),
}, },
success: resolve, success: resolve,
error: error => { error: (error) => {
self.call("crash_manager", "rpc_error", error); self.call("crash_manager", "rpc_error", error);
reject(); reject();
}, },
@ -61,12 +61,12 @@ odoo.define("excel_import_export.report", function(require) {
}); });
}, },
_triggerDownload: function(action, options, type) { _triggerDownload: function (action, options, type) {
var self = this; var self = this;
var reportUrls = this._makeReportUrls(action); var reportUrls = this._makeReportUrls(action);
if (type === "excel") { if (type === "excel") {
return this._downloadReportExcel(reportUrls[type], action).then( return this._downloadReportExcel(reportUrls[type], action).then(
function() { function () {
if (action.close_on_report_download) { if (action.close_on_report_download) {
var closeAction = {type: "ir.actions.act_window_close"}; var closeAction = {type: "ir.actions.act_window_close"};
return self.doAction( return self.doAction(
@ -81,13 +81,13 @@ odoo.define("excel_import_export.report", function(require) {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
_makeReportUrls: function(action) { _makeReportUrls: function (action) {
var reportUrls = this._super.apply(this, arguments); var reportUrls = this._super.apply(this, arguments);
reportUrls.excel = "/report/excel/" + action.report_name; reportUrls.excel = "/report/excel/" + action.report_name;
return reportUrls; return reportUrls;
}, },
_executeReportAction: function(action, options) { _executeReportAction: function (action, options) {
var self = this; var self = this;
if (action.report_type === "excel") { if (action.report_type === "excel") {
return self._triggerDownload(action, options, "excel"); return self._triggerDownload(action, options, "excel");

View File

@ -6,8 +6,8 @@ from odoo.exceptions import ValidationError
class ExportXLSXWizard(models.TransientModel): class ExportXLSXWizard(models.TransientModel):
""" This wizard is used with the template (xlsx.template) to export """This wizard is used with the template (xlsx.template) to export
xlsx template filled with data form the active record """ xlsx template filled with data form the active record"""
_name = "export.xlsx.wizard" _name = "export.xlsx.wizard"
_description = "Wizard for exporting excel" _description = "Wizard for exporting excel"

View File

@ -6,8 +6,8 @@ from odoo.exceptions import RedirectWarning, ValidationError
class ImportXLSXWizard(models.TransientModel): class ImportXLSXWizard(models.TransientModel):
""" This wizard is used with the template (xlsx.template) to import """This wizard is used with the template (xlsx.template) to import
xlsx template back to active record """ xlsx template back to active record"""
_name = "import.xlsx.wizard" _name = "import.xlsx.wizard"
_description = "Wizard for importing excel" _description = "Wizard for importing excel"