summaryrefslogtreecommitdiff
path: root/addons/sale_product_matrix
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2019-11-21 14:30:02 +0000
committerVictor Feyens <vfe@odoo.com>2019-11-27 15:49:57 +0000
commitc32e9a47886a4d9b008c8c2b18172aa98907d353 (patch)
treebcef7e51df60568bbc1de401c506a772843a87bb /addons/sale_product_matrix
parent6c800032088128d818fc970afee7cc7f1c365a6e (diff)
[ADD] (*_)_product_matrix: test tours
closes odoo/odoo#40971 X-original-commit: d729460f5fc72aa70e0a024e1dff281299eed0e3 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Diffstat (limited to 'addons/sale_product_matrix')
-rw-r--r--addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js110
-rw-r--r--addons/sale_product_matrix/tests/__init__.py4
-rw-r--r--addons/sale_product_matrix/tests/test_sale_matrix.py41
-rw-r--r--addons/sale_product_matrix/views/assets.xml6
4 files changed, 161 insertions, 0 deletions
diff --git a/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js b/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js
new file mode 100644
index 00000000000..deb3c8bb2ba
--- /dev/null
+++ b/addons/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js
@@ -0,0 +1,110 @@
+odoo.define('sale_product_matrix.sale_matrix_tour', function (require) {
+"use strict";
+
+var tour = require('web_tour.tour');
+
+tour.register('sale_matrix_tour', {
+ url: "/web",
+ test: true,
+}, [tour.STEPS.SHOW_APPS_MENU_ITEM, {
+ trigger: '.o_app[data-menu-xmlid="sale.sale_menu_root"]',
+}, {
+ trigger: ".o_list_button_add",
+ extra_trigger: ".o_sale_order"
+}, {
+ trigger: "a:contains('Add a product')"
+}, {
+ trigger: 'div[name="product_template_id"] input',
+ run: function () {
+ var $input = $('div[name="product_template_id"] input');
+ $input.click();
+ $input.val('Matrix');
+ var keyDownEvent = jQuery.Event("keydown");
+ keyDownEvent.which = 42;
+ $input.trigger(keyDownEvent);
+ }
+}, {
+ trigger: 'ul.ui-autocomplete a:contains("Matrix")',
+ run: 'click'
+}, {
+ trigger: '.o_product_variant_matrix',
+ run: function () {
+ // fill the whole matrix with 1's
+ $('.o_matrix_input').val(1);
+ }
+}, {
+ trigger: 'span:contains("Confirm")',
+ run: 'click'
+}, {
+ trigger: ".o_form_editable .o_field_many2one[name='partner_id'] input",
+ extra_trigger: ".o_sale_order",
+ run: 'text Agrolait'
+}, {
+ trigger: ".ui-menu-item > a",
+ auto: true,
+ in_modal: false,
+}, {
+ trigger: '.o_form_button_save:contains("Save")',
+ run: 'click' // SAVE Sales Order.
+},
+// Open the matrix through the pencil button next to the product in line edit mode.
+{
+ trigger: '.o_form_button_edit:contains("Edit")',
+ run: 'click' // Edit Sales Order.
+}, {
+ trigger: 'span:contains("Matrix (PAV11, PAV22, PAV31)\n\nPA4: PAV41")',
+ run: 'click'
+}, {
+ trigger: '.o_edit_product_configuration',
+ run: 'click' // edit the matrix
+}, {
+ trigger: '.o_product_variant_matrix',
+ run: function () {
+ // update some of the matrix values.
+ $('.o_matrix_input').slice(8, 16).val(4);
+ } // set the qty to 4 for half of the matrix products.
+}, {
+ trigger: 'span:contains("Confirm")',
+ run: 'click' // apply the matrix
+}, {
+ trigger: '.o_form_button_save:contains("Save")',
+ extra_trigger: '.o_field_cell.o_data_cell.o_list_number:contains("4.000")',
+ run: 'click' // SAVE Sales Order, after matrix has been applied (extra_trigger).
+}, {
+ trigger: '.o_form_button_edit:contains("Edit")',
+ run: 'click' // Edit Sales Order.
+},
+// Ensures the matrix is opened with the values, when adding the same product.
+{
+ trigger: "a:contains('Add a product')"
+}, {
+ trigger: 'div[name="product_template_id"] input',
+ run: function () {
+ var $input = $('div[name="product_template_id"] input');
+ $input.click();
+ $input.val('Matrix');
+ var keyDownEvent = jQuery.Event("keydown");
+ keyDownEvent.which = 42;
+ $input.trigger(keyDownEvent);
+ }
+}, {
+ trigger: 'ul.ui-autocomplete a:contains("Matrix")',
+ run: 'click'
+}, {
+ trigger: "input[value='4']",
+ run: function () {
+ // update some values of the matrix
+ $("input[value='4']").slice(0, 4).val(8.2);
+ }
+}, {
+ trigger: 'span:contains("Confirm")',
+ run: 'click' // apply the matrix
+}, {
+ trigger: '.o_form_button_save:contains("Save")',
+ extra_trigger: '.o_field_cell.o_data_cell.o_list_number:contains("8.200")',
+ run: 'click' // SAVE Sales Order, after matrix has been applied (extra_trigger).
+},
+]);
+
+
+});
diff --git a/addons/sale_product_matrix/tests/__init__.py b/addons/sale_product_matrix/tests/__init__.py
new file mode 100644
index 00000000000..943bad6e41f
--- /dev/null
+++ b/addons/sale_product_matrix/tests/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import test_sale_matrix
diff --git a/addons/sale_product_matrix/tests/test_sale_matrix.py b/addons/sale_product_matrix/tests/test_sale_matrix.py
new file mode 100644
index 00000000000..513c67424e3
--- /dev/null
+++ b/addons/sale_product_matrix/tests/test_sale_matrix.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import odoo.tests
+from odoo.addons.product_matrix.tests import common
+
+
+@odoo.tests.tagged('post_install', '-at_install')
+class TestSaleMatrixUi(common.TestMatrixCommon):
+
+ """
+ This test needs sale_management module to work.
+ """
+
+ def test_sale_matrix_ui(self):
+ # Set the template as configurable by matrix.
+ self.matrix_template.product_add_mode = "matrix"
+
+ self.start_tour("/web", 'sale_matrix_tour', login="admin")
+
+ # Ensures some dynamic create variants have been created by the matrix
+ # Ensures a SO has been created with exactly x lines ...
+
+ self.assertEqual(len(self.matrix_template.product_variant_ids), 8)
+ self.assertEqual(len(self.matrix_template.product_variant_ids.product_template_attribute_value_ids), 6)
+ self.assertEqual(len(self.matrix_template.attribute_line_ids.product_template_value_ids), 8)
+ self.env['sale.order.line'].search([('product_id', 'in', self.matrix_template.product_variant_ids.ids)]).order_id.action_confirm()
+
+ self.matrix_template.flush()
+ self.assertEqual(round(self.matrix_template.sales_count, 2), 56.8)
+ for variant in self.matrix_template.product_variant_ids:
+ # 5 and 9.2 because of no variant attributes
+ self.assertIn(round(variant.sales_count, 2), [5, 9.2])
+
+ # Ensure no duplicate line has been created on the SO.
+ # NB: the *2 is because the no_variant attribute doesn't create a variant
+ # but still gives different order lines.
+ self.assertEqual(
+ len(self.env['sale.order.line'].search([('product_id', 'in', self.matrix_template.product_variant_ids.ids)])),
+ len(self.matrix_template.product_variant_ids)*2
+ )
diff --git a/addons/sale_product_matrix/views/assets.xml b/addons/sale_product_matrix/views/assets.xml
index e3858d3b053..ffd28eff59e 100644
--- a/addons/sale_product_matrix/views/assets.xml
+++ b/addons/sale_product_matrix/views/assets.xml
@@ -11,4 +11,10 @@
<script type="text/javascript" src="/sale_product_matrix/static/tests/section_and_note_widget_tests.js"></script>
</xpath>
</template>
+
+ <template id="assets_tests" name="Sale Product Matrix Assets Tests" inherit_id="web.assets_tests">
+ <xpath expr="." position="inside">
+ <script type="text/javascript" src="/sale_product_matrix/static/tests/tours/sale_product_matrix_tour.js"/>
+ </xpath>
+ </template>
</odoo>