diff --git a/stock_picking_auto_print/README.rst b/stock_picking_auto_print/README.rst new file mode 100644 index 0000000..ef913b9 --- /dev/null +++ b/stock_picking_auto_print/README.rst @@ -0,0 +1,97 @@ +============ +Direct Print +============ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Freport--print--send-lightgray.png?logo=github + :target: https://github.com/OCA/report-print-send/tree/11.0/stock_picking_auto_print + :alt: OCA/report-print-send +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/report-print-send-11-0/report-print-send-11-0-stock_picking_auto_print + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/144/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +* Active developer mode. Go to Technical > Actions > Reports +* Edit report with following fields. + + * Is Default Report? + * Country and + * Company + +Usage +===== + +* Create a sale order and confirm it. +* If delivery order state is ready, the direct print goes to printer. +* As per above configuration, it will find report and send to direct printer. + +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 +~~~~~~~ + +* Open Source Integrators + +Contributors +~~~~~~~~~~~~ + +* Bhavesh Odedra +* Balaji Kannan + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* Open Source Integrators + +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/report-print-send `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_picking_auto_print/__init__.py b/stock_picking_auto_print/__init__.py new file mode 100644 index 0000000..f1ef241 --- /dev/null +++ b/stock_picking_auto_print/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2019 IBM Corp. +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/stock_picking_auto_print/__manifest__.py b/stock_picking_auto_print/__manifest__.py new file mode 100644 index 0000000..5255e8a --- /dev/null +++ b/stock_picking_auto_print/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright (C) 2019 IBM Corp. +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Direct Print', + 'summary': 'Auto print when DO is ready', + 'version': '11.0.1.0.0', + 'license': 'AGPL-3', + 'author': 'Open Source Integrators, Odoo Community Association (OCA)', + 'category': 'Generic Modules/Base', + 'website': 'http://www.opensourceintegrators.com', + 'depends': [ + 'stock', + 'sale_stock', + 'base_report_to_printer', + ], + 'data': [ + 'views/ir_action_report_view.xml' + ], + 'installable': True, +} diff --git a/stock_picking_auto_print/models/__init__.py b/stock_picking_auto_print/models/__init__.py new file mode 100644 index 0000000..e97d207 --- /dev/null +++ b/stock_picking_auto_print/models/__init__.py @@ -0,0 +1,6 @@ +# Copyright (C) 2019 IBM Corp. +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import stock_picking +from . import ir_actions_report diff --git a/stock_picking_auto_print/models/ir_actions_report.py b/stock_picking_auto_print/models/ir_actions_report.py new file mode 100644 index 0000000..88dabc7 --- /dev/null +++ b/stock_picking_auto_print/models/ir_actions_report.py @@ -0,0 +1,13 @@ +# Copyright (C) 2019 IBM Corp. +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + is_default_report = fields.Boolean('Is Default Report?') + country_id = fields.Many2one('res.country', string='Country') + company_id = fields.Many2one('res.company', string='Company') diff --git a/stock_picking_auto_print/models/stock_picking.py b/stock_picking_auto_print/models/stock_picking.py new file mode 100644 index 0000000..9227122 --- /dev/null +++ b/stock_picking_auto_print/models/stock_picking.py @@ -0,0 +1,139 @@ +# Copyright (C) 2019 IBM Corp. +# Copyright (C) 2019 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + @api.multi + def write(self, vals): + res = super(StockPicking, self).write(vals) + if 'date_done' in vals: + user_company_id = self.env.user.company_id.id + report_action_pool = self.env['ir.actions.report'] + for picking in self.filtered(lambda p: p.sale_id): + # Find next picking and it's state + sale_picking_ids = picking.sale_id.picking_ids.filtered( + lambda p: p.state != 'done') + for sp in sale_picking_ids: + if sp.state == 'assigned': + default_report_id = False + # Find picking defaults reports + default_report_ids = report_action_pool.search( + [('model', '=', 'stock.picking'), + ('is_default_report', '=', True)]).ids + # Check Partner country id + country_id = False + if sp.partner_id.country_id: + country_id = sp.partner_id.country_id.id + + if default_report_ids: + # Filter report with Country and Company + report_ids = report_action_pool.search( + [('country_id', '=', country_id), + ('company_id', '=', user_company_id), + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + if not default_report_id: + # Filter report with Company + report_ids = report_action_pool.search( + [('company_id', '=', user_company_id), + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + if not default_report_id and country_id: + # Filter report with Country + report_ids = report_action_pool.search( + [('country_id', '=', country_id), + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + if not default_report_id: + default_report_id = self.env.ref( + 'stock.action_report_picking').with_context( + landscape=True).report_action(sp).get('id') + action_report = report_action_pool.browse( + default_report_id) + + try: + action_report.print_document(sp.id) + except: + pass + return res + + @api.multi + def action_assign(self): + res = super(StockPicking, self).action_assign() + user_company_id = self.env.user.company_id.id + report_action_pool = self.env['ir.actions.report'] + for picking in self: + if (picking.picking_type_code == 'outgoing' or + picking.location_dest_id.name == 'Output') and \ + picking.state == 'assigned': + default_report_id = False + + # Find picking defaults reports + default_report_ids = report_action_pool.search( + [('model', '=', 'stock.picking'), + ('is_default_report', '=', True)]).ids + + # defaults are configured + if default_report_ids: + # Find country id + country_id = False + if picking.partner_id.country_id: + country_id = picking.partner_id.country_id.id + + # Filter report with Country and Company + report_ids = report_action_pool.search( + [('country_id', '=', country_id), + ('company_id', '=', user_company_id), + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + # just look for company record without a country + if not default_report_id: + # Filter report with Company and no country + report_ids = report_action_pool.search( + [('country_id', '=', False), + ('company_id', '=', user_company_id), + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + # just look for a country report without company + if not default_report_id and country_id: + # Filter report with Country + report_ids = report_action_pool.search( + [('country_id', '=', country_id), + ('company_id', '=', False) + ('id', 'in', default_report_ids)], + limit=1) + if report_ids: + default_report_id = report_ids.id + + # defaults not configured + else: + default_report_id = self.env.ref( + 'stock.action_report_picking').with_context( + landscape=True).report_action(picking).get('id') + action_report = report_action_pool.browse(default_report_id) + + try: + action_report.print_document(picking.id) + except: + pass + return res diff --git a/stock_picking_auto_print/readme/CONFIGURE.rst b/stock_picking_auto_print/readme/CONFIGURE.rst new file mode 100644 index 0000000..13ddcd7 --- /dev/null +++ b/stock_picking_auto_print/readme/CONFIGURE.rst @@ -0,0 +1,6 @@ +* Active developer mode. Go to Technical > Actions > Reports +* Edit report with following fields. + + * Is Default Report? + * Country and + * Company diff --git a/stock_picking_auto_print/readme/CONTRIBUTORS.rst b/stock_picking_auto_print/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..1611a03 --- /dev/null +++ b/stock_picking_auto_print/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Bhavesh Odedra +* Balaji Kannan diff --git a/stock_picking_auto_print/readme/CREDITS.rst b/stock_picking_auto_print/readme/CREDITS.rst new file mode 100644 index 0000000..8209266 --- /dev/null +++ b/stock_picking_auto_print/readme/CREDITS.rst @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +* Open Source Integrators diff --git a/stock_picking_auto_print/readme/DESCRIPTION.rst b/stock_picking_auto_print/readme/DESCRIPTION.rst new file mode 100644 index 0000000..e69de29 diff --git a/stock_picking_auto_print/readme/ROADMAP.rst b/stock_picking_auto_print/readme/ROADMAP.rst new file mode 100644 index 0000000..e69de29 diff --git a/stock_picking_auto_print/readme/USAGE.rst b/stock_picking_auto_print/readme/USAGE.rst new file mode 100644 index 0000000..cbc1587 --- /dev/null +++ b/stock_picking_auto_print/readme/USAGE.rst @@ -0,0 +1,3 @@ +* Create a sale order and confirm it. +* If delivery order state is ready, the direct print goes to printer. +* As per above configuration, it will find report and send to direct printer. diff --git a/stock_picking_auto_print/static/description/icon.png b/stock_picking_auto_print/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/stock_picking_auto_print/static/description/icon.png differ diff --git a/stock_picking_auto_print/static/description/index.html b/stock_picking_auto_print/static/description/index.html new file mode 100644 index 0000000..e725a2c --- /dev/null +++ b/stock_picking_auto_print/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +Direct Print + + + +
+

Direct Print

+ + +

Beta License: AGPL-3 OCA/report-print-send Translate me on Weblate Try me on Runbot

+

Table of contents

+ +
+

Configuration

+
    +
  • Active developer mode. Go to Technical > Actions > Reports

    +
  • +
  • Edit report with following fields.

    +
    +
      +
    • Is Default Report?
    • +
    • Country and
    • +
    • Company
    • +
    +
    +
  • +
+
+
+

Usage

+
    +
  • Create a sale order and confirm it.
  • +
  • If delivery order state is ready, the direct print goes to printer.
  • +
  • As per above configuration, it will find report and send to direct printer.
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
+
+ +
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • Open Source Integrators
  • +
+
+
+

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/report-print-send project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_picking_auto_print/views/ir_action_report_view.xml b/stock_picking_auto_print/views/ir_action_report_view.xml new file mode 100644 index 0000000..870124f --- /dev/null +++ b/stock_picking_auto_print/views/ir_action_report_view.xml @@ -0,0 +1,17 @@ + + + + country.company.default.report.form + ir.actions.report + + + + + + + + + + + +