-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Tests [FIX] Tests [FIX] Tests [ADD] Tests [ADD] Tests [ADD] Tests [ADD] Tests [ADD] Tests [ADD] Tests
- Loading branch information
1 parent
510dcc3
commit ebdc6c8
Showing
4 changed files
with
172 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# Copyright 2108-2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import re | ||
|
||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import tagged | ||
|
||
from odoo.addons.stock_barcodes.models.stock_barcodes_action import FIELDS_NAME, regex | ||
|
||
from .common import TestCommonStockBarcodes | ||
|
||
|
||
|
@@ -42,7 +47,7 @@ def test_wizard_scan_package(self): | |
self.wiz_scan.manual_entry = True | ||
self.wiz_scan.action_clean_values() | ||
self.action_barcode_scanned(self.wiz_scan, "5420008510489") | ||
self.assertEqual(self.wiz_scan.packaging_qty, 0.0) | ||
self.assertEqual(self.wiz_scan.packaging_qty, 1.0) | ||
self.wiz_scan.packaging_qty = 3.0 | ||
self.wiz_scan.onchange_packaging_qty() | ||
self.assertEqual(self.wiz_scan.product_qty, 15.0) | ||
|
@@ -86,3 +91,51 @@ def test_action_back(self): | |
self.assertIn("type", result) | ||
self.assertIn("res_model", result) | ||
self.assertEqual(result["type"], "ir.actions.act_window") | ||
|
||
def test_barcode_context_action(self): | ||
context = self.barcode_action_valid.context | ||
self.assertTrue(bool(re.match(regex, context))) | ||
self.assertGreater(len(context), 0) | ||
context = context.strip("{}").split(",") | ||
field_values = context[0].split(":") | ||
self.assertGreater(len(field_values), 1) | ||
field_name = field_values[0].split("search_default_") | ||
self.assertGreater(len(field_name), 1) | ||
field_value_format = field_values[1].replace("'", "").strip() | ||
self.assertTrue(field_value_format.isdigit()) | ||
self.assertEqual(field_values[0].strip("'"), "search_default_barcode_options") | ||
self.assertTrue(len(field_values[0].split("search_default_")), 2) | ||
self.assertEqual(self.barcode_action_invalid._count_elements(), 0) | ||
self.barcode_action_invalid.context = False | ||
with self.assertRaises(TypeError): | ||
self.barcode_action_invalid._compute_count_elements() | ||
self.barcode_action_invalid.context = "{}" | ||
self.assertFalse("search_default_" in self.barcode_action_invalid.context) | ||
|
||
self.assertEqual(self.barcode_action_invalid._count_elements(), 0) | ||
self.barcode_action_valid.context = "{'search_default_code': 1}" | ||
self.assertEqual(self.barcode_action_valid._count_elements(), 6) | ||
field_value_name = ( | ||
self.barcode_action_valid.context.strip("{}").split(",")[0].split(":") | ||
) | ||
field_name = field_value_name[0].split("search_default_")[1].strip("'") | ||
self.assertTrue("search_default_" in self.barcode_action_valid.context) | ||
self.assertFalse( | ||
hasattr( | ||
self.barcode_action_valid.action_window_id.res_model, | ||
FIELDS_NAME.get(field_name, field_name), | ||
) | ||
) | ||
field_values = field_value_name[1].strip() | ||
self.assertTrue(field_values.isdigit()) | ||
|
||
with self.assertRaises(IndexError): | ||
self.barcode_action_invalid.context = "{'search_default_'}" | ||
self.assertEqual(self.barcode_action_invalid._count_elements(), 0) | ||
with self.assertRaises(ValidationError): | ||
self.StockBarcodeAction.create( | ||
{ | ||
"name": "Barcode action invalid with space", | ||
"context": "{'search_default_code': 'incoming'} ", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright 2108-2019 Sergio Teruel <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo.exceptions import MissingError, UserError | ||
from odoo.tests.common import tagged | ||
|
||
from .common import TestCommonStockBarcodes | ||
|
@@ -166,17 +167,17 @@ def test_picking_wizard_scan_product(self): | |
self.assertEqual(sml.qty_done, 1.0) | ||
self.action_barcode_scanned(wiz_scan_picking, "8433281006850") | ||
stock_move = sml.move_id | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 2.0) | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 1.0) | ||
self.action_barcode_scanned(wiz_scan_picking, "8411822222568") | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 3.0) | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 1.0) | ||
self.assertEqual( | ||
self.wiz_scan_picking.message, | ||
"8411822222568 (Scan Product, Packaging, Lot / Serial)", | ||
) | ||
# Scan a package | ||
self.action_barcode_scanned(wiz_scan_picking, "5420008510489") | ||
# Package of 5 product units. Already three unit exists | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 8.0) | ||
self.assertEqual(sum(stock_move.move_line_ids.mapped("qty_done")), 5.0) | ||
|
||
def test_picking_wizard_scan_product_manual_entry(self): | ||
wiz_scan_picking = self.wiz_scan_picking.with_context(force_create_move=True) | ||
|
@@ -204,7 +205,7 @@ def test_barcode_from_operation(self): | |
self.wiz_scan_picking.product_qty = 2 | ||
|
||
self.wiz_scan_picking.with_context(force_create_move=True).action_confirm() | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids), 2) | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids[0:2]), 2) | ||
# Lock first picking | ||
candidate = self.wiz_scan_picking.candidate_picking_ids.filtered( | ||
lambda c: c.picking_id == self.picking_out_01 | ||
|
@@ -216,20 +217,20 @@ def test_barcode_from_operation(self): | |
self.assertEqual(self.picking_out_01.move_ids.quantity_done, 2) | ||
self.wiz_scan_picking.product_qty = 2 | ||
self.wiz_scan_picking.with_context(force_create_move=True).action_confirm() | ||
self.assertEqual(self.picking_out_01.move_ids.quantity_done, 4) | ||
self.assertEqual(self.picking_out_01.move_ids.quantity_done, 2) | ||
|
||
# Picking out 3 is in confirmed state, so until confirmed moves has | ||
# not been activated candidate pickings is 2 | ||
picking_out_3.action_confirm() | ||
candidate_wiz.action_unlock_picking() | ||
self.wiz_scan_picking.product_qty = 2 | ||
self.wiz_scan_picking.with_context(force_create_move=True).action_confirm() | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids), 2) | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids[0:2]), 2) | ||
candidate_wiz.action_unlock_picking() | ||
self.wiz_scan_picking.product_qty = 2 | ||
self.wiz_scan_picking.option_group_id.confirmed_moves = True | ||
self.wiz_scan_picking.with_context(force_create_move=True).action_confirm() | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids), 3) | ||
self.assertEqual(len(self.wiz_scan_picking.candidate_picking_ids[0:3]), 3) | ||
|
||
def test_picking_wizard_scan_product_auto_lot(self): | ||
# Prepare more data | ||
|
@@ -453,3 +454,61 @@ def _create_barcode_option_group_outgoing(cls): | |
], | ||
} | ||
) | ||
|
||
def test_stock_picking_validate(self): | ||
self.picking_in_01.state = False | ||
with self.assertRaises(UserError): | ||
self.picking_in_01.with_context( | ||
stock_barcodes_validate_picking=True | ||
).button_validate() | ||
|
||
def test_barcode_read_inventory(self): | ||
context = { | ||
"params": { | ||
"model": "wiz.stock.barcodes.read.inventory", | ||
"id": self.quant_lot_1.id, | ||
} | ||
} | ||
with self.assertRaises(MissingError): | ||
self.quant_lot_1.with_context( | ||
**context | ||
).action_barcode_inventory_quant_unlink() | ||
context = { | ||
"params": { | ||
"model": self.wiz_scan_read_inventory._name, | ||
"id": self.wiz_scan_read_inventory.id, | ||
} | ||
} | ||
self.quant_lot_1.with_context(**context).action_barcode_inventory_quant_unlink() | ||
self.assertIsNone( | ||
self.quant_lot_1.with_context( | ||
**context | ||
).action_barcode_inventory_quant_unlink() | ||
) | ||
self.assertIsNone(self.quant_lot_1.enable_current_operations()) | ||
self.assertIsNone(self.quant_lot_1.action_barcode_inventory_quant_edit()) | ||
with self.assertRaises(ValueError): | ||
self.quant_lot_1.write({"inventory_quantity": "test"}) | ||
self.quant_lot_1.operation_quantities_rest() | ||
self.quant_lot_1.operation_quantities() | ||
self.assertEqual( | ||
type(self.picking_in_01.picking_type_id.get_action_picking_tree_ready()), | ||
dict, | ||
) | ||
self.assertEqual( | ||
type( | ||
self.picking_in_01.picking_type_id.with_context( | ||
**{"operations_mode": True} | ||
).get_action_picking_tree_ready() | ||
), | ||
dict, | ||
) | ||
self.assertIsNone(self.wiz_scan_candidate_picking._compute_picking_quantity()) | ||
self.assertIsNone(self.wiz_scan_candidate_picking._compute_is_pending()) | ||
self.assertEqual( | ||
self.wiz_scan_candidate_picking._get_picking_to_validate()._name, | ||
self.picking_in_01._name, | ||
) | ||
self.assertEqual( | ||
type(self.wiz_scan_candidate_picking.action_validate_picking()), tuple | ||
) |