[MIG] stock_card_report: Migration to 13.0

This commit is contained in:
ps-tubtim
2020-03-20 11:24:10 +07:00
parent 86a2d2958f
commit 4f5b101a22
7 changed files with 14 additions and 19 deletions

2
oca_dependencies.txt Normal file
View File

@@ -0,0 +1,2 @@
server-ux
reporting-engine

View File

@@ -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 = (

View File

@@ -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):

View File

@@ -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();
},
});

View File

@@ -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")

View File

@@ -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"

View File

@@ -33,7 +33,6 @@
<record id="stock_card_report_action" model="ir.actions.act_window">
<field name="name">Stock Card</field>
<field name="res_model">stock.card.report.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>