From 4f5b101a2244ec4349a2a6b9c523c2ac2e71e300 Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Fri, 20 Mar 2020 11:24:10 +0700 Subject: [PATCH] [MIG] stock_card_report: Migration to 13.0 --- oca_dependencies.txt | 2 ++ stock_card_report/reports/stock_card_report.py | 3 --- .../reports/stock_card_report_xlsx.py | 1 + .../static/src/js/stock_card_report_backend.js | 16 ++++++++-------- .../tests/test_stock_card_report.py | 4 ++-- .../wizard/stock_card_report_wizard.py | 6 +----- .../wizard/stock_card_report_wizard_view.xml | 1 - 7 files changed, 14 insertions(+), 19 deletions(-) create mode 100644 oca_dependencies.txt diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 0000000..5cd2498 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1,2 @@ +server-ux +reporting-engine diff --git a/stock_card_report/reports/stock_card_report.py b/stock_card_report/reports/stock_card_report.py index 953adb7..425715a 100644 --- a/stock_card_report/reports/stock_card_report.py +++ b/stock_card_report/reports/stock_card_report.py @@ -39,7 +39,6 @@ class StockCardReport(models.TransientModel): help="Use compute fields, so there is nothing store in database", ) - @api.multi def _compute_results(self): self.ensure_one() date_from = self.date_from or "0001-01-01" @@ -77,13 +76,11 @@ class StockCardReport(models.TransientModel): ReportLine = self.env["stock.card.view"] self.results = [ReportLine.new(line).id for line in stock_card_results] - @api.multi def _get_initial(self, product_line): product_input_qty = sum(product_line.mapped("product_in")) product_output_qty = sum(product_line.mapped("product_out")) return product_input_qty - product_output_qty - @api.multi def print_report(self, report_type="qweb"): self.ensure_one() action = ( diff --git a/stock_card_report/reports/stock_card_report_xlsx.py b/stock_card_report/reports/stock_card_report_xlsx.py index 18766cf..8a9f41a 100644 --- a/stock_card_report/reports/stock_card_report_xlsx.py +++ b/stock_card_report/reports/stock_card_report_xlsx.py @@ -10,6 +10,7 @@ _logger = logging.getLogger(__name__) class ReportStockCardReportXlsx(models.AbstractModel): _name = "report.stock_card_report.report_stock_card_report_xlsx" + _description = "Stock Card Report XLSX" _inherit = "report.report_xlsx.abstract" def generate_xlsx_report(self, workbook, data, objects): diff --git a/stock_card_report/static/src/js/stock_card_report_backend.js b/stock_card_report/static/src/js/stock_card_report_backend.js index b5e7a49..2833649 100644 --- a/stock_card_report/static/src/js/stock_card_report_backend.js +++ b/stock_card_report/static/src/js/stock_card_report_backend.js @@ -1,19 +1,20 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) { 'use strict'; + var AbstractAction = require('web.AbstractAction'); var core = require('web.core'); - var Widget = require('web.Widget'); - var ControlPanelMixin = require('web.ControlPanelMixin'); var ReportWidget = require('web.Widget'); - var report_backend = Widget.extend(ControlPanelMixin, { + var report_backend = AbstractAction.extend({ + hasControlPanel: true, // Stores all the parameters of the action. events: { 'click .o_stock_card_reports_print': 'print', 'click .o_stock_card_reports_export': 'export', }, init: function (parent, action) { + this._super.apply(this, arguments); this.actionManager = parent; this.given_context = {}; this.odoo_context = action.context; @@ -25,17 +26,16 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) { action.params.active_id; this.given_context.model = action.context.active_model || false; this.given_context.ttype = action.context.ttype || false; - return this._super.apply(this, arguments); }, willStart: function () { - return $.when(this.get_html()); + return Promise.all([this._super.apply(this, arguments), this.get_html()]); }, set_html: function () { var self = this; - var def = $.when(); + var def = Promise.resolve(); if (!this.report_widget) { this.report_widget = new ReportWidget(this, this.given_context); - def = this.report_widget.appendTo(this.$el); + def = this.report_widget.appendTo(this.$('.o_content')); } def.then(function () { self.report_widget.$el.html(self.html); @@ -100,7 +100,7 @@ odoo.define('stock_card_report.stock_card_report_backend', function (require) { }); }, canBeRemoved: function () { - return $.when(); + return Promise.resolve(); }, }); diff --git a/stock_card_report/tests/test_stock_card_report.py b/stock_card_report/tests/test_stock_card_report.py index 59bd897..02fa0c6 100644 --- a/stock_card_report/tests/test_stock_card_report.py +++ b/stock_card_report/tests/test_stock_card_report.py @@ -13,7 +13,7 @@ _logger = logging.getLogger(__name__) class TestStockCard(common.TransactionCase): def setUp(self): - super(TestStockCard, self).setUp() + super().setUp() # Create uom: uom_id = self.ref("uom.product_uom_unit") @@ -126,7 +126,7 @@ class TestStockCard(common.TransactionCase): class TestStockCardReport(common.TransactionCase): def setUp(self): - super(TestStockCardReport, self).setUp() + super().setUp() # Create uom: uom_id = self.ref("uom.product_uom_unit") diff --git a/stock_card_report/wizard/stock_card_report_wizard.py b/stock_card_report/wizard/stock_card_report_wizard.py index ed70097..efd55a6 100644 --- a/stock_card_report/wizard/stock_card_report_wizard.py +++ b/stock_card_report/wizard/stock_card_report_wizard.py @@ -2,7 +2,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models -from odoo.tools import pycompat from odoo.tools.safe_eval import safe_eval @@ -25,13 +24,12 @@ class StockCardReportWizard(models.TransientModel): self.date_from = self.date_range_id.date_start self.date_to = self.date_range_id.date_end - @api.multi def button_export_html(self): self.ensure_one() action = self.env.ref("stock_card_report.action_report_stock_card_report_html") vals = action.read()[0] context = vals.get("context", {}) - if isinstance(context, pycompat.string_types): + if context: context = safe_eval(context) model = self.env["report.stock.card.report"] report = model.create(self._prepare_stock_card_report()) @@ -40,13 +38,11 @@ class StockCardReportWizard(models.TransientModel): vals["context"] = context return vals - @api.multi def button_export_pdf(self): self.ensure_one() report_type = "qweb-pdf" return self._export(report_type) - @api.multi def button_export_xlsx(self): self.ensure_one() report_type = "xlsx" diff --git a/stock_card_report/wizard/stock_card_report_wizard_view.xml b/stock_card_report/wizard/stock_card_report_wizard_view.xml index a8cdfc9..f0570dc 100644 --- a/stock_card_report/wizard/stock_card_report_wizard_view.xml +++ b/stock_card_report/wizard/stock_card_report_wizard_view.xml @@ -33,7 +33,6 @@ Stock Card stock.card.report.wizard - form form new