Skip to content

Commit

Permalink
[MIG] stock_inventory_valuation_report: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
solo4games committed Oct 17, 2023
1 parent 3ea92be commit d0e8b42
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 66 deletions.
2 changes: 1 addition & 1 deletion stock_inventory_valuation_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "Ecosoft,Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"stock_account",
"stock_account_valuation_report",
"report_xlsx_helper",
],
"data": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class StockInventoryValuationReport(models.TransientModel):
help="Use compute fields, so there is nothing store in database",
)

@api.multi
def _compute_results(self):
self.ensure_one()
if not self.compute_at_date:
Expand All @@ -59,26 +58,21 @@ def _compute_results(self):
ReportLine = self.env["stock.inventory.valuation.view"]
for product in products:
standard_price = product.standard_price
if self.date:
standard_price = product.get_history_price(
self.env.user.company_id.id, date=self.date
)
line = {
"name": product.name,
"reference": product.default_code,
"barcode": product.barcode,
"qty_at_date": product.qty_at_date,
"qty_at_date": product.qty_available,
"uom_id": product.uom_id,
"currency_id": product.currency_id,
"cost_currency_id": product.cost_currency_id,
"standard_price": standard_price,
"stock_value": product.qty_at_date * standard_price,
"stock_value": product.qty_available * standard_price,
"cost_method": product.cost_method,
}
if product.qty_at_date != 0:
if product.qty_available != 0:
self.results += ReportLine.new(line)

@api.multi
def print_report(self, report_type="qweb"):
self.ensure_one()
action = (
Expand All @@ -103,7 +97,7 @@ def _get_html(self):
result["html"] = self.env.ref(
"stock_inventory_valuation_report."
"report_stock_inventory_valuation_report_html"
).render(rcontext)
)._render(rcontext)
return result

@api.model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

from odoo import models

from odoo.addons.report_xlsx_helper.report.report_xlsx_format import (
FORMATS,
XLS_HEADERS,
)

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -57,7 +62,7 @@ def _get_ws_params(self, wb, data, objects):
},
"data": {
"value": self._render("qty_at_date"),
"format": self.format_tcell_amount_conditional_right,
"format": FORMATS["format_tcell_amount_conditional_right"],
},
"width": 18,
},
Expand All @@ -67,7 +72,7 @@ def _get_ws_params(self, wb, data, objects):
},
"data": {
"value": self._render("standard_price"),
"format": self.format_tcell_amount_conditional_right,
"format": FORMATS["format_tcell_amount_conditional_right"],
},
"width": 18,
},
Expand All @@ -77,7 +82,7 @@ def _get_ws_params(self, wb, data, objects):
},
"data": {
"value": self._render("stock_value"),
"format": self.format_tcell_amount_conditional_right,
"format": FORMATS["format_tcell_amount_conditional_right"],
},
"width": 18,
},
Expand All @@ -98,8 +103,8 @@ def _inventory_valuation_report(self, wb, ws, ws_params, data, objects):

ws.set_portrait()
ws.fit_to_pages(1, 0)
ws.set_header(self.xls_headers["standard"])
ws.set_footer(self.xls_footers["standard"])
ws.set_header(XLS_HEADERS["xls_headers"]["standard"])
ws.set_footer(XLS_HEADERS["xls_footers"]["standard"])

self._set_column_width(ws, ws_params)

Expand All @@ -111,14 +116,16 @@ def _inventory_valuation_report(self, wb, ws, ws_params, data, objects):
row_pos,
0,
["Date", "Partner", "Tax ID"],
self.format_theader_blue_center,
FORMATS["format_theader_blue_center"],
)
ws.write_row(
row_pos + 1, 0, [o.date or ""], FORMATS["format_tcell_date_center"]
)
ws.write_row(row_pos + 1, 0, [o.date or ""], self.format_tcell_date_center)
ws.write_row(
row_pos + 1,
1,
[o.company_id.name or "", o.company_id.vat or ""],
self.format_tcell_center,
FORMATS["format_tcell_center"],
)

row_pos += 3
Expand All @@ -127,7 +134,7 @@ def _inventory_valuation_report(self, wb, ws, ws_params, data, objects):
row_pos,
ws_params,
col_specs_section="header",
default_format=self.format_theader_blue_center,
default_format=FORMATS["format_theader_blue_center"],
)
ws.freeze_panes(row_pos, 0)

