diff --git a/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print b/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print new file mode 120000 index 0000000..4b9e771 --- /dev/null +++ b/setup/stock_picking_auto_print/odoo/addons/stock_picking_auto_print @@ -0,0 +1 @@ +../../../../stock_picking_auto_print \ No newline at end of file diff --git a/setup/stock_picking_auto_print/setup.py b/setup/stock_picking_auto_print/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/stock_picking_auto_print/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_picking_auto_print/README.rst b/stock_picking_auto_print/README.rst new file mode 100644 index 0000000..00b0901 --- /dev/null +++ b/stock_picking_auto_print/README.rst @@ -0,0 +1,105 @@ +============ +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. + +.. |maintainer-bodedra| image:: https://github.com/bodedra.png?size=40px + :target: https://github.com/bodedra + :alt: bodedra + +Current `maintainer `__: + +|maintainer-bodedra| + +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..8245e55 --- /dev/null +++ b/stock_picking_auto_print/__manifest__.py @@ -0,0 +1,17 @@ +# 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": "13.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": ["sale_stock", "base_report_to_printer"], + "data": ["views/ir_action_report_view.xml"], + "maintainers": ["bodedra"], + "installable": True, +} diff --git a/stock_picking_auto_print/i18n/stock_picking_auto_print.pot b/stock_picking_auto_print/i18n/stock_picking_auto_print.pot new file mode 100644 index 0000000..4d9dbaa --- /dev/null +++ b/stock_picking_auto_print/i18n/stock_picking_auto_print.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_picking_auto_print +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_picking_auto_print +#: model:ir.model.fields,field_description:stock_picking_auto_print.field_ir_act_report_xml_company_id +msgid "Company" +msgstr "" + +#. module: stock_picking_auto_print +#: model:ir.model.fields,field_description:stock_picking_auto_print.field_ir_act_report_xml_country_id +msgid "Country" +msgstr "" + +#. module: stock_picking_auto_print +#: model:ir.model.fields,field_description:stock_picking_auto_print.field_ir_act_report_xml_is_default_report +msgid "Is Default Report?" +msgstr "" + +#. module: stock_picking_auto_print +#: model:ir.model,name:stock_picking_auto_print.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: stock_picking_auto_print +#: model:ir.model,name:stock_picking_auto_print.model_ir_actions_report +msgid "ir.actions.report" +msgstr "" + 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..7a81c8e --- /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..6501895 --- /dev/null +++ b/stock_picking_auto_print/models/stock_picking.py @@ -0,0 +1,98 @@ +# 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 models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _search_default_report(self, country_id=False, company_id=False): + report_id = False + report_action_pool = self.env["ir.actions.report"] + domain = [("model", "=", "stock.picking"), ("is_default_report", "=", True)] + fields = ["country_id", "company_id"] + stock_picking_reports = report_action_pool.search_read(domain, fields) + if country_id and company_id: + for value in stock_picking_reports: + if value.get("country_id") and value.get("company_id"): + if ( + value.get("country_id")[0] == country_id + and value.get("company_id")[0] == company_id + ): + return value["id"] + elif country_id: + for value in stock_picking_reports: + if value.get("country_id"): + if value.get("country_id")[0] == country_id: + return value["id"] + elif company_id: + for value in stock_picking_reports: + if value.get("company_id"): + if value.get("company_id")[0] == company_id: + return value["id"] + else: + report_id = ( + self.env.ref("stock.action_report_picking") + .with_context(landscape=True) + .report_action(self) + .get("id") + ) + return report_id + + def _stock_picking_default_auto_print_report(self): + 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): + default_report_id = False + # Check Partner country id + country_id = False + if picking.partner_id.country_id: + country_id = picking.partner_id.country_id.id + + if country_id and user_company_id: + # Filter report with Country and Company + default_report_id = picking._search_default_report( + country_id, user_company_id + ) + + if not default_report_id and country_id: + # Filter report with Country + default_report_id = picking._search_default_report( + country_id=country_id + ) + + if not default_report_id: + # Filter report with Company + default_report_id = picking._search_default_report( + company_id=user_company_id + ) + + if not default_report_id: + # Search for default picking operation report + default_report_id = picking._search_default_report() + + action_report = report_action_pool.browse(default_report_id) + + try: + action_report.print_document(picking.id) + except Exception: + pass + return True + + def write(self, vals): + res = super(StockPicking, self).write(vals) + if "date_done" in vals: + self._stock_picking_default_auto_print_report() + return res + + def action_assign(self): + res = super(StockPicking, self).action_assign() + for picking in self: + if ( + picking.picking_type_code == "outgoing" + or picking.location_dest_id.name == "Output" + ) and picking.state == "assigned": + picking._stock_picking_default_auto_print_report() + 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..7ea3a41 --- /dev/null +++ b/stock_picking_auto_print/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +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.

