[IMP] sale: Adapt tests to work with/without demo data

This commit is contained in:
Yannick Tivisse
2019-11-05 13:08:03 +01:00
parent 00e4df9702
commit 5361706e5e
6 changed files with 112 additions and 52 deletions
+16 -7
View File
@@ -67,8 +67,10 @@ class TestOnchangeProductId(TransactionCase):
def test_pricelist_application(self):
""" Test different prices are correctly applied based on dates """
support_product = self.env.ref('product.product_product_2')
support_product.list_price = 100
support_product = self.env['product.product'].create({
'name': 'Virtual Home Staging',
'list_price': 100,
})
partner = self.res_partner_model.create(dict(name="George"))
christmas_pricelist = self.env['product.pricelist'].create({
@@ -115,8 +117,10 @@ class TestOnchangeProductId(TransactionCase):
def test_pricelist_uom_discount(self):
""" Test prices and discounts are correctly applied based on date and uom"""
computer_case = self.env.ref('product.product_product_16')
computer_case.list_price = 100
computer_case = self.env['product.product'].create({
'name': 'Drawer Black',
'list_price': 100,
})
partner = self.res_partner_model.create(dict(name="George"))
categ_unit_id = self.ref('uom.product_uom_categ_unit')
goup_discount_id = self.ref('product.group_discount_per_so_line')
@@ -167,8 +171,10 @@ class TestOnchangeProductId(TransactionCase):
def test_pricelist_based_on_other(self):
""" Test price and discount are correctly applied with a pricelist based on an other one"""
computer_case = self.env.ref('product.product_product_16')
computer_case.list_price = 100
computer_case = self.env['product.product'].create({
'name': 'Drawer Black',
'list_price': 100,
})
partner = self.res_partner_model.create(dict(name="George"))
goup_discount_id = self.ref('product.group_discount_per_so_line')
self.env.user.write({'groups_id': [(4, goup_discount_id, 0)]})
@@ -217,7 +223,10 @@ class TestOnchangeProductId(TransactionCase):
def test_pricelist_with_other_currency(self):
""" Test prices are correctly applied with a pricelist with an other currency"""
computer_case = self.env.ref('product.product_product_16')
computer_case = self.env['product.product'].create({
'name': 'Drawer Black',
'list_price': 100,
})
computer_case.list_price = 100
partner = self.res_partner_model.create(dict(name="George"))
categ_unit_id = self.ref('uom.product_uom_categ_unit')
+46 -20
View File
@@ -1,25 +1,28 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import OrderedDict
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.addons.account.tests.account_test_no_chart import TestAccountNoChartCommon
class TestSale(AccountingTestCase):
def setUp(self):
super(TestSale, self).setUp()
@classmethod
def setUpClass(cls):
super(TestSale, cls).setUpClass()
# some users
group_manager = self.env.ref('sales_team.group_sale_manager')
group_user = self.env.ref('sales_team.group_sale_salesman')
self.manager = self.env['res.users'].create({
group_manager = cls.env.ref('sales_team.group_sale_manager')
group_user = cls.env.ref('sales_team.group_sale_salesman')
cls.manager = cls.env['res.users'].create({
'name': 'Andrew Manager',
'login': 'manager',
'email': 'a.m@example.com',
'signature': '--\nAndreww',
'notification_type': 'email',
'groups_id': [(6, 0, [group_manager.id, self.env.ref('base.group_user').id])]
'groups_id': [(6, 0, [group_manager.id, cls.env.ref('base.group_user').id])]
})
self.user = self.env['res.users'].create({
cls.user = cls.env['res.users'].create({
'name': 'Mark User',
'login': 'user',
'email': 'm.u@example.com',
@@ -28,39 +31,62 @@ class TestSale(AccountingTestCase):
'groups_id': [(6, 0, [group_user.id])]
})
# create quotation with differend kinds of products (all possible combinations)
service_delivery = self.env['product.product'].create({
service_delivery = cls.env['product.product'].create({
'name': 'Cost-plus Contract',
'categ_id': self.env.ref('product.product_category_5').id,
# 'categ_id': cls.env.ref('product.product_category_5').id,
'categ_id': cls.env.ref('product.product_category_all').id,
'standard_price': 200.0,
'list_price': 180.0,
'type': 'service',
'uom_id': self.env.ref('uom.product_uom_unit').id,
'uom_po_id': self.env.ref('uom.product_uom_unit').id,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'default_code': 'SERV_DEL',
'invoice_policy': 'delivery',
})
service_order_01 = self.env['product.product'].create({
service_order_01 = cls.env['product.product'].create({
'name': 'Remodeling Service',
'categ_id': self.env.ref('product.product_category_3').id,
'categ_id': cls.env.ref('product.product_category_all').id,
'standard_price': 40.0,
'list_price': 90.0,
'type': 'service',
'uom_id': self.env.ref('uom.product_uom_hour').id,
'uom_po_id': self.env.ref('uom.product_uom_hour').id,
'uom_id': cls.env.ref('uom.product_uom_hour').id,
'uom_po_id': cls.env.ref('uom.product_uom_hour').id,
'description': 'Example of product to invoice on order',
'default_code': 'PRE-PAID',
'invoice_policy': 'order',
})
product_order_01 = self.env.ref('product.product_order_01')
product_order_01.type = 'consu'
self.products = OrderedDict([
product_order_01 = cls.env['product.product'].create({
'name': 'Office Design Software',
'categ_id': cls.env.ref('product.product_category_all').id,
'standard_price': 235.0,
'list_price': 280.0,
'type': 'consu', # Will be changed in 'product' in sale_stock
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'default_code': 'FURN_9999',
'invoice_policy': 'order',
})
product_delivery_01 = cls.env['product.product'].create({
'name': 'Office Chair',
'categ_id': cls.env.ref('product.product_category_all').id,
'standard_price': 55.0,
'list_price': 70.0,
'type': 'consu', # Will be changed in 'product' in sale_stock
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'default_code': 'FURN_7777',
'invoice_policy': 'delivery',
})
cls.products = OrderedDict([
('prod_order', product_order_01),
('serv_del', service_delivery),
('serv_order', service_order_01),
('prod_del', self.env.ref('product.product_delivery_01')),
('prod_del', product_delivery_01),
])
self.partner = self.env.ref('base.res_partner_1')
cls.partner = cls.env['res.partner'].create({'name': 'A test Partner'})
class TestCommonSaleNoChart(TestAccountNoChartCommon):
+19 -2
View File
@@ -266,13 +266,30 @@ class TestSaleOrder(TestCommonSaleNoChart):
def test_so_create_multicompany(self):
"""Check that only taxes of the right company are applied on the lines."""
user_demo = self.env.ref('base.user_demo')
# Preparing test Data
company_1 = self.env.ref('base.main_company')
company_2 = self.env['res.company'].create({
'name': 'company 2',
'parent_id': company_1.id,
})
user_demo = self.env['res.users'].create({
'login': 'zizizmyuser',
'password': 'zizizmyuser',
'partner_id': self.env['res.partner'].create({'name': 'Zizizmypartner'}).id,
'company_ids': [(6, False, [company_1.id])],
'company_id': company_1.id,
'groups_id': [(6, 0, [
self.env.ref('base.group_user').id,
self.env.ref('base.group_partner_manager').id,
self.env.ref('sales_team.group_sale_manager').id])]})
so_partner = self.env['res.partner'].create({'name': 'SO Partner'})
so_partner.write({
'property_account_position_id': False,
})
tax_company_1 = self.env['account.tax'].create({
'name': 'T1',
'amount': 90,
@@ -291,7 +308,7 @@ class TestSaleOrder(TestCommonSaleNoChart):
})
so_1 = self.env['sale.order'].with_user(user_demo.id).create({
'partner_id': self.env.ref('base.res_partner_2').id,
'partner_id': self.env['res.partner'].create({'name': 'A partner'}).id,
'company_id': company_1.id,
})
so_1.write({
@@ -7,27 +7,29 @@ from odoo.tests import tagged
class TestSaleProductAttributeValueSetup(TestProductAttributeValueSetup):
def _setup_currency(self, currency_ratio=2):
@classmethod
def _setup_currency(cls, currency_ratio=2):
"""Get or create a currency. This makes the test non-reliant on demo.
With an easy currency rate, for a simple 2 ratio in the following tests.
"""
from_currency = self.computer.currency_id
self._set_or_create_rate_today(from_currency, rate=1)
to_currency = self._get_or_create_currency("my currency", "C")
self._set_or_create_rate_today(to_currency, currency_ratio)
from_currency = cls.computer.currency_id
cls._set_or_create_rate_today(from_currency, rate=1)
to_currency = cls._get_or_create_currency("my currency", "C")
cls._set_or_create_rate_today(to_currency, currency_ratio)
return to_currency
def _set_or_create_rate_today(self, currency, rate):
@classmethod
def _set_or_create_rate_today(cls, currency, rate):
"""Get or create a currency rate for today. This makes the test
non-reliant on demo data."""
name = fields.Date.today()
currency_id = currency.id
company_id = self.env.company.id
company_id = cls.env.company.id
CurrencyRate = self.env['res.currency.rate']
CurrencyRate = cls.env['res.currency.rate']
currency_rate = CurrencyRate.search([
('company_id', '=', company_id),
@@ -45,10 +47,11 @@ class TestSaleProductAttributeValueSetup(TestProductAttributeValueSetup):
'rate': rate,
})
def _get_or_create_currency(self, name, symbol):
@classmethod
def _get_or_create_currency(cls, name, symbol):
"""Get or create a currency based on name. This makes the test
non-reliant on demo data."""
currency = self.env['res.currency'].search([('name', '=', name)])
currency = cls.env['res.currency'].search([('name', '=', name)])
return currency or currency.create({
'name': name,
'symbol': symbol,
@@ -125,7 +128,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
self.assertFalse(self.computer._is_combination_possible(computer_ssd_256 + computer_ram_8 + computer_hdd_1))
# CASE: OK after attribute line removed
self.computer_hdd_attribute_lines.unlink()
self.computer_hdd_attribute_lines.write({'active': False})
self.assertTrue(self.computer._is_combination_possible(computer_ssd_256 + computer_ram_8))
# CASE: not archived (with no_variant)
@@ -142,7 +145,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
self.assertFalse(self.computer._is_combination_possible(computer_ssd_256 + computer_ram_8 + computer_hdd_1))
# CASE: archived combination has different attributes (including no_variant)
self.computer_ssd_attribute_lines.unlink()
self.computer_ssd_attribute_lines.write({'active': False})
variant4 = self.computer._get_variant_for_combination(computer_ram_8 + computer_hdd_1)
self.env['sale.order.line'].create({
@@ -153,7 +156,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
self.assertTrue(self.computer._is_combination_possible(computer_ram_8 + computer_hdd_1))
# CASE: archived combination has different attributes (without no_variant)
self.computer_hdd_attribute_lines.unlink()
self.computer_hdd_attribute_lines.write({'active': False})
self.hdd_attribute.create_variant = 'always'
self._add_hdd_attribute_line()
computer_ssd_256 = self._get_product_template_attribute_value(self.ssd_256)
@@ -229,7 +232,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
# CASE: no_variant combination, it's another variant now
self.computer_ssd_attribute_lines.unlink()
self.computer_ssd_attribute_lines.write({'active': False})
self.ssd_attribute.create_variant = 'no_variant'
self._add_ssd_attribute_line()
computer_ssd_256 = self._get_product_template_attribute_value(self.ssd_256)
@@ -248,7 +251,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
self.assertEqual(res['list_price'], 2222 * currency_ratio)
# CASE: dynamic combination, but the variant already exists
self.computer_hdd_attribute_lines.unlink()
self.computer_hdd_attribute_lines.write({'active': False})
self.hdd_attribute.create_variant = 'dynamic'
self._add_hdd_attribute_line()
computer_ssd_256 = self._get_product_template_attribute_value(self.ssd_256)
@@ -347,7 +350,7 @@ class TestSaleProductAttributeValueConfig(TestSaleProductAttributeValueSetup):
"""The goal of this test is to make sure the create_product_variant does
work with dynamic. If the combination is possible, it should create it.
If it's not possible, it should not create it."""
self.computer_hdd_attribute_lines.unlink()
self.computer_hdd_attribute_lines.write({'active': False})
self.hdd_attribute.create_variant = 'dynamic'
self._add_hdd_attribute_line()
+6 -5
View File
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo.tests
from odoo.addons.base.tests.common import HttpCaseWithUserPortal
from odoo.tests import tagged
@odoo.tests.common.tagged('post_install', '-at_install')
class TestSaleSignature(odoo.tests.HttpCase):
@tagged('post_install', '-at_install')
class TestSaleSignature(HttpCaseWithUserPortal):
def test_01_portal_sale_signature_tour(self):
"""The goal of this test is to make sure the portal user can sign SO."""
portal_user = self.env.ref('base.partner_demo_portal')
portal_user = self.partner_portal
# create a SO to be signed
sales_order = self.env['sale.order'].create({
'name': 'test SO',
@@ -19,7 +20,7 @@ class TestSaleSignature(odoo.tests.HttpCase):
})
self.env['sale.order.line'].create({
'order_id': sales_order.id,
'product_id': self.env.ref('product.product_product_6').id,
'product_id': self.env['product.product'].create({'name': 'A product'}).id,
})
# must be sent to the user so he can see it
+5 -1
View File
@@ -17,8 +17,12 @@ class TestSaleTransaction(AccountingTestCase):
'name': 'Product A',
})
self.env.ref('payment.payment_acquirer_transfer').journal_id = self.cash_journal
if not self.env.user.company_id.country_id:
self.env.user.company_id.country_id = self.env.ref('base.us')
order = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'partner_id': self.env['res.partner'].create({'name': 'A partner'}).id,
'order_line': [
(0, False, {
'product_id': product.id,