11# Copyright 2021 Camptocamp
22# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33
4- from odoo .tests .common import RecordCapturer , TransactionCase
4+ from odoo import Command
5+ from odoo .tests .common import RecordCapturer
56
7+ from odoo .addons .base .tests .common import BaseCommon
68
7- class TestIntercompanyDelivery (TransactionCase ):
8- def setUp (self ):
9- super ().setUp ()
10- self .user_demo = self .env ["res.users" ].create (
9+
10+ class TestIntercompanyDelivery (BaseCommon ):
11+ @classmethod
12+ def setUpClass (cls ):
13+ super ().setUpClass ()
14+ cls .user_demo = cls .env ["res.users" ].create (
1115 {
1216 "login" : "firstnametest" ,
1317 "name" : "User Demo" ,
1418 "email" : "firstnametest@example.org" ,
1519 "groups_id" : [
16- ( 4 , self .env .ref ("base.group_user" ).id ),
17- ( 4 , self .env .ref ("stock.group_stock_user" ).id ),
20+ Command . link ( cls .env .ref ("base.group_user" ).id ),
21+ Command . link ( cls .env .ref ("stock.group_stock_user" ).id ),
1822 ],
1923 }
2024 )
21- company_obj = self .env ["res.company" ]
22- # Create 2 companies and configure intercompany picking type param on them
23- self .company1 = company_obj .create ({"name" : "Company A" })
24- self .company2 = company_obj .create ({"name" : "Company B" })
25- self .picking_type_1 = (
26- self .env ["stock.picking.type" ]
25+ company_obj = cls .env ["res.company" ]
26+ cls .company1 = company_obj .create ({"name" : "Company A" })
27+ cls .company2 = company_obj .create ({"name" : "Company B" })
28+ cls .picking_type_1 = (
29+ cls .env ["stock.picking.type" ]
2730 .sudo ()
2831 .search (
2932 [
30- ("company_id" , "=" , self .company1 .id ),
33+ ("company_id" , "=" , cls .company1 .id ),
3134 ("name" , "=" , "Delivery Orders" ),
3235 ],
3336 limit = 1 ,
3437 )
3538 )
36- self .picking_type_2 = (
37- self .env ["stock.picking.type" ]
39+ cls .picking_type_2 = (
40+ cls .env ["stock.picking.type" ]
3841 .sudo ()
3942 .search (
40- [("company_id" , "=" , self .company2 .id ), ("name" , "=" , "Receipts" )],
43+ [
44+ ("company_id" , "=" , cls .company2 .id ),
45+ ("name" , "=" , "Receipts" ),
46+ ],
4147 limit = 1 ,
4248 )
4349 )
4450
45- self .company1 .intercompany_in_type_id = self .picking_type_1 .id
46- self .company2 .intercompany_in_type_id = self .picking_type_2 .id
47- # assign both companies to current user
48- self .user_demo .write (
51+ cls .company1 .intercompany_in_type_id = cls .picking_type_1 .id
52+ cls .company2 .intercompany_in_type_id = cls .picking_type_2 .id
53+ cls .user_demo .write (
4954 {
50- "company_id" : self .company1 .id ,
51- "company_ids" : [(4 , self .company1 .id ), (4 , self .company2 .id )],
55+ "company_id" : cls .company1 .id ,
56+ "company_ids" : [
57+ Command .link (cls .company1 .id ),
58+ Command .link (cls .company2 .id ),
59+ ],
5260 }
5361 )
54- # create storable product
55- self .product1 = self .env ["product.product" ].create (
62+ cls .user_demo .partner_id .with_context (
63+ allowed_company_ids = [cls .company1 .id , cls .company2 .id ]
64+ ).write ({})
65+
66+ cls .product1 = cls .env ["product.product" ].create (
5667 {
5768 "name" : "Product A" ,
5869 "type" : "product" ,
59- "categ_id" : self .env .ref ("product.product_category_all" ).id ,
70+ "categ_id" : cls .env .ref ("product.product_category_all" ).id ,
6071 "qty_available" : 100 ,
6172 }
6273 )
63- self .stock_location = (
64- self .env ["stock.location" ]
74+ cls .stock_location = (
75+ cls .env ["stock.location" ]
6576 .sudo ()
66- .search ([("name" , "=" , "Stock" ), ("company_id" , "=" , self .company1 .id )])
77+ .search (
78+ [("name" , "=" , "Stock" ), ("company_id" , "=" , cls .company1 .id )], limit = 1
79+ )
6780 )
68- self .uom_unit = self .env .ref ("uom.product_uom_unit" )
81+ cls .uom_unit = cls .env .ref ("uom.product_uom_unit" )
6982
7083 def test_picking_creation (self ):
7184 stock_location = self .env ["stock.location" ].search (
72- [("usage" , "=" , "internal" ), ("company_id" , "=" , self .company1 .id )]
85+ [("usage" , "=" , "internal" ), ("company_id" , "=" , self .company1 .id )], limit = 1
7386 )
7487 custs_location = self .env .ref ("stock.stock_location_customers" )
7588 custs_location .company_id = False
@@ -93,7 +106,7 @@ def test_picking_creation(self):
93106 "location_dest_id" : custs_location .id ,
94107 "product_id" : self .product1 .id ,
95108 "product_uom_id" : self .uom_unit .id ,
96- "qty_done " : 1.0 ,
109+ "quantity " : 1.0 ,
97110 "picking_id" : picking .id ,
98111 }
99112 )
@@ -105,12 +118,12 @@ def test_picking_creation(self):
105118 self .assertEqual (len (counterpart_picking ), 1 )
106119 self .assertEqual (counterpart_picking .counterpart_of_picking_id , picking )
107120 self .assertEqual (len (counterpart_picking .move_ids ), len (picking .move_ids ))
108- for cp_move , move in zip (counterpart_picking .move_ids , picking .move_ids ):
121+ for cp_move , move in zip (counterpart_picking .move_ids , picking .move_ids ): # noqa: B905
109122 self .assertEqual (cp_move .counterpart_of_move_id , move )
110123 self .assertEqual (
111124 len (counterpart_picking .move_line_ids ), len (picking .move_line_ids )
112125 )
113- for cp_line , line in zip (
126+ for cp_line , line in zip ( # noqa: B905
114127 counterpart_picking .move_line_ids , picking .move_line_ids
115128 ):
116129 self .assertEqual (cp_line .counterpart_of_line_id , line )
0 commit comments