+

Current maintainer:

+

bodedra

+

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/tests/__init__.py b/stock_picking_auto_print/tests/__init__.py new file mode 100644 index 0000000..c9f63eb --- /dev/null +++ b/stock_picking_auto_print/tests/__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 test_stock_picking_auto_print diff --git a/stock_picking_auto_print/tests/test_stock_picking_auto_print.py b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py new file mode 100644 index 0000000..ad26cbb --- /dev/null +++ b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py @@ -0,0 +1,121 @@ +# 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.tests.common import TransactionCase + + +class StockPikcing(TransactionCase): + def setUp(self): + super(StockPikcing, self).setUp() + + self.stock_location = self.env.ref("stock.stock_location_stock") + self.customer_location = self.env.ref("stock.stock_location_customers") + stock_location_locations_virtual = self.env["stock.location"].create( + {"name": "Virtual Locations", "usage": "view", "posz": 1} + ) + self.scrapped_location = self.env["stock.location"].create( + { + "name": "Scrapped", + "location_id": stock_location_locations_virtual.id, + "scrap_location": True, + "usage": "inventory", + } + ) + + uom_unit = self.env.ref("uom.product_uom_unit") + + self.product_A = self.env["product.product"].create( + { + "name": "Product A", + "type": "product", + "list_price": 1.0, + "categ_id": self.env.ref("product.product_category_all").id, + "uom_id": uom_unit.id, + } + ) + + self.country_us = self.env["res.country"].search( + [("code", "like", "US")], limit=1 + ) + self.partner = self.env["res.partner"].create( + {"name": "BOdedra", "country_id": self.country_us.id} + ) + + self.so = self.env["sale.order"].create( + { + "partner_id": self.partner.id, + "partner_invoice_id": self.partner.id, + "partner_shipping_id": self.partner.id, + "order_line": [ + ( + 0, + 0, + { + "name": self.product_A.name, + "product_id": self.product_A.id, + "product_uom_qty": 2, + "product_uom": self.product_A.uom_id.id, + "price_unit": self.product_A.list_price, + }, + ) + ], + "pricelist_id": self.env.ref("product.list0").id, + "picking_policy": "direct", + } + ) + + self.uom_unit = self.env.ref("uom.product_uom_unit") + + def test_stock_picking_auto_print(self): + """ Auto print when DO is ready or done + """ + self.env["stock.quant"]._update_available_quantity( + self.product_A, self.stock_location, 2 + ) + self.so.action_confirm() + for picking in self.so.picking_ids: + picking.move_lines._do_unreserve() + + # Unreserve picking and update default report configuration + picking.move_lines._do_unreserve() + + # Made Delivery Slip report as a default report + deliveryslip_report = self.env["ir.actions.report"].search( + [("report_name", "=", "stock.report_deliveryslip")] + ) + + deliveryslip_report.write({"is_default_report": True}) + picking.action_assign() + + # Remove country ID from Delivery Slip report + deliveryslip_report.write( + {"country_id": self.country_us.id, "company_id": False} + ) + picking.action_confirm() + picking.action_assign() + + picking.move_lines._do_unreserve() + + # Unreserve picking and update default report configuration + picking.do_unreserve() + + # Remove company ID from Delivery Slip report + deliveryslip_report.write( + {"company_id": self.env.user.company_id.id, "country_id": False} + ) + picking.action_confirm() + picking.action_assign() + + picking.do_unreserve() + picking.move_lines._do_unreserve() + + deliveryslip_report.write( + { + "company_id": self.env.user.company_id.id, + "country_id": self.country_us.id, + } + ) + picking.action_confirm() + picking.action_assign() + picking.action_done() 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..a8465a3 --- /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 + + + + + + + + + + + +