diff --git a/stock_kardex_report/README.rst b/stock_kardex_report/README.rst new file mode 100644 index 0000000..ed01c0f --- /dev/null +++ b/stock_kardex_report/README.rst @@ -0,0 +1,102 @@ +=================== +Stock Kardex Report +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-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_kardex_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_kardex_report + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/151/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This report shows the stock of a product in a specific location in a defined time period. + +If I ask a report for Product A from 01-01-2020 to 03-01-2020 in location WH/Stock + +The report will be the following + ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product | Date | Description | Origin | Destination | Qty | Balance | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 01-01-2020 12:00:00 | Initial Balance | | | 100 | 100 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 12:00:00 | PO001 | Vendors | WH/Stock | 100 | 200 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 14:00:00 | SO001 | WH/Stock | Customers | -50 | 150 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 16:30:00 | SO002 | WH/Stock | Customers | -75 | 75 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 03-01-2020 12:00:00 | PO002 | Vendors | WH/Stock | 100 | 175 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To get the stock kardex report: + +#. Go to Inventory/Reports/Stock Kardex Report +#. A wizard will open; select the product, location and date range to generate the report. +#. Click on *Retrieve Kardex Report* button. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Jarsa + +Contributors +~~~~~~~~~~~~ + +* `Jarsa Sistemas, S.A. de C.V. `_: + + * Juventino Villegas + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_kardex_report/__init__.py b/stock_kardex_report/__init__.py new file mode 100644 index 0000000..e53d29a --- /dev/null +++ b/stock_kardex_report/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lpgl.html). + +from . import models +from . import wizard diff --git a/stock_kardex_report/__manifest__.py b/stock_kardex_report/__manifest__.py new file mode 100644 index 0000000..b6999d0 --- /dev/null +++ b/stock_kardex_report/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lpgl.html). + +{ + 'name': 'Stock Kardex Report', + 'summary': 'Generate Kardex Report', + 'version': '12.0.1.0.0', + 'category': 'Reports', + 'author': 'Jarsa,' + 'Odoo Community Association (OCA)', + 'website': "https://github.com/OCA/stock-logistics-reporting", + 'license': 'LGPL-3', + 'depends': [ + 'stock', + ], + 'data': [ + 'views/stock_kardex_report_views.xml', + 'wizard/stock_kardex_report_wizard_view.xml', + 'security/ir.model.access.csv', + ], +} diff --git a/stock_kardex_report/models/__init__.py b/stock_kardex_report/models/__init__.py new file mode 100644 index 0000000..97d125a --- /dev/null +++ b/stock_kardex_report/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lpgl.html). + +from . import stock_kardex_report diff --git a/stock_kardex_report/models/stock_kardex_report.py b/stock_kardex_report/models/stock_kardex_report.py new file mode 100644 index 0000000..3a24222 --- /dev/null +++ b/stock_kardex_report/models/stock_kardex_report.py @@ -0,0 +1,23 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import fields, models + + +class StockKardexReport(models.Model): + _name = 'stock.kardex.report' + _description = 'This model creates a kardex report for stock moves' + _order = 'date desc' + + move_id = fields.Many2one('stock.move', readonly=True) + product_id = fields.Many2one('product.product', readonly=True) + product_uom_id = fields.Many2one('uom.uom', readonly=True) + lot_id = fields.Many2one('stock.production.lot', readonly=True) + owner_id = fields.Many2one('res.partner', readonly=True) + package_id = fields.Many2one('stock.quant.package', readonly=True) + location_id = fields.Many2one('stock.location', readonly=True) + location_dest_id = fields.Many2one('stock.location', readonly=True) + qty_done = fields.Float('Done', readonly=True) + date = fields.Datetime(readonly=True) + origin = fields.Char(readonly=True) + balance = fields.Float(readonly=True) diff --git a/stock_kardex_report/readme/CONTRIBUTORS.rst b/stock_kardex_report/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..dcb5709 --- /dev/null +++ b/stock_kardex_report/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Jarsa Sistemas, S.A. de C.V. `_: + + * Juventino Villegas diff --git a/stock_kardex_report/readme/DESCRIPTION.rst b/stock_kardex_report/readme/DESCRIPTION.rst new file mode 100644 index 0000000..6f3f9b6 --- /dev/null +++ b/stock_kardex_report/readme/DESCRIPTION.rst @@ -0,0 +1,19 @@ +This report shows the stock of a product in a specific location in a defined time period. + +If I ask a report for Product A from 01-01-2020 to 03-01-2020 in location WH/Stock + +The report will be the following + ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product | Date | Description | Origin | Destination | Qty | Balance | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 01-01-2020 12:00:00 | Initial Balance | | | 100 | 100 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 12:00:00 | PO001 | Vendors | WH/Stock | 100 | 200 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 14:00:00 | SO001 | WH/Stock | Customers | -50 | 150 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 02-01-2020 16:30:00 | SO002 | WH/Stock | Customers | -75 | 75 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ +| Product A | 03-01-2020 12:00:00 | PO002 | Vendors | WH/Stock | 100 | 175 | ++-----------+---------------------+-----------------+----------+-------------+-----+---------+ diff --git a/stock_kardex_report/readme/USAGE.rst b/stock_kardex_report/readme/USAGE.rst new file mode 100644 index 0000000..d9f6ef9 --- /dev/null +++ b/stock_kardex_report/readme/USAGE.rst @@ -0,0 +1,5 @@ +To get the stock kardex report: + +#. Go to Inventory/Reports/Stock Kardex Report +#. A wizard will open; select the product, location and date range to generate the report. +#. Click on *Retrieve Kardex Report* button. diff --git a/stock_kardex_report/security/ir.model.access.csv b/stock_kardex_report/security/ir.model.access.csv new file mode 100644 index 0000000..eef3541 --- /dev/null +++ b/stock_kardex_report/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_stock_kardex_report_user,access_stock_kardex_report_user,model_stock_kardex_report,stock.group_stock_user,1,1,1,1 diff --git a/stock_kardex_report/static/description/index.html b/stock_kardex_report/static/description/index.html new file mode 100644 index 0000000..716f68e --- /dev/null +++ b/stock_kardex_report/static/description/index.html @@ -0,0 +1,495 @@ + + + + + + +Stock Kardex Report + + + +
+

