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..a8c07ac --- /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': [ + 'sale_stock', + 'base_report_to_printer', + ], + 'data': [ + 'views/ir_action_report_view.xml' + ], + 'maintainers': ['bodedra'], + '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..230c7cf --- /dev/null +++ b/stock_picking_auto_print/models/stock_picking.py @@ -0,0 +1,94 @@ +# 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" + + 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 + + @api.multi + 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: + pass + return True + + @api.multi + def write(self, vals): + res = super(StockPicking, self).write(vals) + if 'date_done' in vals: + self._stock_picking_default_auto_print_report() + return res + + @api.multi + 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..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/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..04eca89 --- /dev/null +++ b/stock_picking_auto_print/tests/test_stock_picking_auto_print.py @@ -0,0 +1,91 @@ +# 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') + self.scrapped_location = self.env.ref('stock.stock_location_scrapped') + + uom_unit = self.env.ref('product.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('product.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..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 + + + + + + + + + + + +