diff --git a/pos_picking_delayed/__init__.py b/pos_picking_delayed/__init__.py index 042e239e..0650744f 100644 --- a/pos_picking_delayed/__init__.py +++ b/pos_picking_delayed/__init__.py @@ -1,2 +1 @@ -# coding: utf-8 from . import models diff --git a/pos_picking_delayed/__manifest__.py b/pos_picking_delayed/__manifest__.py index b215b527..555d83c2 100644 --- a/pos_picking_delayed/__manifest__.py +++ b/pos_picking_delayed/__manifest__.py @@ -1,4 +1,3 @@ -# coding: utf-8 # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -13,9 +12,9 @@ 'website': 'https://www.github.com/OCA/pos', 'depends': [ 'point_of_sale', + 'queue_job', ], 'data': [ - 'data/ir_cron.xml', 'views/view_pos_config.xml', 'views/view_pos_order.xml', ], diff --git a/pos_picking_delayed/data/ir_cron.xml b/pos_picking_delayed/data/ir_cron.xml deleted file mode 100644 index d0d71607..00000000 --- a/pos_picking_delayed/data/ir_cron.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - Create Delayed PoS Picking - - 1 - minutes - -1 - - pos.order - create_delayed_picking - () - - - diff --git a/pos_picking_delayed/models/__init__.py b/pos_picking_delayed/models/__init__.py index 527a57a5..7d540dbf 100644 --- a/pos_picking_delayed/models/__init__.py +++ b/pos_picking_delayed/models/__init__.py @@ -1,4 +1,3 @@ -# coding: utf-8 from . import pos_config from . import pos_order diff --git a/pos_picking_delayed/models/pos_config.py b/pos_picking_delayed/models/pos_config.py index 73a637da..4b7fb06c 100644 --- a/pos_picking_delayed/models/pos_config.py +++ b/pos_picking_delayed/models/pos_config.py @@ -1,4 +1,3 @@ -# coding: utf-8 # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/pos_picking_delayed/models/pos_order.py b/pos_picking_delayed/models/pos_order.py index c32d89fb..fc7fbd53 100644 --- a/pos_picking_delayed/models/pos_order.py +++ b/pos_picking_delayed/models/pos_order.py @@ -1,12 +1,8 @@ -# coding: utf-8 # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import logging - from odoo import api, fields, models - -_logger = logging.getLogger(__name__) +from odoo.addons.queue_job.job import job class PosOrder(models.Model): @@ -31,6 +27,8 @@ class PosOrder(models.Model): def create_picking(self): if self.env.context.get('create_from_ui', False): orders = self.filtered(lambda x: not x.has_picking_delayed) + delayed_orders = self.filtered(lambda x: x.has_picking_delayed) + delayed_orders.with_delay()._create_delayed_picking() else: orders = self res = super(PosOrder, orders).create_picking() @@ -44,14 +42,8 @@ class PosOrder(models.Model): return res # Custom Section - @api.model - def create_delayed_picking(self): - orders = self.search([ - ('state', '!=', 'draft'), - ('has_picking_delayed', '=', True), - ], order='date_order') - for order in orders: - order.sudo(order.user_id.id).with_context( - force_company=order.company_id.id).create_picking() - if orders: - _logger.info("Pickings handled for %d PoS Orders" % (len(orders))) + @api.multi + @job + def _create_delayed_picking(self): + super(PosOrder, self).create_picking() + self.write({'has_picking_delayed': False}) diff --git a/pos_picking_delayed/readme/CONFIGURE.rst b/pos_picking_delayed/readme/CONFIGURE.rst index 03835268..6b773fd3 100644 --- a/pos_picking_delayed/readme/CONFIGURE.rst +++ b/pos_picking_delayed/readme/CONFIGURE.rst @@ -3,3 +3,7 @@ * Set the value in the field 'Picking Creation Delayed'. (Checked by default) .. image:: /pos_picking_delayed/static/description/pos_config_form.png + +* This module depends on ``queue_job`` module that requires specific + configuration to works properly. Make sure your config file is correctly set. + See https://github.com/OCA/queue/tree/12.0/queue_job diff --git a/pos_picking_delayed/readme/DESCRIPTION.rst b/pos_picking_delayed/readme/DESCRIPTION.rst index b5e6f70d..b793c4ff 100644 --- a/pos_picking_delayed/readme/DESCRIPTION.rst +++ b/pos_picking_delayed/readme/DESCRIPTION.rst @@ -2,16 +2,7 @@ This module extends the functionality of odoo Point Of Sale to reduce creation time of the PoS orders, via the front UI. For that purpose, it delays the creation of the picking associated, that will -be created later, by cron. (set by default to run each minute). - -Technical information ---------------------- - -A log will be generated to mention the creation of the pickings by cron. - -``2018-09-28 07:47:18,300 163 INFO db odoo.addons.base.ir.ir_cron: Starting job `Create Delayed PoS Picking.`` - -``2018-09-28 07:47:19,168 163 INFO db odoo.addons.pos_picking_delayed.models.pos_order: Pickings created for 3 PoS Orders`` +be created later by queue job. This module is interesting specially in a context of Synchroneous Point Of Sale that is introduced by certification modules like 'l10n_fr_pos_cert' because diff --git a/pos_picking_delayed/readme/ROADMAP.rst b/pos_picking_delayed/readme/ROADMAP.rst deleted file mode 100644 index d3eba886..00000000 --- a/pos_picking_delayed/readme/ROADMAP.rst +++ /dev/null @@ -1,5 +0,0 @@ -* Make this module depend on the module OCA `queue_job` job module. - -* In the cron job (or the future queue job), improvment can be done, limiting - the quantity of environments, grouping orders by company, and changing - context once. diff --git a/pos_picking_delayed/readme/USAGE.rst b/pos_picking_delayed/readme/USAGE.rst index be46510c..00c9f863 100644 --- a/pos_picking_delayed/readme/USAGE.rst +++ b/pos_picking_delayed/readme/USAGE.rst @@ -1,4 +1,4 @@ -* Use your Point of Sale as usual. when validating an order, the order will - be in a different color until the cron is executed +* Use your Point of Sale as usual. When validating an order, the order will + be in a different color until the job is executed .. image:: /pos_picking_delayed/static/description/pos_order_tree.png diff --git a/pos_picking_delayed/static/description/pos_config_form.png b/pos_picking_delayed/static/description/pos_config_form.png index a23f4db4..d4756d3a 100644 Binary files a/pos_picking_delayed/static/description/pos_config_form.png and b/pos_picking_delayed/static/description/pos_config_form.png differ diff --git a/pos_picking_delayed/static/description/pos_order_tree.png b/pos_picking_delayed/static/description/pos_order_tree.png index a8781e7f..1420d6b9 100644 Binary files a/pos_picking_delayed/static/description/pos_order_tree.png and b/pos_picking_delayed/static/description/pos_order_tree.png differ diff --git a/pos_picking_delayed/tests/__init__.py b/pos_picking_delayed/tests/__init__.py index e46a9f76..13290d89 100644 --- a/pos_picking_delayed/tests/__init__.py +++ b/pos_picking_delayed/tests/__init__.py @@ -1,3 +1,2 @@ -# coding: utf-8 from . import test_module diff --git a/pos_picking_delayed/tests/test_module.py b/pos_picking_delayed/tests/test_module.py index 0f7a6c6e..05bc7560 100644 --- a/pos_picking_delayed/tests/test_module.py +++ b/pos_picking_delayed/tests/test_module.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -10,42 +9,37 @@ class TestModule(TransactionCase): def setUp(self): super(TestModule, self).setUp() - self.pos_order_obj = self.env['pos.order'] - self.pos_picking_cron = self.env.ref( - 'pos_picking_delayed.cron_create_delayed_pos_picking') - self.pos_config = self.env.ref('point_of_sale.pos_config_main') - self.carotte_product = self.env.ref('point_of_sale.carotte') + self.PosOrder = self.env['pos.order'] + self.QueueJob = self.env['queue.job'] + self.pos_product = self.env.ref('point_of_sale.whiteboard_pen') + self.pricelist = self.env.ref('product.list0') - def test_01_picking_delayed_enabled(self): - # Disable Cron - self.pos_picking_cron.active = False + # Create a new pos config and open it + self.pos_config = self.env.ref('point_of_sale.pos_config_main').copy() + self.pos_config.open_session_cb() + def test_01_picking_delayed_enabled(self): # Enable feature self.pos_config.picking_creation_delayed = True - order = self._open_session_create_order() + order = self._create_order() self.assertEqual( order.picking_id.id, False, "Creating order via UI should not generate a picking if" " feature is enabled") - # run cron and test if picking is now created - self.pos_picking_cron.method_direct_trigger() - - self.assertNotEqual( - order.picking_id.id, False, - "Run PoS picking Cron should generate picking for PoS Orders" - " without picking") + # Test if a Queue Job has been generated + func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id) + queues = self.QueueJob.search([ + ('func_string', '=', func_string)]) + self.assertEqual(len(queues), 1, "Queue Job has not been created") def test_02_picking_delayed_disabled(self): - # Disable Cron - self.pos_picking_cron.active = False - # Disable feature self.pos_config.picking_creation_delayed = False - order = self._open_session_create_order() + order = self._create_order() picking_id = order.picking_id.id self.assertNotEqual( @@ -53,34 +47,30 @@ class TestModule(TransactionCase): "Creating order via UI should generate a picking if" " feature is disabled") - # run cron and test if picking is now created - self.pos_picking_cron.method_direct_trigger() + # Test if a Queue Job has not been generated + func_string = 'pos.order(%d,)._create_delayed_picking()' % (order.id) + queues = self.QueueJob.search([ + ('func_string', '=', func_string)]) + self.assertEqual(len(queues), 0, "Queue Job has been created") - self.assertEqual( - order.picking_id.id, picking_id, - "Run PoS picking Cron should not regenerate picking for" - " PoS Orders that have already a picking created.") - - def _open_session_create_order(self): + def _create_order(self): # Create order - self.pos_config.open_session_cb() order_data = { 'id': u'0006-001-0010', 'to_invoice': False, 'data': { + 'pricelist_id': self.pricelist.id, 'user_id': 1, 'name': 'Order 0006-001-0010', 'partner_id': False, 'amount_paid': 0.9, 'pos_session_id': self.pos_config.current_session_id.id, 'lines': [[0, 0, { - 'id': 1, - 'product_id': self.carotte_product.id, - 'tax_ids': [[6, False, []]], + 'product_id': self.pos_product.id, 'price_unit': 0.9, 'qty': 1, - 'pack_lot_ids': [], - 'discount': 0, + 'price_subtotal': 0.9, + 'price_subtotal_incl': 0.9, }]], 'statement_ids': [[0, 0, { 'journal_id': self.pos_config.journal_ids[0].id, @@ -100,7 +90,6 @@ class TestModule(TransactionCase): 'amount_total': 0.9, }} - # Test if picking is not created - result = self.pos_order_obj.create_from_ui([order_data]) - order = self.pos_order_obj.browse(result[0]) + result = self.PosOrder.create_from_ui([order_data]) + order = self.PosOrder.browse(result[0]) return order diff --git a/pos_picking_delayed/views/view_pos_config.xml b/pos_picking_delayed/views/view_pos_config.xml index 9405a9e0..4c6f3314 100644 --- a/pos_picking_delayed/views/view_pos_config.xml +++ b/pos_picking_delayed/views/view_pos_config.xml @@ -6,11 +6,13 @@ pos.config - + - - - + + + + +