[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",
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-tools/",
"website": "https://github.com/OCA/server-tools",
"category": "Tools",
"depends": ["mail"],
"external_dependencies": {"python": ["xlrd", "xlwt", "openpyxl"]},

View File

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

View File

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

View File

@ -44,10 +44,10 @@ class XLSXExport(models.AbstractModel):
@api.model
def _get_line_vals(self, record, line_field, fields):
""" Get values of this field from record set and return as dict of vals
- record: main object
- line_field: rows object, i.e., line_ids
- fields: fields in line_ids, i.e., partner_id.display_name
"""Get values of this field from record set and return as dict of vals
- record: main object
- line_field: rows object, i.e., line_ids
- fields: fields in line_ids, i.e., partner_id.display_name
"""
line_field, max_row = co.get_line_max(line_field)
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):
""" Master Data for XLSX Templates
"""Master Data for XLSX Templates
- Excel Template
- Import/Export Meta Data (dict text)
- Default values, etc.
@ -95,10 +95,12 @@ class XLSXTemplate(models.Model):
)
# Utilities
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(
comodel_name="ir.actions.act_window", ondelete="set null",
comodel_name="ir.actions.act_window",
ondelete="set null",
)
use_report_wizard = fields.Boolean(
string="Easy Reporting",
@ -109,12 +111,17 @@ class XLSXTemplate(models.Model):
string="Report 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(
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(
comodel_name="ir.actions.report", string="Report Action",
comodel_name="ir.actions.report",
string="Report Action",
)
def _compute_result_field(self):
@ -208,8 +215,8 @@ class XLSXTemplate(models.Model):
_field.ensure_one()
_field.write({"relation": self.result_model_id.model})
_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_model_id.model,
)

View File

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

View File

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

View File

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