-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathtest_sale.py
43 lines (37 loc) · 1.32 KB
/
test_sale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests.common import TransactionCase
class TestSaleOrderLine(TransactionCase):
def setUp(self):
super().setUp()
# Set up the environment
self.Product = self.env["product.product"]
self.Partner = self.env["res.partner"]
# Create a product
self.product = self.Product.create(
{
"name": "Test Product",
"type": "consu",
"list_price": 100.0,
"standard_price": 50.0,
}
)
# Create a customer
self.partner = self.Partner.create(
{
"name": "Test Customer",
"email": "[email protected]",
}
)
def test_onchange_product_id_no_customer(self):
# Create a sale order without a customer
so = Form(self.env["sale.order"])
# Try to add a product to the sale order line without a customer
with self.assertRaises(UserError):
so.order_line.new()
def test_onchange_product_id_customer(self):
so = Form(self.env["sale.order"])
so.partner_id = self.partner
with so.order_line.new() as line_form:
line_form.product_id = self.product
line_form.product_uom_qty = 1