77
88
99class TestProductSupplierinfoForCustomerSale (TransactionCase ):
10- def setUp (self ):
11- super ().setUp ()
12- self .supplierinfo_model = self .env ["product.supplierinfo" ]
13- self .customerinfo_model = self .env ["product.customerinfo" ]
14- self .pricelist_item_model = self .env ["product.pricelist.item" ]
15- self .pricelist_model = self .env ["product.pricelist" ]
16- self .customer = self ._create_customer ("customer1" )
17- self .product = self .env .ref ("product.product_product_4" )
18- self .product_variant_1 = self .env .ref ("product.product_product_4b" )
19- self .product_variant_2 = self .env .ref ("product.product_product_4c" )
20- self .customerinfo = self ._create_partnerinfo (
21- "customer" , self .customer , self .product
22- )
23- self .pricelist = self ._create_pricelist ("Test Pricelist" , self .product )
24- self .pricelist_item = self ._create_pricelist_item (
25- "Test Pricelist Item" , self .pricelist , self .product
26- )
27- self .company = self .env .ref ("base.main_company" )
28- self ._create_partnerinfo ("customer" , self .customer , self .product_variant_1 )
29- self ._create_partnerinfo (
30- "customer" , self .customer , self .product_variant_2 , empty_variant = True
31- )
32- self .product_template = self .env ["product.template" ].create (
10+ @classmethod
11+ def setUpClass (cls ):
12+ super ().setUpClass ()
13+ cls .supplierinfo_model = cls .env ["product.supplierinfo" ]
14+ cls .customerinfo_model = cls .env ["product.customerinfo" ]
15+ cls .pricelist_item_model = cls .env ["product.pricelist.item" ]
16+ cls .pricelist_model = cls .env ["product.pricelist" ]
17+ cls .customer = cls ._create_customer ("customer1" )
18+ cls .product = cls .env .ref ("product.product_product_4" )
19+ cls .product_variant_1 = cls .env .ref ("product.product_product_4b" )
20+ cls .product_variant_2 = cls .env .ref ("product.product_product_4c" )
21+ cls .customerinfo = cls ._create_partnerinfo (
22+ "customer" , cls .customer , cls .product
23+ )
24+ cls .pricelist = cls ._create_pricelist ("Test Pricelist" , cls .product )
25+ cls .pricelist_item = cls ._create_pricelist_item (
26+ "Test Pricelist Item" , cls .pricelist , cls .product
27+ )
28+ cls .company = cls .env .ref ("base.main_company" )
29+ cls ._create_partnerinfo ("customer" , cls .customer , cls .product_variant_1 )
30+ cls ._create_partnerinfo (
31+ "customer" , cls .customer , cls .product_variant_2 , empty_variant = True
32+ )
33+ cls .product_template = cls .env ["product.template" ].create (
3334 {"name" : "product wo variants" }
3435 )
35- self ._create_partnerinfo (
36+ cls ._create_partnerinfo (
3637 "customer" ,
37- self .customer ,
38- self .product_template .product_variant_ids [:1 ],
38+ cls .customer ,
39+ cls .product_template .product_variant_ids [:1 ],
3940 empty_variant = True ,
4041 )
41- self .pricelist_template = self ._create_pricelist (
42- "Test Pricelist Template" , self .product_template .product_variant_ids [:1 ]
42+ cls .pricelist_template = cls ._create_pricelist (
43+ "Test Pricelist Template" , cls .product_template .product_variant_ids [:1 ]
4344 )
44- self .env .user .groups_id |= self .env .ref ("product.group_product_pricelist" )
45+ cls .env .user .groups_id |= cls .env .ref ("product.group_product_pricelist" )
4546
46- def _create_customer (self , name ):
47- return self .env ["res.partner" ].create (
47+ @classmethod
48+ def _create_customer (cls , name ):
49+ return cls .env ["res.partner" ].create (
4850 {"name" : name , "email" : "example@yourcompany.com" , "phone" : 123456 }
4951 )
5052
53+ @classmethod
5154 def _create_partnerinfo (
52- self , supplierinfo_type , partner , product , empty_variant = False
55+ cls , supplierinfo_type , partner , product , empty_variant = False
5356 ):
5457 vals = {
5558 "partner_id" : partner .id ,
@@ -62,15 +65,17 @@ def _create_partnerinfo(
6265 if empty_variant :
6366 vals .pop ("product_id" , None )
6467 vals ["product_tmpl_id" ] = product .product_tmpl_id .id
65- return self .env ["product." + supplierinfo_type + "info" ].create (vals )
68+ return cls .env ["product." + supplierinfo_type + "info" ].create (vals )
6669
67- def _create_pricelist (self , name , product ):
68- return self .pricelist_model .create (
69- {"name" : name , "currency_id" : self .env .ref ("base.USD" ).id }
70+ @classmethod
71+ def _create_pricelist (cls , name , product ):
72+ return cls .pricelist_model .create (
73+ {"name" : name , "currency_id" : cls .env .ref ("base.USD" ).id }
7074 )
7175
72- def _create_pricelist_item (self , name , pricelist , product ):
73- return self .pricelist_item_model .create (
76+ @classmethod
77+ def _create_pricelist_item (cls , name , pricelist , product ):
78+ return cls .pricelist_item_model .create (
7479 {
7580 "name" : name ,
7681 "pricelist_id" : pricelist .id ,
0 commit comments