6
6
from odoo .addons .website_sale .controllers .main import WebsiteSale , PaymentPortal
7
7
from odoo .addons .website .tools import MockRequest
8
8
from odoo .addons .website_sale .models .product_template import ProductTemplate
9
- from odoo .exceptions import UserError
9
+ from odoo .exceptions import UserError , ValidationError
10
10
from odoo .tests .common import tagged
11
11
from odoo .fields import Command
12
12
@@ -20,6 +20,13 @@ def setUpClass(cls):
20
20
cls .website = cls .env ['website' ].browse (1 )
21
21
cls .WebsiteSaleController = WebsiteSale ()
22
22
cls .public_user = cls .env .ref ('base.public_user' )
23
+ cls .product = cls .env ['product.product' ].create ({
24
+ 'name' : 'Test Product' ,
25
+ 'sale_ok' : True ,
26
+ 'website_published' : True ,
27
+ 'lst_price' : 1000.0 ,
28
+ 'standard_price' : 800.0 ,
29
+ })
23
30
24
31
def test_add_cart_deleted_product (self ):
25
32
# Create a published product then unlink it
@@ -101,24 +108,29 @@ def test_zero_price_product_rule(self):
101
108
self .WebsiteSaleController .cart_update_json (product_id = product_service .id , add_qty = 1 )
102
109
103
110
def test_update_cart_before_payment (self ):
104
- product = self .env ['product.product' ].create ({
105
- 'name' : 'Test Product' ,
106
- 'sale_ok' : True ,
107
- 'website_published' : True ,
108
- 'lst_price' : 1000.0 ,
109
- 'standard_price' : 800.0 ,
110
- })
111
111
website = self .website .with_user (self .public_user )
112
- with MockRequest (product .with_user (self .public_user ).env , website = website ):
113
- self .WebsiteSaleController .cart_update_json (product_id = product .id , add_qty = 1 )
112
+ with MockRequest (self . product .with_user (self .public_user ).env , website = website ):
113
+ self .WebsiteSaleController .cart_update_json (product_id = self . product .id , add_qty = 1 )
114
114
sale_order = website .sale_get_order ()
115
115
sale_order .access_token = 'test_token'
116
116
old_amount = sale_order .amount_total
117
- self .WebsiteSaleController .cart_update_json (product_id = product .id , add_qty = 1 )
117
+ self .WebsiteSaleController .cart_update_json (product_id = self . product .id , add_qty = 1 )
118
118
# Try processing payment with the old amount
119
119
with self .assertRaises (UserError ):
120
120
PaymentPortal ().shop_payment_transaction (sale_order .id , sale_order .access_token , amount = old_amount )
121
121
122
+ def test_check_order_delivery_before_payment (self ):
123
+ website = self .website .with_user (self .public_user )
124
+ with MockRequest (self .product .with_user (self .public_user ).env , website = website ):
125
+ sale_order = self .env ['sale.order' ].create ({
126
+ 'partner_id' : self .public_user .id ,
127
+ 'order_line' : [Command .create ({'product_id' : self .product .id })],
128
+ 'access_token' : 'test_token' ,
129
+ })
130
+ # Try processing payment with a storable product and no carrier_id
131
+ with self .assertRaises (ValidationError ):
132
+ PaymentPortal ().shop_payment_transaction (sale_order .id , sale_order .access_token )
133
+
122
134
def test_update_cart_zero_qty (self ):
123
135
# Try to remove a product that has already been removed
124
136
product = self .env ['product.product' ].create ({
0 commit comments