summaryrefslogtreecommitdiff
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
parent6c800032088128d818fc970afee7cc7f1c365a6e (diff)
[ADD] (*_)_product_matrix: test tours
closes odoo/odoo#40971 X-original-commit: d729460f5fc72aa70e0a024e1dff281299eed0e3 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
-rw-r--r--addons/product_matrix/tests/__init__.py4
-rw-r--r--addons/product_matrix/tests/common.py46
-rw-r--r--addons/purchase/views/purchase_views.xml6
-rw-r--r--addons/purchase_product_matrix/static/tests/tours/purchase_product_matrix_tour.js110
-rw-r--r--addons/purchase_product_matrix/tests/__init__.py4
-rw-r--r--addons/purchase_product_matrix/tests/test_purchase_matrix.py34
-rw-r--r--addons/purchase_product_matrix/views/assets.xml8
-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
11 files changed, 369 insertions, 4 deletions
diff --git a/addons/product_matrix/tests/__init__.py b/addons/product_matrix/tests/__init__.py
new file mode 100644
index 00000000000..511e649c9e2
--- /dev/null
+++ b/addons/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 common
diff --git a/addons/product_matrix/tests/common.py b/addons/product_matrix/tests/common.py
new file mode 100644
index 00000000000..51e0a366588
--- /dev/null
+++ b/addons/product_matrix/tests/common.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo.tests import tagged, common
+
+
+@tagged('post_install', '-at_install')
+class TestMatrixCommon(common.HttpCase):
+
+ def setUp(self):
+ super(TestMatrixCommon, self).setUp()
+
+ # Prepare relevant test data
+ # This is not included in demo data to avoid useless noise
+ product_attributes = self.env['product.attribute'].create([{
+ 'name': 'PA1',
+ 'create_variant': 'always',
+ 'sequence': 1
+ }, {
+ 'name': 'PA2',
+ 'create_variant': 'always',
+ 'sequence': 2
+ }, {
+ 'name': 'PA3',
+ 'create_variant': 'dynamic',
+ 'sequence': 3
+ }, {
+ 'name': 'PA4',
+ 'create_variant': 'no_variant',
+ 'sequence': 4
+ }])
+
+ self.env['product.attribute.value'].create([{
+ 'name': 'PAV' + str(product_attribute.sequence) + str(i),
+ 'attribute_id': product_attribute.id
+ } for i in range(1, 3) for product_attribute in product_attributes])
+
+ self.matrix_template = self.env['product.template'].create({
+ 'name': "Matrix",
+ 'type': "consu",
+ 'uom_id': self.ref("uom.product_uom_unit"),
+ 'uom_po_id': self.ref("uom.product_uom_unit"),
+ 'attribute_line_ids': [(0, 0, {
+ 'attribute_id': attribute.id,
+ 'value_ids': [(6, 0, attribute.value_ids.ids)]
+ }) for attribute in product_attributes],
+ })
diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml
index a9036caf30f..d255774d5fa 100644
--- a/addons/purchase/views/purchase_views.xml
+++ b/addons/purchase/views/purchase_views.xml
@@ -120,7 +120,7 @@
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
- <form string="Purchase Order">
+ <form string="Purchase Order" class="o_purchase_order">
<header>
<button name="action_rfq_send" states="draft" string="Send by Email" type="object" context="{'send_rfq':True}" class="oe_highlight"/>
<button name="print_quotation" string="Print RFQ" type="object" states="draft" class="oe_highlight" groups="base.group_user"/>
@@ -470,7 +470,7 @@
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<tree string="Purchase Order" multi_edit="1" decoration-bf="message_unread==True"
- decoration-muted="state=='cancel'" decoration-info="state in ('wait','confirmed')">
+ decoration-muted="state=='cancel'" decoration-info="state in ('wait','confirmed')" class="o_purchase_order">
<field name="message_unread" invisible="1"/>
<field name="partner_ref" optional="hide"/>
<field name="name" string="Reference" readonly="1"/>
@@ -496,7 +496,7 @@
<field name="name">purchase.order.view.tree</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
- <tree decoration-bf="message_unread==True" decoration-muted="state=='cancel'" decoration-info="state in ('wait','confirmed')" string="Purchase Order">
+ <tree decoration-bf="message_unread==True" decoration-muted="state=='cancel'" decoration-info="state in ('wait','confirmed')" string="Purchase Order" class="o_purchase_order">
<field name="message_unread" invisible="1"/>
<field name="partner_ref" optional="hide"/>
<field name="name" string="Reference" readonly="1"/>
diff --git a/addons/purchase_product_matrix/static/tests/tours/purchase_product_matrix_tour.js b/addons/purchase_product_matrix/static/tests/tours/purchase_product_matrix_tour.js
new file mode 100644
index 00000000000..9148f888b53
--- /dev/null
+++ b/addons/purchase_product_matrix/static/tests/tours/purchase_product_matrix_tour.js
@@ -0,0 +1,110 @@
+odoo.define('purchase_product_matrix.purchase_matrix_tour', function (require) {
+"use strict";
+
+var tour = require('web_tour.tour');
+
+tour.register('purchase_matrix_tour', {
+ url: "/web",
+ test: true,
+}, [tour.STEPS.SHOW_APPS_MENU_ITEM, {
+ trigger: '.o_app[data-menu-xmlid="purchase.menu_purchase_root"]',
+}, {
+ trigger: ".o_list_button_add",
+ extra_trigger: ".o_purchase_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_purchase_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)\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/purchase_product_matrix/tests/__init__.py b/addons/purchase_product_matrix/tests/__init__.py
new file mode 100644
index 00000000000..8c94384317a
--- /dev/null
+++ b/addons/purchase_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_purchase_matrix
diff --git a/addons/purchase_product_matrix/tests/test_purchase_matrix.py b/addons/purchase_product_matrix/tests/test_purchase_matrix.py
new file mode 100644
index 00000000000..fccf36ce87e
--- /dev/null
+++ b/addons/purchase_product_matrix/tests/test_purchase_matrix.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+import odoo.tests
+from odoo.addons.product_matrix.tests.common import TestMatrixCommon
+
+
+@odoo.tests.tagged('post_install', '-at_install')
+class TestPurchaseMatrixUi(TestMatrixCommon):
+
+ def test_purchase_matrix_ui(self):
+ self.start_tour("/web", 'purchase_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['purchase.order.line'].search([('product_id', 'in', self.matrix_template.product_variant_ids.ids)]).order_id.button_confirm()
+
+ self.matrix_template.flush()
+ self.assertEqual(round(self.matrix_template.purchased_product_qty, 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.purchased_product_qty, 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['purchase.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/purchase_product_matrix/views/assets.xml b/addons/purchase_product_matrix/views/assets.xml
index c9aaf58fbed..ff11e9907fd 100644
--- a/addons/purchase_product_matrix/views/assets.xml
+++ b/addons/purchase_product_matrix/views/assets.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
- <template id="assets_backend_inherit_purchase" inherit_id="web.assets_backend" name="Sale Grid assets">
+ <template id="assets_backend_inherit_purchase" inherit_id="web.assets_backend" name="Purchase Grid assets">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/purchase_product_matrix/static/src/js/product_matrix_configurator.js"/>
</xpath>
@@ -12,4 +12,10 @@
<script type="text/javascript" src="/purchase_product_matrix/static/tests/section_and_note_widget_tests.js"></script>
</xpath>
</template>
+
+ <template id="assets_tests" name="Purchase Product Matrix Assets Tests" inherit_id="web.assets_tests">
+ <xpath expr="." position="inside">
+ <script type="text/javascript" src="/purchase_product_matrix/static/tests/tours/purchase_product_matrix_tour.js"/>
+ </xpath>
+ </template>
</odoo>
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>