Browse Source

[MIG][12.0] pos_picking_delayed

[IMP] replace cron by queue_job
pull/380/head
Sylvain LE GAL 5 years ago
committed by OCA-git-bot
parent
commit
ebf3acf4f3
  1. 1
      oca_dependencies.txt
  2. 1
      pos_picking_delayed/__init__.py
  3. 3
      pos_picking_delayed/__manifest__.py
  4. 20
      pos_picking_delayed/data/ir_cron.xml
  5. 1
      pos_picking_delayed/models/__init__.py
  6. 1
      pos_picking_delayed/models/pos_config.py
  7. 24
      pos_picking_delayed/models/pos_order.py
  8. 4
      pos_picking_delayed/readme/CONFIGURE.rst
  9. 11
      pos_picking_delayed/readme/DESCRIPTION.rst
  10. 5
      pos_picking_delayed/readme/ROADMAP.rst
  11. 4
      pos_picking_delayed/readme/USAGE.rst
  12. BIN
      pos_picking_delayed/static/description/pos_config_form.png
  13. BIN
      pos_picking_delayed/static/description/pos_order_tree.png
  14. 1
      pos_picking_delayed/tests/__init__.py
  15. 65
      pos_picking_delayed/tests/test_module.py
  16. 8
      pos_picking_delayed/views/view_pos_config.xml

1
oca_dependencies.txt

@ -0,0 +1 @@
queue_job

1
pos_picking_delayed/__init__.py

@ -1,2 +1 @@
# coding: utf-8
from . import models from . import models

3
pos_picking_delayed/__manifest__.py

@ -1,4 +1,3 @@
# coding: utf-8
# Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -13,9 +12,9 @@
'website': 'https://www.github.com/OCA/pos', 'website': 'https://www.github.com/OCA/pos',
'depends': [ 'depends': [
'point_of_sale', 'point_of_sale',
'queue_job',
], ],
'data': [ 'data': [
'data/ir_cron.xml',
'views/view_pos_config.xml', 'views/view_pos_config.xml',
'views/view_pos_order.xml', 'views/view_pos_order.xml',
], ],

20
pos_picking_delayed/data/ir_cron.xml

@ -1,20 +0,0 @@
<?xml version="1.0"?>
<!-- Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).-->
<odoo>
<data noupdate="1">
<record forcecreate="True" id="cron_create_delayed_pos_picking" model="ir.cron">
<field name="name">Create Delayed PoS Picking</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model">pos.order</field>
<field name="function">create_delayed_picking</field>
<field name="args">()</field>
</record>
</data>
</odoo>

1
pos_picking_delayed/models/__init__.py

@ -1,4 +1,3 @@
# coding: utf-8
from . import pos_config from . import pos_config
from . import pos_order from . import pos_order

1
pos_picking_delayed/models/pos_config.py

@ -1,4 +1,3 @@
# coding: utf-8
# Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

24
pos_picking_delayed/models/pos_order.py

@ -1,12 +1,8 @@
# coding: utf-8
# Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, fields, models from odoo import api, fields, models
_logger = logging.getLogger(__name__)
from odoo.addons.queue_job.job import job
class PosOrder(models.Model): class PosOrder(models.Model):
@ -31,6 +27,8 @@ class PosOrder(models.Model):
def create_picking(self): def create_picking(self):
if self.env.context.get('create_from_ui', False): if self.env.context.get('create_from_ui', False):
orders = self.filtered(lambda x: not x.has_picking_delayed) 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: else:
orders = self orders = self
res = super(PosOrder, orders).create_picking() res = super(PosOrder, orders).create_picking()
@ -44,14 +42,8 @@ class PosOrder(models.Model):
return res return res
# Custom Section # 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})

4
pos_picking_delayed/readme/CONFIGURE.rst

@ -3,3 +3,7 @@
* Set the value in the field 'Picking Creation Delayed'. (Checked by default) * Set the value in the field 'Picking Creation Delayed'. (Checked by default)
.. image:: /pos_picking_delayed/static/description/pos_config_form.png .. 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

