From 54508caee557cbda31c8fc38d9f1572dddbaa1ae Mon Sep 17 00:00:00 2001 From: lreficent Date: Tue, 10 Oct 2017 11:52:25 +0200 Subject: [PATCH] [9.0][IMP] stock_cycle_count: basic_accuracy report --- stock_cycle_count/__init__.py | 1 + stock_cycle_count/__openerp__.py | 4 +- stock_cycle_count/reports/__init__.py | 4 + .../reports/report_stock_location_accuracy.py | 38 ++++++++++ .../stock_location_accuracy_report.xml | 73 +++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 stock_cycle_count/reports/__init__.py create mode 100644 stock_cycle_count/reports/report_stock_location_accuracy.py create mode 100644 stock_cycle_count/reports/stock_location_accuracy_report.xml diff --git a/stock_cycle_count/__init__.py b/stock_cycle_count/__init__.py index 08f93b3a4..f1ca255e7 100644 --- a/stock_cycle_count/__init__.py +++ b/stock_cycle_count/__init__.py @@ -4,3 +4,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from . import models +from . import reports diff --git a/stock_cycle_count/__openerp__.py b/stock_cycle_count/__openerp__.py index 89bd88823..9108ded83 100644 --- a/stock_cycle_count/__openerp__.py +++ b/stock_cycle_count/__openerp__.py @@ -26,7 +26,9 @@ 'views/stock_location_view.xml', 'data/cycle_count_sequence.xml', 'data/cycle_count_ir_cron.xml', - 'security/ir.model.access.csv'], + 'reports/stock_location_accuracy_report.xml', + 'security/ir.model.access.csv', + ], "license": "AGPL-3", 'installable': True, 'application': False, diff --git a/stock_cycle_count/reports/__init__.py b/stock_cycle_count/reports/__init__.py new file mode 100644 index 000000000..97c997be9 --- /dev/null +++ b/stock_cycle_count/reports/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import report_stock_location_accuracy diff --git a/stock_cycle_count/reports/report_stock_location_accuracy.py b/stock_cycle_count/reports/report_stock_location_accuracy.py new file mode 100644 index 000000000..f2807da1b --- /dev/null +++ b/stock_cycle_count/reports/report_stock_location_accuracy.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services S.L. +# (http://www.eficent.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models + + +class LocationAccuracyReport(models.AbstractModel): + _name = "report.stock_location_accuracy" + + @api.model + def _get_inventory_domain(self, loc_id): + return [('location_id', '=', loc_id), + ('exclude_sublocation', '=', True), + ('state', '=', 'done')] + + @api.model + def _get_location_data(self, locations): + data = dict() + inventory_obj = self.env["stock.inventory"] + for loc in locations: + counts = inventory_obj.search(self._get_inventory_domain(loc.id)) + data[loc] = counts + return data + + @api.multi + def render_html(self, data=None): + report_obj = self.env["report"] + locs = self.env["stock.location"].browse(self._ids) + data = self._get_location_data(locs) + docargs = { + "doc_ids": locs._ids, + "docs": locs, + "data": data, + } + return report_obj.render( + "stock_cycle_count.stock_location_accuracy", docargs) diff --git a/stock_cycle_count/reports/stock_location_accuracy_report.xml b/stock_cycle_count/reports/stock_location_accuracy_report.xml new file mode 100644 index 000000000..2db18f471 --- /dev/null +++ b/stock_cycle_count/reports/stock_location_accuracy_report.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + +