From fa9e7cb1e398ac6326977cc792a0489b9209027e Mon Sep 17 00:00:00 2001 From: Andrey Solodovnikov Date: Tue, 17 Oct 2023 13:07:31 +0300 Subject: [PATCH] [MIG] stock_inventory_valuation_report: Migration to 14.0 Co-authored-by: dessanhemrayev Co-authored-by: Alessandro Uffreduzzi --- stock_inventory_valuation_report/README.rst | 24 ++- .../__manifest__.py | 4 +- ...{paper_format.xml => paperformat_data.xml} | 1 + .../data/report_data.xml | 33 --- .../readme/CONTRIBUTORS.rst | 8 +- .../readme/USAGE.rst | 4 +- .../stock_inventory_valuation_report.py | 86 ++++---- .../stock_inventory_valuation_report.xml | 53 ++++- .../stock_inventory_valuation_report_xlsx.py | 37 ++-- .../security/ir.model.access.csv | 4 + .../static/description/index.html | 38 +++- ...tock_inventory_valuation_report_backend.js | 24 ++- .../test_stock_inventory_valuation_report.py | 192 ++++++++++-------- .../wizard/stock_quantity_history.py | 35 ++-- .../wizard/stock_quantity_history_view.xml | 16 +- 15 files changed, 331 insertions(+), 228 deletions(-) rename stock_inventory_valuation_report/data/{paper_format.xml => paperformat_data.xml} (94%) delete mode 100644 stock_inventory_valuation_report/data/report_data.xml create mode 100644 stock_inventory_valuation_report/security/ir.model.access.csv diff --git a/stock_inventory_valuation_report/README.rst b/stock_inventory_valuation_report/README.rst index badf7a2c1..9ad3b0b6d 100644 --- a/stock_inventory_valuation_report/README.rst +++ b/stock_inventory_valuation_report/README.rst @@ -7,7 +7,7 @@ Stock Inventory Valuation Report !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:f52dbe5b051ec99d9ee7a63c214cf404ccafa168d8be97ae1d9af05ce83951f2 + !! source digest: sha256:7e81cc55bfaa7140318103e270fb5e41e7ee0ab5c82d8ce7ae587f6586adafa0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ Stock Inventory Valuation Report :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--reporting-lightgray.png?logo=github - :target: https://github.com/OCA/stock-logistics-reporting/tree/12.0/stock_inventory_valuation_report + :target: https://github.com/OCA/stock-logistics-reporting/tree/14.0/stock_inventory_valuation_report :alt: OCA/stock-logistics-reporting .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-12-0/stock-logistics-reporting-12-0-stock_inventory_valuation_report + :target: https://translation.odoo-community.org/projects/stock-logistics-reporting-14-0/stock-logistics-reporting-14-0-stock_inventory_valuation_report :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-reporting&target_branch=12.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-reporting&target_branch=14.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -41,8 +41,8 @@ Usage To use this module, you need to: #. Go to Inventory > Reporting > Inventory Valuation. -#. Select Compute (Current Inventory or At a Specific Date). -#. Choose Retrieve the inventory valuation or View report or Export PDF or Export XLSX or Cancel. +#. Select Inventory At Date. +#. You can now choose a few additional options: "View report", "Export PDF" and "Export XLSX". Bug Tracker =========== @@ -50,7 +50,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -65,7 +65,13 @@ Authors Contributors ~~~~~~~~~~~~ -* Pimolnat Suntian +* `Pimolnat Suntian `_ +* `Ooops404 `_ + * `Francesco Foresti `_ +* `Cetmix `_ + * `Andrey Solodovnikov `_ +* `PyTech SRL `_ + * `Alessandro Uffreduzzi `_ Maintainers ~~~~~~~~~~~ @@ -80,6 +86,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/stock-logistics-reporting `_ project on GitHub. +This module is part of the `OCA/stock-logistics-reporting `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_inventory_valuation_report/__manifest__.py b/stock_inventory_valuation_report/__manifest__.py index 22e4b8c17..6e6f33ec5 100644 --- a/stock_inventory_valuation_report/__manifest__.py +++ b/stock_inventory_valuation_report/__manifest__.py @@ -14,8 +14,8 @@ "report_xlsx_helper", ], "data": [ - "data/paper_format.xml", - "data/report_data.xml", + "data/paperformat_data.xml", + "security/ir.model.access.csv", "reports/stock_inventory_valuation_report.xml", "wizard/stock_quantity_history_view.xml", ], diff --git a/stock_inventory_valuation_report/data/paper_format.xml b/stock_inventory_valuation_report/data/paperformat_data.xml similarity index 94% rename from stock_inventory_valuation_report/data/paper_format.xml rename to stock_inventory_valuation_report/data/paperformat_data.xml index 68f416e64..fdcb1853f 100644 --- a/stock_inventory_valuation_report/data/paper_format.xml +++ b/stock_inventory_valuation_report/data/paperformat_data.xml @@ -1,3 +1,4 @@ + diff --git a/stock_inventory_valuation_report/data/report_data.xml b/stock_inventory_valuation_report/data/report_data.xml deleted file mode 100644 index 7abb53e63..000000000 --- a/stock_inventory_valuation_report/data/report_data.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - Inventory Valuation Report - stock_inventory_valuation_report_backend - - - - - - - - diff --git a/stock_inventory_valuation_report/readme/CONTRIBUTORS.rst b/stock_inventory_valuation_report/readme/CONTRIBUTORS.rst index 0ef1f84c3..6ac0c2c23 100644 --- a/stock_inventory_valuation_report/readme/CONTRIBUTORS.rst +++ b/stock_inventory_valuation_report/readme/CONTRIBUTORS.rst @@ -1 +1,7 @@ -* Pimolnat Suntian +* `Pimolnat Suntian `_ +* `Ooops404 `_ + * `Francesco Foresti `_ +* `Cetmix `_ + * `Andrey Solodovnikov `_ +* `PyTech SRL `_ + * `Alessandro Uffreduzzi `_ diff --git a/stock_inventory_valuation_report/readme/USAGE.rst b/stock_inventory_valuation_report/readme/USAGE.rst index dfa51ab58..43979a164 100644 --- a/stock_inventory_valuation_report/readme/USAGE.rst +++ b/stock_inventory_valuation_report/readme/USAGE.rst @@ -1,5 +1,5 @@ To use this module, you need to: #. Go to Inventory > Reporting > Inventory Valuation. -#. Select Compute (Current Inventory or At a Specific Date). -#. Choose Retrieve the inventory valuation or View report or Export PDF or Export XLSX or Cancel. +#. Select Inventory At Date. +#. You can now choose a few additional options: "View report", "Export PDF" and "Export XLSX". diff --git a/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.py b/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.py index f0c2b47f6..38dac0d91 100644 --- a/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.py +++ b/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.py @@ -2,12 +2,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.osv import expression class StockInventoryValuationView(models.TransientModel): _name = "stock.inventory.valuation.view" _description = "Stock Inventory Valuation View" + report_id = fields.Many2one("report.stock.inventory.valuation.report") + name = fields.Char() reference = fields.Char() barcode = fields.Char() @@ -34,62 +37,73 @@ class StockInventoryValuationReport(models.TransientModel): company_id = fields.Many2one( comodel_name="res.company", ) - compute_at_date = fields.Integer() - date = fields.Datetime() + inventory_datetime = fields.Datetime(required=True, default=fields.Datetime.now) - # Data fields, used to browse report data - results = fields.Many2many( + results = fields.One2many( comodel_name="stock.inventory.valuation.view", + inverse_name="report_id", compute="_compute_results", - help="Use compute fields, so there is nothing store in database", ) - @api.multi + @api.depends("inventory_datetime") def _compute_results(self): + """ + Generate report lines, one per product present at the time + """ self.ensure_one() - if not self.compute_at_date: - self.date = fields.Datetime.now() + domain = [("type", "=", "product")] + product_id = self.env.context.get("product_id") + product_tmpl_id = self.env.context.get("product_tmpl_id") + if product_id: + domain = expression.AND([domain, [("id", "=", product_id)]]) + elif product_tmpl_id: + domain = expression.AND( + [domain, [("product_tmpl_id", "=", product_tmpl_id)]] + ) products = ( self.env["product.product"] .with_context( - dict(to_date=self.date, company_owned=True, create=False, edit=False) + to_date=self.inventory_datetime, + company_owned=True, + create=False, + edit=False, ) - .search([("type", "=", "product"), ("qty_available", "!=", 0)]) - ) - 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, - "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, - "cost_method": product.cost_method, - } - if product.qty_at_date != 0: - self.results += ReportLine.new(line) + .search(domain) + # 'quantity_svl' is not stored, can't be used in search + ).filtered(lambda pp: pp.quantity_svl != 0) + if products: + vals = [ + { + "name": product.name, + "reference": product.default_code, + "barcode": product.barcode, + "qty_at_date": product.quantity_svl, + "uom_id": product.uom_id, + "currency_id": product.currency_id, + "cost_currency_id": product.cost_currency_id, + "standard_price": product.standard_price, + "stock_value": product.value_svl, + "cost_method": product.cost_method, + } + for product in products + ] + self.results = self.env["stock.inventory.valuation.view"].create(vals) + else: + self.results = False - @api.multi def print_report(self, report_type="qweb"): self.ensure_one() action = ( report_type == "xlsx" and self.env.ref( "stock_inventory_valuation_report." - "action_stock_inventory_valuation_report_xlsx" + "action_stock_inventory_valuation_report_xlsx", + raise_if_not_found=False, ) or self.env.ref( "stock_inventory_valuation_report." - "action_stock_inventory_valuation_report_pdf" + "action_stock_inventory_valuation_report_pdf", + raise_if_not_found=False, ) ) return action.report_action(self, config=False) @@ -103,7 +117,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 diff --git a/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.xml b/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.xml index 6b46cd4e8..d3701249c 100644 --- a/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.xml +++ b/stock_inventory_valuation_report/reports/stock_inventory_valuation_report.xml @@ -1,5 +1,56 @@ + + + Inventory Valuation Report + stock_inventory_valuation_report_backend + + + + + Stock Inventory Valuation Report PDF + report.stock.inventory.valuation.report + qweb-pdf + stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf + stock_inventory_valuation_report.report_stock_inventory_valuation_report_pdf + 'Inventory Valuation Report - [%s]' % object.inventory_datetime + + report + + + + + Stock Inventory Valuation Report XLSX + report.stock.inventory.valuation.report + xlsx + s_i_v_r.report_stock_inventory_valuation_report_xlsx + Inventory Valuation Report + + report + False + + +