11
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. time of the PoS orders, via the front UI.
For that purpose, it delays the creation of the picking associated, that will 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 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 Sale that is introduced by certification modules like 'l10n_fr_pos_cert' because

5
pos_picking_delayed/readme/ROADMAP.rst

@ -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.

4
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 .. image:: /pos_picking_delayed/static/description/pos_order_tree.png

BIN
pos_picking_delayed/static/description/pos_config_form.png

Before

Width: 1019  |  Height: 353  |  Size: 42 KiB

After

Width: 429  |  Height: 189  |  Size: 11 KiB

BIN
pos_picking_delayed/static/description/pos_order_tree.png

Before

Width: 971  |  Height: 153  |  Size: 25 KiB

After

Width: 1052  |  Height: 253  |  Size: 37 KiB

1
pos_picking_delayed/tests/__init__.py

@ -1,3 +1,2 @@
# coding: utf-8
from . import test_module from . import test_module

65
pos_picking_delayed/tests/test_module.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain) # Copyright 2018 - Today Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -10,42 +9,37 @@ class TestModule(TransactionCase):
def setUp(self): def setUp(self):
super(TestModule, self).setUp() 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 # Enable feature
self.pos_config.picking_creation_delayed = True self.pos_config.picking_creation_delayed = True
order = self._open_session_create_order()
order = self._create_order()
self.assertEqual( self.assertEqual(
order.picking_id.id, False, order.picking_id.id, False,
"Creating order via UI should not generate a picking if" "Creating order via UI should not generate a picking if"
" feature is enabled") " 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): def test_02_picking_delayed_disabled(self):
# Disable Cron
self.pos_picking_cron.active = False
# Disable feature # Disable feature
self.pos_config.picking_creation_delayed = False self.pos_config.picking_creation_delayed = False
order = self._open_session_create_order()
order = self._create_order()
picking_id = order.picking_id.id picking_id = order.picking_id.id
self.assertNotEqual( self.assertNotEqual(
@ -53,34 +47,30 @@ class TestModule(TransactionCase):
"Creating order via UI should generate a picking if" "Creating order via UI should generate a picking if"
" feature is disabled") " 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 # Create order
self.pos_config.open_session_cb()
order_data = { order_data = {
'id': u'0006-001-0010', 'id': u'0006-001-0010',
'to_invoice': False, 'to_invoice': False,
'data': { 'data': {
'pricelist_id': self.pricelist.id,
'user_id': 1, 'user_id': 1,
'name': 'Order 0006-001-0010', 'name': 'Order 0006-001-0010',
'partner_id': False, 'partner_id': False,
'amount_paid': 0.9, 'amount_paid': 0.9,
'pos_session_id': self.pos_config.current_session_id.id, 'pos_session_id': self.pos_config.current_session_id.id,
'lines': [[0, 0, { '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, 'price_unit': 0.9,
'qty': 1, 'qty': 1,
'pack_lot_ids': [],
'discount': 0,
'price_subtotal': 0.9,
'price_subtotal_incl': 0.9,
}]], }]],
'statement_ids': [[0, 0, { 'statement_ids': [[0, 0, {
'journal_id': self.pos_config.journal_ids[0].id, 'journal_id': self.pos_config.journal_ids[0].id,
@ -100,7 +90,6 @@ class TestModule(TransactionCase):
'amount_total': 0.9, '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 return order

8
pos_picking_delayed/views/view_pos_config.xml

@ -6,11 +6,13 @@
<record id="view_pos_config_form" model="ir.ui.view"> <record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field> <field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="default_fiscal_position_id" position="after">
<xpath expr="//div[@id='title']" position="after">
<group string="Picking Creation Delayed">
<field name="picking_creation_delayed"/> <field name="picking_creation_delayed"/>
</field>
</group>
</xpath>
</field> </field>
</record> </record>

Loading…
Cancel
Save