Expand All @@ -147,8 +154,8 @@ def _inventory_valuation_report(self, wb, ws, ws_params, data, objects):
"standard_price": line.standard_price or 0.00,
"stock_value": line.stock_value or 0.00,
},
default_format=self.format_tcell_left,
default_format=FORMATS["format_tcell_left"],
)
total += line.stock_value

ws.write(row_pos, 6, total, self.format_theader_blue_amount_right)
ws.write(row_pos, 6, total, FORMATS["format_theader_blue_amount_right"])
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ odoo.define(
"use strict";

var core = require("web.core");
var Widget = require("web.Widget");
var ControlPanelMixin = require("web.ControlPanelMixin");
var AbstractAction = require("web.AbstractAction");
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_inventory_valuation_report_print": "print",
"click .o_stock_inventory_valuation_report_export": "export",
},
init: function (parent, action) {
this._super.apply(this, arguments);
this.actionManager = parent;
this.given_context = {};
this.odoo_context = action.context;
Expand All @@ -26,17 +27,19 @@ odoo.define(
action.context.active_id || 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);
Expand All @@ -59,7 +62,7 @@ odoo.define(
}).then(function (result) {
self.html = result.html;
defs.push(self.update_cp());
return $.when.apply($, defs);
return Promise.all(defs);
});
},
// Updates the control panel and render the elements that have yet
Expand Down Expand Up @@ -100,7 +103,7 @@ odoo.define(
});
},
canBeRemoved: function () {
return $.when();
return Promise.resolve();
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@


class TestStockInventoryValuation(common.TransactionCase):
def setUp(cls):
super(TestStockInventoryValuation, cls).setUp()
def setUp(self):
super(TestStockInventoryValuation, self).setUp()

cls.model = cls._getReportModel()
self.model = self._getReportModel()

cls.qweb_report_name = cls._getQwebReportName()
cls.xlsx_report_name = cls._getXlsxReportName()
cls.xlsx_action_name = cls._getXlsxReportActionName()
self.qweb_report_name = self._getQwebReportName()
self.xlsx_report_name = self._getXlsxReportName()
self.xlsx_action_name = self._getXlsxReportActionName()

cls.report_title = cls._getReportTitle()
self.report_title = self._getReportTitle()

cls.base_filters = cls._getBaseFilters()
self.base_filters = self._getBaseFilters()

cls.report = cls.model.create(cls.base_filters)
cls.report._compute_results()
self.report = self.model.create(self.base_filters)
self.report._compute_results()

def test_html(self):
test_reports.try_report(
Expand Down Expand Up @@ -84,7 +84,7 @@ def _getReportTitle(self):
def _getBaseFilters(self):
return {
"company_id": self.env.user.company_id.id,
"compute_at_date": 0,
"compute_at_date": "0",
"date": datetime.datetime.now(),
}

Expand All @@ -93,7 +93,7 @@ class TestStockInventoryValuationReport(common.TransactionCase):
def setUp(self):
super(TestStockInventoryValuationReport, self).setUp()
self.company_id = self.env.ref("base.main_company")
self.compute_at_date = 0
self.compute_at_date = "0"
self.date = datetime.datetime.now()

def test_get_report_html(self):
Expand All @@ -110,7 +110,7 @@ def test_get_report_html(self):
def test_wizard(self):
wizard = self.env["stock.quantity.history"].create(
{
"compute_at_date": 0,
"compute_at_date": "0",
"date": datetime.datetime.now(),
}
)
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_date_report_result(self):
}
)
receipt.action_confirm()
receipt.action_done()
receipt._action_done()
receipt.move_lines.date = date_with_stock
self.assertEqual(
product.with_context(to_date=date_with_stock).qty_available, product_qty
Expand All @@ -170,7 +170,7 @@ def test_date_report_result(self):
report = self.env["report.stock.inventory.valuation.report"].create(
{
"company_id": self.company_id.id,
"compute_at_date": 0,
"compute_at_date": "0",
}
)
product_row = report.results.filtered(lambda r: r.name == product.name)
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_date_report_result(self):
report = self.env["report.stock.inventory.valuation.report"].create(
{
"company_id": self.company_id.id,
"compute_at_date": 0,
"compute_at_date": "0",
}
)
product_row = report.results.filtered(lambda r: r.name == product.name)
Expand All @@ -222,7 +222,7 @@ def test_date_report_result(self):
report = self.env["report.stock.inventory.valuation.report"].create(
{
"company_id": self.company_id.id,
"compute_at_date": 1,
"compute_at_date": "1",
"date": date_with_stock,
}
)
Expand Down
Loading

0 comments on commit d0e8b42

Please sign in to comment.