[FIX] point_of_sale,pos_hr,pos_coupon: adapt tests for localization builds

Part of task 2124952

By using AccountTestInvoicingHttpCommon, we have a setup independant
from the demo datas. This also prevents running tests with incompatible
localization: the tests for l10n with another currency than USD failed
because of the demo datas preventing the change of currency.
This commit is contained in:
wan
2021-02-17 08:39:28 +00:00
parent 7da284ea5b
commit 82c75aeff3
3 changed files with 89 additions and 77 deletions
+63 -61
View File
@@ -4,33 +4,44 @@
from odoo import tools
from odoo.api import Environment
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
from odoo.addons.account.tests.common import AccountTestInvoicingHttpCommon
from datetime import date, timedelta
import odoo.tests
class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
class TestPointOfSaleHttpCommon(AccountTestInvoicingHttpCommon):
def setUp(self):
super().setUp()
env = self.env(user=self.env.ref('base.user_admin'))
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
env = cls.env
cls.env.user.groups_id += env.ref('point_of_sale.group_pos_manager')
journal_obj = env['account.journal']
account_obj = env['account.account']
main_company = env.ref('base.main_company')
self.main_pos_config = env.ref('point_of_sale.pos_config_main')
env['res.partner'].create({
'name': 'Deco Addict',
})
main_company = cls.company_data['company']
account_receivable = account_obj.create({'code': 'X1012',
'name': 'Account Receivable - Test',
'user_type_id': env.ref('account.data_account_type_receivable').id,
'reconcile': True})
self.env.company.account_default_pos_receivable_account_id = account_receivable
env.company.account_default_pos_receivable_account_id = account_receivable
env['ir.property']._set_default('property_account_receivable_id', 'res.partner', account_receivable, main_company)
# Pricelists are set below, do not take demo data into account
env['ir.property'].sudo().search([('name', '=', 'property_product_pricelist')]).unlink()
self.env['ir.property']._set_default('property_account_receivable_id', 'res.partner', account_receivable, main_company)
env['pos.payment.method'].create({
'name': 'Bank',
})
cls.main_pos_config = env['pos.config'].create({
'name': 'Shop',
'barcode_nomenclature_id': env.ref('barcodes.default_barcode_nomenclature').id,
})
env['res.partner'].create({
'name': 'Deco Addict',
})
cash_journal = journal_obj.create({
'name': 'Cash Test',
@@ -41,10 +52,10 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
})
# Archive all existing product to avoid noise during the tours
all_pos_product = self.env['product.product'].search([('available_in_pos', '=', True)])
discount = self.env.ref('point_of_sale.product_product_consumable')
self.tip = self.env.ref('point_of_sale.product_product_tip')
(all_pos_product - discount - self.tip)._write({'active': False})
all_pos_product = env['product.product'].search([('available_in_pos', '=', True)])
discount = env.ref('point_of_sale.product_product_consumable')
cls.tip = env.ref('point_of_sale.product_product_tip')
(all_pos_product - discount - cls.tip)._write({'active': False})
# In DESKS categ: Desk Pad
pos_categ_desks = env.ref('point_of_sale.pos_category_desks')
@@ -56,7 +67,7 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
pos_categ_chairs = env.ref('point_of_sale.pos_category_chairs')
# test an extra price on an attribute
self.whiteboard_pen = env['product.product'].create({
cls.whiteboard_pen = env['product.product'].create({
'name': 'Whiteboard Pen',
'available_in_pos': True,
'list_price': 1.20,
@@ -65,45 +76,45 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'to_weight': True,
'pos_categ_id': pos_categ_misc.id,
})
self.wall_shelf = env['product.product'].create({
cls.wall_shelf = env['product.product'].create({
'name': 'Wall Shelf Unit',
'available_in_pos': True,
'list_price': 1.98,
'taxes_id': False,
})
self.small_shelf = env['product.product'].create({
cls.small_shelf = env['product.product'].create({
'name': 'Small Shelf',
'available_in_pos': True,
'list_price': 2.83,
'taxes_id': False,
})
self.magnetic_board = env['product.product'].create({
cls.magnetic_board = env['product.product'].create({
'name': 'Magnetic Board',
'available_in_pos': True,
'list_price': 1.98,
'taxes_id': False,
})
self.monitor_stand = env['product.product'].create({
cls.monitor_stand = env['product.product'].create({
'name': 'Monitor Stand',
'available_in_pos': True,
'list_price': 3.19,
'taxes_id': False,
})
self.desk_pad = env['product.product'].create({
cls.desk_pad = env['product.product'].create({
'name': 'Desk Pad',
'available_in_pos': True,
'list_price': 1.98,
'taxes_id': False,
'pos_categ_id': pos_categ_desks.id,
})
self.letter_tray = env['product.product'].create({
cls.letter_tray = env['product.product'].create({
'name': 'Letter Tray',
'available_in_pos': True,
'list_price': 4.80,
'taxes_id': False,
'pos_categ_id': pos_categ_chairs.id,
})
self.desk_organizer = env['product.product'].create({
cls.desk_organizer = env['product.product'].create({
'name': 'Desk Organizer',
'available_in_pos': True,
'list_price': 5.10,
@@ -124,7 +135,7 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'attribute_id': attribute.id,
})
line = env['product.template.attribute.line'].create({
'product_tmpl_id': self.whiteboard_pen.product_tmpl_id.id,
'product_tmpl_id': cls.whiteboard_pen.product_tmpl_id.id,
'attribute_id': attribute.id,
'value_ids': [(6, 0, attribute_value.ids)]
})
@@ -201,12 +212,12 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'compute_price': 'fixed',
'fixed_price': 2,
'applied_on': '0_product_variant',
'product_id': self.wall_shelf.id,
'product_id': cls.wall_shelf.id,
}), (0, 0, {
'compute_price': 'fixed',
'fixed_price': 13.95, # test for issues like in 7f260ab517ebde634fc274e928eb062463f0d88f
'applied_on': '0_product_variant',
'product_id': self.small_shelf.id,
'product_id': cls.small_shelf.id,
})],
})
@@ -216,17 +227,17 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'compute_price': 'percentage',
'percent_price': 100,
'applied_on': '0_product_variant',
'product_id': self.wall_shelf.id,
'product_id': cls.wall_shelf.id,
}), (0, 0, {
'compute_price': 'percentage',
'percent_price': 99,
'applied_on': '0_product_variant',
'product_id': self.small_shelf.id,
'product_id': cls.small_shelf.id,
}), (0, 0, {
'compute_price': 'percentage',
'percent_price': 0,
'applied_on': '0_product_variant',
'product_id': self.magnetic_board.id,
'product_id': cls.magnetic_board.id,
})],
})
@@ -237,33 +248,33 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'price_discount': 6,
'price_surcharge': 5,
'applied_on': '0_product_variant',
'product_id': self.wall_shelf.id,
'product_id': cls.wall_shelf.id,
}), (0, 0, {
# .99 prices
'compute_price': 'formula',
'price_surcharge': -0.01,
'price_round': 1,
'applied_on': '0_product_variant',
'product_id': self.small_shelf.id,
'product_id': cls.small_shelf.id,
}), (0, 0, {
'compute_price': 'formula',
'price_min_margin': 10,
'price_max_margin': 100,
'applied_on': '0_product_variant',
'product_id': self.magnetic_board.id,
'product_id': cls.magnetic_board.id,
}), (0, 0, {
'compute_price': 'formula',
'price_surcharge': 10,
'price_max_margin': 5,
'applied_on': '0_product_variant',
'product_id': self.monitor_stand.id,
'product_id': cls.monitor_stand.id,
}), (0, 0, {
'compute_price': 'formula',
'price_discount': -100,
'price_min_margin': 5,
'price_max_margin': 20,
'applied_on': '0_product_variant',
'product_id': self.desk_pad.id,
'product_id': cls.desk_pad.id,
})],
})
@@ -274,13 +285,13 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'fixed_price': 1,
'applied_on': '0_product_variant',
'min_quantity': 2,
'product_id': self.wall_shelf.id,
'product_id': cls.wall_shelf.id,
}), (0, 0, {
'compute_price': 'fixed',
'fixed_price': 2,
'applied_on': '0_product_variant',
'min_quantity': 1,
'product_id': self.wall_shelf.id,
'product_id': cls.wall_shelf.id,
}), (0, 0, {
'compute_price': 'fixed',
'fixed_price': 2,
@@ -296,7 +307,7 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
'compute_price': 'fixed',
'fixed_price': 1,
'applied_on': '1_product',
'product_tmpl_id': self.wall_shelf.product_tmpl_id.id,
'product_tmpl_id': cls.wall_shelf.product_tmpl_id.id,
}), (0, 0, {
'compute_price': 'fixed',
'fixed_price': 2,
@@ -409,23 +420,12 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
excluded_pricelist = env['product.pricelist'].create({
'name': 'Not loaded'
})
res_partner_18 = self.env['res.partner'].create({
res_partner_18 = env['res.partner'].create({
'name': 'Lumber Inc',
'is_company': True,
})
res_partner_18.property_product_pricelist = excluded_pricelist
partner = self.env['res.partner'].create({
'name': 'TEST PARTNER',
'email': 'test@partner.com',
})
# set the company currency to USD, otherwise it will assume
# euro's. this will cause issues as the sales journal is in
# USD, because of this all products would have a different
# price
main_company.currency_id = env.ref('base.USD')
test_sale_journal = journal_obj.create({'name': 'Sales Journal - Test',
'code': 'TSJ',
'type': 'sale',
@@ -437,9 +437,9 @@ class TestPointOfSaleHttpCommon(odoo.tests.HttpCase):
src_tax = env['account.tax'].create({'name': "SRC", 'amount': 10})
dst_tax = env['account.tax'].create({'name': "DST", 'amount': 5})
self.letter_tray.taxes_id = [(6, 0, [src_tax.id])]
cls.letter_tray.taxes_id = [(6, 0, [src_tax.id])]
self.main_pos_config.write({
cls.main_pos_config.write({
'tax_regime_selection': True,
'fiscal_position_ids': [(0, 0, {
'name': "FP-POS-2M",
@@ -489,11 +489,11 @@ class TestUi(TestPointOfSaleHttpCommon):
# this you end up with js, css but no qweb.
self.env['ir.module.module'].search([('name', '=', 'point_of_sale')], limit=1).state = 'installed'
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'pos_pricelist', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'pos_basic_order', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ProductScreenTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ReceiptScreenTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'pos_pricelist', login="accountman")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'pos_basic_order', login="accountman")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ProductScreenTour', login="accountman")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenTour', login="accountman")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ReceiptScreenTour', login="accountman")
for order in self.env['pos.order'].search([]):
self.assertEqual(order.state, 'paid', "Validated order has payment of " + str(order.amount_paid) + " and total of " + str(order.amount_total))
@@ -504,22 +504,24 @@ class TestUi(TestPointOfSaleHttpCommon):
def test_02_pos_with_invoiced(self):
self.main_pos_config.open_session_cb(check_coa=False)
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ChromeTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'ChromeTour', login="accountman")
n_invoiced = self.env['pos.order'].search_count([('state', '=', 'invoiced')])
n_paid = self.env['pos.order'].search_count([('state', '=', 'paid')])
self.assertEqual(n_invoiced, 1, 'There should be 1 invoiced order.')
self.assertEqual(n_paid, 2, 'There should be 2 paid order.')
def test_03_order_management(self):
if hasattr(self.main_pos_config, 'module_pos_restaurant'):
self.main_pos_config.module_pos_restaurant = False
self.main_pos_config.write({ 'manage_orders': True, 'module_account': True })
self.main_pos_config.open_session_cb(check_coa=False)
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'OrderManagementScreenTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'OrderManagementScreenTour', login="accountman")
def test_04_product_configurator(self):
self.main_pos_config.write({ 'product_configurator': True })
self.main_pos_config.open_session_cb(check_coa=False)
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config, 'ProductConfiguratorTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config, 'ProductConfiguratorTour', login="accountman")
def test_05_ticket_screen(self):
self.main_pos_config.open_session_cb(check_coa=False)
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'TicketScreenTour', login="admin")
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'TicketScreenTour', login="accountman")
+3 -5
View File
@@ -100,9 +100,7 @@ class TestUi(TestPointOfSaleHttpCommon):
for promo_program in self.promo_programs:
pos_config.promo_program_ids.add(promo_program)
self.main_pos_config.with_user(self.env.ref("base.user_admin")).open_session_cb(
check_coa=False
)
self.main_pos_config.open_session_cb(check_coa=False)
##
# Tour Part 1
@@ -113,7 +111,7 @@ class TestUi(TestPointOfSaleHttpCommon):
self.start_tour(
"/pos/web?config_id=%d" % self.main_pos_config.id,
"PosCouponTour1",
login="admin",
login="accountman",
)
# check coupon usage
@@ -161,7 +159,7 @@ class TestUi(TestPointOfSaleHttpCommon):
self.start_tour(
"/pos/web?config_id=%d" % self.main_pos_config.id,
"PosCouponTour2",
login="admin",
login="accountman",
)
self.assertEqual(self.coupon4.state, "new")
self.assertEqual(promo_coupon4.state, "new")
+23 -11
View File
@@ -11,19 +11,28 @@ from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCom
class TestPosHrHttpCommon(TestPointOfSaleHttpCommon):
def setUp(self):
super().setUp()
self.main_pos_config.write({"module_pos_hr": True})
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env.user.groups_id += cls.env.ref('hr.group_hr_user')
cls.main_pos_config.write({"module_pos_hr": True})
# Admin employee
self.env.ref("hr.employee_admin").write(
{"name": "Mitchell Admin", "pin": False}
)
admin = cls.env.ref("hr.employee_admin").sudo().copy({
"company_id": cls.env.company.id,
"user_id": cls.env.user.id,
"name": "Mitchell Admin",
"pin": False,
})
# User employee
emp1 = self.env.ref("hr.employee_han")
emp1 = cls.env.ref("hr.employee_han").sudo().copy({
"company_id": cls.env.company.id,
})
emp1_user = new_test_user(
self.env,
cls.env,
login="emp1_user",
groups="base.group_user",
name="Pos Employee1",
@@ -32,10 +41,13 @@ class TestPosHrHttpCommon(TestPointOfSaleHttpCommon):
emp1.write({"name": "Pos Employee1", "pin": "2580", "user_id": emp1_user.id})
# Non-user employee
emp2 = self.env.ref("hr.employee_jve")
emp2 = cls.env.ref("hr.employee_jve").sudo().copy({
"company_id": cls.env.company.id,
})
emp2.write({"name": "Pos Employee2", "pin": "1234"})
(admin + emp1 + emp2).company_id = cls.env.company
with Form(self.main_pos_config) as config:
with Form(cls.main_pos_config) as config:
config.employee_ids.add(emp1)
config.employee_ids.add(emp2)
@@ -49,5 +61,5 @@ class TestUi(TestPosHrHttpCommon):
self.start_tour(
"/pos/ui?config_id=%d" % self.main_pos_config.id,
"PosHrTour",
login="admin",
login="accountman",
)