diff --git a/stock_card_report/README.rst b/stock_card_report/README.rst new file mode 100644 index 0000000..243d96b --- /dev/null +++ b/stock_card_report/README.rst @@ -0,0 +1,82 @@ +================= +Stock Card 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-AGPL--3-blue.png + :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_card_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_card_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| + +Stock Card Report is the report that display movement (in/out) of a product in a specified location and date range. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to Inventory > Reporting > Stock Card. +#. Select Start date, End date, Products, Location. +#. Choose View or Export PDF or Export XLSX or Cancel. + +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 +~~~~~~~ + +* Ecosoft + +Contributors +~~~~~~~~~~~~ + +* Pimolnat Suntian + +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_card_report/__init__.py b/stock_card_report/__init__.py new file mode 100644 index 0000000..2873ef6 --- /dev/null +++ b/stock_card_report/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import wizard +from . import reports diff --git a/stock_card_report/__manifest__.py b/stock_card_report/__manifest__.py new file mode 100644 index 0000000..bead020 --- /dev/null +++ b/stock_card_report/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Stock Card Report', + 'summary': 'Add stock card report on Inventory Reporting.', + 'version': '12.0.1.0.0', + 'category': 'Warehouse', + 'website': 'https://github.com/OCA/stock-logistics-reporting', + 'author': 'Ecosoft,Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'depends': [ + 'stock', + 'date_range', + 'report_xlsx_helper', + ], + 'data': [ + 'data/paper_format.xml', + 'data/report_data.xml', + 'reports/stock_card_report.xml', + 'wizard/stock_card_report_wizard_view.xml', + ], + 'installable': True, +} diff --git a/stock_card_report/data/paper_format.xml b/stock_card_report/data/paper_format.xml new file mode 100644 index 0000000..163c384 --- /dev/null +++ b/stock_card_report/data/paper_format.xml @@ -0,0 +1,19 @@ + + + + Stock Card A4 + + A4 + 0 + 0 + Portrait + 28 + 28 + 7 + 7 + + 24 + 90 + + + diff --git a/stock_card_report/data/report_data.xml b/stock_card_report/data/report_data.xml new file mode 100644 index 0000000..55b5cbd --- /dev/null +++ b/stock_card_report/data/report_data.xml @@ -0,0 +1,26 @@ + + + + Stock Card Report + stock_card_report_backend + + + + + + + + diff --git a/stock_card_report/readme/CONTRIBUTORS.rst b/stock_card_report/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..0ef1f84 --- /dev/null +++ b/stock_card_report/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Pimolnat Suntian diff --git a/stock_card_report/readme/DESCRIPTION.rst b/stock_card_report/readme/DESCRIPTION.rst new file mode 100644 index 0000000..1d5fcb2 --- /dev/null +++ b/stock_card_report/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Stock Card Report is the report that display movement (in/out) of a product in a specified location and date range. diff --git a/stock_card_report/readme/USAGE.rst b/stock_card_report/readme/USAGE.rst new file mode 100644 index 0000000..cce04a4 --- /dev/null +++ b/stock_card_report/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module, you need to: + +#. Go to Inventory > Reporting > Stock Card. +#. Select Start date, End date, Products, Location. +#. Choose View or Export PDF or Export XLSX or Cancel. diff --git a/stock_card_report/reports/__init__.py b/stock_card_report/reports/__init__.py new file mode 100644 index 0000000..0bf3b7a --- /dev/null +++ b/stock_card_report/reports/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import stock_card_report +from . import stock_card_report_xlsx diff --git a/stock_card_report/reports/stock_card_report.py b/stock_card_report/reports/stock_card_report.py new file mode 100644 index 0000000..694173a --- /dev/null +++ b/stock_card_report/reports/stock_card_report.py @@ -0,0 +1,109 @@ +# Copyright 2019 Ecosoft Co., Ltd. (http://ecosoft.co.th) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class StockCardView(models.TransientModel): + _name = 'stock.card.view' + _description = 'Stock Card View' + _order = 'date' + + date = fields.Datetime() + product_id = fields.Many2one(comodel_name='product.product') + product_qty = fields.Float() + product_uom_qty = fields.Float() + product_uom = fields.Many2one(comodel_name='uom.uom') + reference = fields.Char() + location_id = fields.Many2one(comodel_name='stock.location') + location_dest_id = fields.Many2one(comodel_name='stock.location') + is_initial = fields.Boolean() + product_in = fields.Float() + product_out = fields.Float() + + +class StockCardReport(models.TransientModel): + _name = 'report.stock.card.report' + _description = 'Stock Card Report' + + # Filters fields, used for data computation + date_from = fields.Date() + date_to = fields.Date() + product_ids = fields.Many2many( + comodel_name='product.product', + ) + location_id = fields.Many2one( + comodel_name='stock.location', + ) + + # Data fields, used to browse report data + results = fields.Many2many( + comodel_name='stock.card.view', + compute='_compute_results', + help='Use compute fields, so there is nothing store in database', + ) + + @api.multi + def _compute_results(self): + self.ensure_one() + change = False + if not self.date_from: + change = True + self.date_from = '0001-01-01' + if not self.date_to: + self.date_to = fields.Date.context_today(self) + locations = self.env['stock.location'].search( + [('id', 'child_of', [self.location_id.id])]) + self._cr.execute(""" + SELECT move.date, move.product_id, move.product_qty, + move.product_uom_qty, move.product_uom, move.reference, + move.location_id, move.location_dest_id, + case when move.location_dest_id in %s + then move.product_qty end as product_in, + case when move.location_id in %s + then move.product_qty end as product_out, + case when move.date < %s then True else False end as is_initial + FROM stock_move move + WHERE (move.location_id in %s or move.location_dest_id in %s) + and move.state = 'done' and move.product_id in %s + and CAST(move.date AS date) <= %s + ORDER BY move.date, move.reference + """, ( + tuple(locations.ids), tuple(locations.ids), self.date_from, + tuple(locations.ids), tuple(locations.ids), + tuple(self.product_ids.ids+[0]), self.date_to)) + stock_card_results = self._cr.dictfetchall() + ReportLine = self.env['stock.card.view'] + for line in stock_card_results: + self.results += ReportLine.new(line) + if change: + self.date_from = not change + + @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 = report_type == 'xlsx' and self.env.ref( + 'stock_card_report.action_stock_card_report_xlsx') or \ + self.env.ref('stock_card_report.action_stock_card_report_pdf') + return action.report_action(self, config=False) + + def _get_html(self): + result = {} + rcontext = {} + report = self.browse(self._context.get('active_id')) + if report: + rcontext['o'] = report + result['html'] = self.env.ref( + 'stock_card_report.report_stock_card_report_html').render( + rcontext) + return result + + @api.model + def get_html(self, given_context=None): + return self.with_context(given_context)._get_html() diff --git a/stock_card_report/reports/stock_card_report.xml b/stock_card_report/reports/stock_card_report.xml new file mode 100644 index 0000000..2b08f79 --- /dev/null +++ b/stock_card_report/reports/stock_card_report.xml @@ -0,0 +1,144 @@ + + +