Stock Kardex Report

+ + +

Beta License: LGPL-3 OCA/stock-logistics-reporting Translate me on Weblate Try me on Runbot

+

This report shows the stock of a product in a specific location in a defined time period.

+

If I ask a report for Product A from 01-01-2020 to 03-01-2020 in location WH/Stock

+

The report will be the following

+ +++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ProductDateDescriptionOriginDestinationQtyBalance
Product A01-01-2020 12:00:00Initial Balance  100100
Product A02-01-2020 12:00:00PO001VendorsWH/Stock100200
Product A02-01-2020 14:00:00SO001WH/StockCustomers-50150
Product A02-01-2020 16:30:00SO002WH/StockCustomers-7575
Product A03-01-2020 12:00:00PO002VendorsWH/Stock100175
+

Table of contents

+ +
+

Usage

+

To get the stock kardex report:

+
    +
  1. Go to Inventory/Reports/Stock Kardex Report
  2. +
  3. A wizard will open; select the product, location and date range to generate the report.
  4. +
  5. Click on Retrieve Kardex Report button.
  6. +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Jarsa
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/stock_kardex_report/views/stock_kardex_report_views.xml b/stock_kardex_report/views/stock_kardex_report_views.xml new file mode 100644 index 0000000..4d3eada --- /dev/null +++ b/stock_kardex_report/views/stock_kardex_report_views.xml @@ -0,0 +1,21 @@ + + + stock.kardex.report.tree + stock.kardex.report + + + + + + + + + + + + + + + + + diff --git a/stock_kardex_report/wizard/__init__.py b/stock_kardex_report/wizard/__init__.py new file mode 100644 index 0000000..27433fc --- /dev/null +++ b/stock_kardex_report/wizard/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lpgl.html). + +from . import stock_kardex_report_wizard diff --git a/stock_kardex_report/wizard/stock_kardex_report_wizard.py b/stock_kardex_report/wizard/stock_kardex_report_wizard.py new file mode 100644 index 0000000..1a1f42e --- /dev/null +++ b/stock_kardex_report/wizard/stock_kardex_report_wizard.py @@ -0,0 +1,139 @@ +# Copyright 2020, Jarsa Sistemas, S.A. de C.V. +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from odoo import _, fields, models +import textwrap + + +class StockKardexReportWiz(models.TransientModel): + _name = 'stock.kardex.report.wiz' + _description = 'Wizard to create kardex reports of stock moves' + + date_from = fields.Datetime( + string='From', required=True, default=fields.Datetime.now) + date_to = fields.Datetime( + string='To', required=True, default=fields.Datetime.now) + product = fields.Many2one('product.product', required=True) + location = fields.Many2one('stock.location', required=True) + + def open_table(self): + self.env['stock.kardex.report'].search([]).unlink() + self._cr.execute(''' + SELECT + a.done - b.done + AS + total + FROM + ( + SELECT sum(qty_done) + AS + done + FROM + stock_move_line + WHERE + product_id = %s + AND + state = \'done\' + AND + date < %s + AND + location_dest_id = %s + ) + a + CROSS JOIN + ( + SELECT sum(qty_done) + AS + done + FROM + stock_move_line + WHERE + product_id = %s + AND + state = \'done\' + AND + date < %s + AND + location_id = %s + ) + b + ''', [ + self.product.id, self.date_from, self.location.id, + self.product.id, self.date_from, self.location.id + ]) + start_qty = self._cr.dictfetchall() + total = 0 + if start_qty[0]['total']: + total = start_qty[0]['total'] + self._cr.execute("""WITH one AS ( + SELECT + sml.product_id, sml.product_uom_id, + sml.lot_id, sml.owner_id, sml.package_id, + sml.qty_done, sml.move_id, sml.location_id, + sml.location_dest_id, sm.date, sm.origin, + sm.state + FROM stock_move_line sml + INNER JOIN stock_move sm + ON sml.move_id = sm.id + WHERE + sm.date >= %s + AND sm.date <= %s), + two AS ( + SELECT * + FROM one + WHERE location_id = %s + OR location_dest_id = %s) + SELECT * + FROM two + WHERE product_id = %s + AND state = 'done' + ORDER BY date;""", [ + self.date_from, self.date_to, + self.location.id, self.location.id, + self.product.id + ]) + moves = self._cr.dictfetchall() + report_list = [] + report_list.append({ + 'product_id': self.product.id, + 'qty_done': 0, + 'date': self.date_from, + 'origin': _('Initial Balance'), + 'balance': total, + }) + for rec in moves: + done_qty = rec['qty_done'] + if rec['location_id'] == self.location.id: + done_qty = -rec['qty_done'] + total += done_qty + origin = rec['origin'] + if origin: + origin = textwrap.shorten( + rec['origin'], width=80, placeholder="...") + line = { + 'move_id': rec['move_id'], + 'product_id': rec['product_id'], + 'product_uom_id': rec['product_uom_id'], + 'lot_id': rec['lot_id'], + 'owner_id': rec['owner_id'], + 'package_id': rec['package_id'], + 'qty_done': done_qty, + 'location_id': rec['location_id'], + 'location_dest_id': rec['location_dest_id'], + 'date': rec['date'], + 'balance': total, + 'origin': origin, + } + report_list.append(line) + self.env['stock.kardex.report'].create(report_list) + tree_view_id = self.env.ref( + 'stock_kardex_report.stock_kardex_report_tree_view').id + action = { + 'type': 'ir.actions.act_window', + 'views': [(tree_view_id, 'tree')], + 'view_id': tree_view_id, + 'view_mode': 'tree', + 'name': _('Stock Report'), + 'res_model': 'stock.kardex.report', + } + return action diff --git a/stock_kardex_report/wizard/stock_kardex_report_wizard_view.xml b/stock_kardex_report/wizard/stock_kardex_report_wizard_view.xml new file mode 100644 index 0000000..b2db033 --- /dev/null +++ b/stock_kardex_report/wizard/stock_kardex_report_wizard_view.xml @@ -0,0 +1,34 @@ + + + Inventory Kardex Report + stock.kardex.report.wiz + +
+ + + + + + + + +
+
+
+
+
+ + + Stock Kardex Report + stock.kardex.report.wiz + form + form + + new + + + + +