Skip to content
Snippets Groups Projects
Commit c32e9a47 authored by Victor Feyens's avatar Victor Feyens
Browse files

[ADD] (*_)_product_matrix: test tours


closes odoo/odoo#40971

X-original-commit: d729460f
Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent 6c800032
No related branches found
No related tags found
No related merge requests found
Showing with 369 additions and 4 deletions
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import common
# -*- 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],
})
......@@ -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"/>
......
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).
},
]);
});
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_purchase_matrix
# -*- 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
)
<?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>
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).
},
]);
});
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_sale_matrix
# -*- 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
)
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment