| 1 |
|
| 2 |
|
| 3 |
import logging |
| 4 |
import lxml.html |
| 5 |
|
| 6 |
from odoo.fields import Command |
| 7 |
from odoo.tests import tagged |
| 8 |
|
| 9 |
from odoo.addons.base.tests.common import HttpCaseWithUserDemo |
| 10 |
from odoo.addons.website_sale.tests.common import WebsiteSaleCommon |
| 11 |
from odoo.addons.website.tests.common import HttpCaseWithWebsiteUser |
| 12 |
|
| 13 |
_logger = logging.getLogger(__name__) |
| 14 |
|
| 15 |
|
| 16 |
@tagged('post_install', '-at_install') |
| 17 |
class TestSaleProcess(HttpCaseWithUserDemo, WebsiteSaleCommon, HttpCaseWithWebsiteUser): |
| 18 |
|
| 19 |
@classmethod |
| 20 |
def setUpClass(cls): |
| 21 |
super().setUpClass() |
| 22 |
cls.storage_box = cls.env['product.product'].create({ |
| 23 |
'name': 'Storage Box', |
| 24 |
'standard_price': 70.0, |
| 25 |
'list_price': 79.0, |
| 26 |
'website_published': True, |
| 27 |
}) |
| 28 |
cls.product_attribute_legs = cls.env['product.attribute'].create({ |
| 29 |
'name': 'Legs', |
| 30 |
'sequence': 10, |
| 31 |
'value_ids': [ |
| 32 |
Command.create({ |
| 33 |
'name': 'Steel', |
| 34 |
'sequence': 1, |
| 35 |
}), |
| 36 |
Command.create({ |
| 37 |
'name': 'Aluminium', |
| 38 |
'sequence': 2, |
| 39 |
}), |
| 40 |
], |
| 41 |
}) |
| 42 |
cls.conference_chair = cls.env['product.template'].create({ |
| 43 |
'name': 'Conference Chair', |
| 44 |
'list_price': 16.50, |
| 45 |
'website_published': True, |
| 46 |
'accessory_product_ids': [Command.link(cls.storage_box.id)], |
| 47 |
'attribute_line_ids': [ |
| 48 |
Command.create({ |
| 49 |
'attribute_id': cls.product_attribute_legs.id, |
| 50 |
'value_ids': [Command.set(cls.product_attribute_legs.value_ids.ids)], |
| 51 |
}) |
| 52 |
], |
| 53 |
}) |
| 54 |
|
| 55 |
cls.chair_floor_protection = cls.env['product.template'].create({ |
| 56 |
'name': 'Chair floor protection', |
| 57 |
'list_price': 12.0, |
| 58 |
}) |
| 59 |
|
| 60 |
if 'optional_product_ids' in cls.env['product.template']: |
| 61 |
cls.conference_chair.optional_product_ids = [Command.set(cls.chair_floor_protection.ids)] |
| 62 |
|
| 63 |
cls.env['account.journal'].create({ |
| 64 |
'name': 'Cash - Test', |
| 65 |
'type': 'cash', |
| 66 |
'code': 'CASH - Test', |
| 67 |
}) |
| 68 |
|
| 69 |
|
| 70 |
cls.env.ref('base.partner_admin').write(cls.dummy_partner_address_values) |
| 71 |
cls.partner_website_user.write(cls.dummy_partner_address_values) |
| 72 |
|
| 73 |
if cls.env['ir.module.module']._get('payment_custom').state == 'installed': |
| 74 |
transfer_provider = cls.env.ref('payment.payment_provider_transfer') |
| 75 |
transfer_provider.write({ |
| 76 |
'state': 'enabled', |
| 77 |
'is_published': True, |
| 78 |
}) |
| 79 |
transfer_provider._transfer_ensure_pending_msg_is_set() |
| 80 |
|
| 81 |
def test_01_admin_shop_tour(self): |
| 82 |
self.start_tour(self.env['website'].get_client_action_url('/shop'), 'test_01_admin_shop_tour', login='admin') |
| 83 |
|
| 84 |
def test_01_cart_update_check(self): |
| 85 |
self.start_tour('/', 'shop_update_cart', login='admin') |
| 86 |
|
| 87 |
def test_02_admin_checkout(self): |
| 88 |
if self.env['ir.module.module']._get('payment_custom').state != 'installed': |
| 89 |
self.skipTest("Transfer provider is not installed") |
| 90 |
|
| 91 |
self.start_tour("/", 'shop_buy_product', login="admin") |
| 92 |
|
| 93 |
def test_03_demo_checkout(self): |
| 94 |
self.partner_demo.write(self.dummy_partner_address_values) |
| 95 |
if self.env['ir.module.module']._get('payment_custom').state != 'installed': |
| 96 |
self.skipTest("Transfer provider is not installed") |
| 97 |
|
| 98 |
self.start_tour("/", 'shop_buy_product', login="demo") |
| 99 |
|
| 100 |
def test_04_admin_website_sale_tour(self): |
| 101 |
if self.env['ir.module.module']._get('payment_custom').state != 'installed': |
| 102 |
self.skipTest("Transfer provider is not installed") |
| 103 |
|
| 104 |
self.env.company.country_id = self.country_us |
| 105 |
tax_group = self.env['account.tax.group'].create({'name': 'Tax 15%'}) |
| 106 |
tax = self.env['account.tax'].create({ |
| 107 |
'name': 'Tax 15%', |
| 108 |
'amount': 15, |
| 109 |
'type_tax_use': 'sale', |
| 110 |
'tax_group_id': tax_group.id |
| 111 |
}) |
| 112 |
|
| 113 |
self.product_product_7 = self.env['product.product'].create({ |
| 114 |
'name': 'Storage Box Test', |
| 115 |
'standard_price': 70.0, |
| 116 |
'list_price': 79.0, |
| 117 |
'website_published': True, |
| 118 |
'invoice_policy': 'delivery', |
| 119 |
}) |
| 120 |
self.product_product_7.taxes_id = [tax.id] |
| 121 |
self.env['res.config.settings'].create({ |
| 122 |
'auth_signup_uninvited': 'b2c', |
| 123 |
'show_line_subtotals_tax_selection': 'tax_excluded', |
| 124 |
}).execute() |
| 125 |
|
| 126 |
self.start_tour("/", 'website_sale_tour_1') |
| 127 |
self.start_tour( |
| 128 |
self.env['website'].get_client_action_url('/shop/cart'), |
| 129 |
'website_sale_tour_backend', |
| 130 |
login='admin' |
| 131 |
) |
| 132 |
self.start_tour("/", 'website_sale_tour_2', login="admin") |
| 133 |
|
| 134 |
def test_05_google_analytics_tracking(self): |
| 135 |
|
| 136 |
attribute = self.env['product.attribute'].create({ |
| 137 |
'name': 'Color', |
| 138 |
'sequence': 10, |
| 139 |
'display_type': 'color', |
| 140 |
'value_ids': [ |
| 141 |
Command.create({ |
| 142 |
'name': 'Red', |
| 143 |
}), |
| 144 |
Command.create({ |
| 145 |
'name': 'Pink', |
| 146 |
}), |
| 147 |
] |
| 148 |
}) |
| 149 |
self.env['product.template'].create({ |
| 150 |
'name': 'Colored T-Shirt', |
| 151 |
'standard_price': 500, |
| 152 |
'list_price': 750, |
| 153 |
'type': 'consu', |
| 154 |
'website_published': True, |
| 155 |
'attribute_line_ids': [ |
| 156 |
Command.create({ |
| 157 |
'attribute_id': attribute.id, |
| 158 |
'value_ids': attribute.value_ids, |
| 159 |
}) |
| 160 |
] |
| 161 |
}) |
| 162 |
self.env['website'].browse(1).write({'google_analytics_key': 'G-XXXXXXXXXXX'}) |
| 163 |
self.start_tour("/shop", 'google_analytics_view_item') |
| 164 |
|
| 165 |
self.env['product.template'].create({ |
| 166 |
'name': 'Basic Shirt', |
| 167 |
'standard_price': 500, |
| 168 |
'type': 'consu', |
| 169 |
'website_published': True |
| 170 |
}) |
| 171 |
self.start_tour("/shop", 'google_analytics_add_to_cart') |
| 172 |
|
| 173 |
def test_06_public_user_shop_repair(self): |
| 174 |
""" Public user purchasing repair service products in website shop. """ |
| 175 |
if self.env['ir.module.module']._get('repair').state != 'installed': |
| 176 |
self.skipTest("Repair is not installed") |
| 177 |
|
| 178 |
self.env['product.template'].create({ |
| 179 |
'name': 'Test Repair Service', |
| 180 |
'type': 'service', |
| 181 |
'service_tracking': 'repair', |
| 182 |
'sale_ok': True, |
| 183 |
'is_published': True, |
| 184 |
}) |
| 185 |
self.start_tour("/", 'shop_repair_product', login=None) |
| 186 |
|
| 187 |
def test_checkout_with_rewrite(self): |
| 188 |
|
| 189 |
self.env['website.rewrite'].create({ |
| 190 |
'name': 'Test Address Rename', |
| 191 |
'redirect_type': '308', |
| 192 |
'url_from': '/shop/address', |
| 193 |
'url_to': '/test/address', |
| 194 |
}) |
| 195 |
self.env['website.rewrite'].create({ |
| 196 |
'name': 'Test Checkout Rename', |
| 197 |
'redirect_type': '308', |
| 198 |
'url_from': '/shop/checkout', |
| 199 |
'url_to': '/test/checkout', |
| 200 |
}) |
| 201 |
self._create_so(partner_id=self.user_demo.partner_id.id) |
| 202 |
self.authenticate('demo', 'demo') |
| 203 |
response = self.url_open('/shop/address') |
| 204 |
self.assertEqual(response.status_code, 200) |
| 205 |
self.assertEqual(response.url[-13:], '/test/address') |
| 206 |
|
| 207 |
|
| 208 |
allowed_steps_domain = self.website._get_allowed_steps_domain() |
| 209 |
checkout_step = self.env.ref('website_sale.checkout_step_delivery') |
| 210 |
previous_step = checkout_step._get_previous_checkout_step(allowed_steps_domain) |
| 211 |
next_step = checkout_step._get_next_checkout_step(allowed_steps_domain) |
| 212 |
root = lxml.html.fromstring(response.content) |
| 213 |
self.assertEqual(len(root.xpath(f'//a[@href="{previous_step.step_href}"]//span[text()="{previous_step.back_button_label}"]')), 2) |
| 214 |
self.assertEqual(len(root.xpath(f'//a[@name="website_sale_main_button"][not(@href)]//span[text()="{next_step.main_button_label}"]')), 2) |
| 215 |
|
| 216 |
def test_update_same_address_billing_shipping_edit(self): |
| 217 |
''' Phone field should be required when updating an adress for billing and shipping ''' |
| 218 |
self.env['product.product'].create({ |
| 219 |
'name': 'Office Chair Black TEST', |
| 220 |
'list_price': 12.50, |
| 221 |
'is_published': True, |
| 222 |
}) |
| 223 |
self.start_tour("/shop", 'update_billing_shipping_address', login="website_user") |