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