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+ company_obj = cls .env ["res.company" ]
15+ cls .company1 = company_obj .create ({"name" : "Company A" })
16+ cls .company2 = company_obj .create ({"name" : "Company B" })
17+ cls .user_demo = cls .env ["res.users" ].create (
1118 {
1219 "login" : "firstnametest" ,
1320 "name" : "User Demo" ,
1421 "email" : "firstnametest@example.org" ,
22+ "company_id" : cls .company1 .id ,
23+ "company_ids" : [
24+ Command .link (cls .company1 .id ),
25+ Command .link (cls .company2 .id ),
26+ ],
1527 "groups_id" : [
16- ( 4 , self .env .ref ("base.group_user" ).id ),
17- ( 4 , self .env .ref ("stock.group_stock_user" ).id ),
28+ Command . link ( cls .env .ref ("base.group_user" ).id ),
29+ Command . link ( cls .env .ref ("stock.group_stock_user" ).id ),
1830 ],
1931 }
2032 )
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" ]
33+ cls .picking_type_1 = (
34+ cls .env ["stock.picking.type" ]
2735 .sudo ()
2836 .search (
2937 [
30- ("company_id" , "=" , self .company1 .id ),
38+ ("company_id" , "=" , cls .company1 .id ),
3139 ("name" , "=" , "Delivery Orders" ),
3240 ],
3341 limit = 1 ,
3442 )
3543 )
36- self .picking_type_2 = (
37- self .env ["stock.picking.type" ]
44+ cls .picking_type_2 = (
45+ cls .env ["stock.picking.type" ]
3846 .sudo ()
3947 .search (
40- [("company_id" , "=" , self .company2 .id ), ("name" , "=" , "Receipts" )],
48+ [
49+ ("company_id" , "=" , cls .company2 .id ),
50+ ("name" , "=" , "Receipts" ),
51+ ],
4152 limit = 1 ,
4253 )
4354 )
4455
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 (
56+ cls .company1 .intercompany_in_type_id = cls .picking_type_1 .id
57+ cls .company2 .intercompany_in_type_id = cls .picking_type_2 .id
58+ cls .user_demo .write (
4959 {
50- "company_id" : self .company1 .id ,
51- "company_ids" : [(4 , self .company1 .id ), (4 , self .company2 .id )],
60+ "company_id" : cls .company1 .id ,
61+ "company_ids" : [
62+ Command .link (cls .company1 .id ),
63+ Command .link (cls .company2 .id ),
64+ ],
5265 }
5366 )
54- # create storable product
55- self .product1 = self .env ["product.product" ].create (
67+ cls .user_demo .partner_id .with_context (
68+ allowed_company_ids = [cls .company1 .id , cls .company2 .id ]
69+ ).write ({})
70+
71+ cls .product1 = cls .env ["product.product" ].create (
5672 {
5773 "name" : "Product A" ,
5874 "type" : "product" ,
59- "categ_id" : self .env .ref ("product.product_category_all" ).id ,
75+ "categ_id" : cls .env .ref ("product.product_category_all" ).id ,
6076 "qty_available" : 100 ,
6177 }
6278 )
63- self .stock_location = (
64- self .env ["stock.location" ]
79+ cls .stock_location = (
80+ cls .env ["stock.location" ]
6581 .sudo ()
66- .search ([("name" , "=" , "Stock" ), ("company_id" , "=" , self .company1 .id )])
82+ .search (
83+ [("name" , "=" , "Stock" ), ("company_id" , "=" , cls .company1 .id )], limit = 1
84+ )
6785 )
68- self .uom_unit = self .env .ref ("uom.product_uom_unit" )
86+ cls .uom_unit = cls .env .ref ("uom.product_uom_unit" )
6987
7088 def test_picking_creation (self ):
7189 stock_location = self .env ["stock.location" ].search (
72- [("usage" , "=" , "internal" ), ("company_id" , "=" , self .company1 .id )]
90+ [("usage" , "=" , "internal" ), ("company_id" , "=" , self .company1 .id )], limit = 1
7391 )
7492 custs_location = self .env .ref ("stock.stock_location_customers" )
7593 custs_location .company_id = False
@@ -93,7 +111,7 @@ def test_picking_creation(self):
93111 "location_dest_id" : custs_location .id ,
94112 "product_id" : self .product1 .id ,
95113 "product_uom_id" : self .uom_unit .id ,
96- "qty_done " : 1.0 ,
114+ "quantity " : 1.0 ,
97115 "picking_id" : picking .id ,
98116 }
99117 )
@@ -105,12 +123,12 @@ def test_picking_creation(self):
105123 self .assertEqual (len (counterpart_picking ), 1 )
106124 self .assertEqual (counterpart_picking .counterpart_of_picking_id , picking )
107125 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 ):
126+ for cp_move , move in zip (counterpart_picking .move_ids , picking .move_ids ): # noqa: B905
109127 self .assertEqual (cp_move .counterpart_of_move_id , move )
110128 self .assertEqual (
111129 len (counterpart_picking .move_line_ids ), len (picking .move_line_ids )
112130 )
113- for cp_line , line in zip (
131+ for cp_line , line in zip ( # noqa: B905
114132 counterpart_picking .move_line_ids , picking .move_line_ids
115133 ):
116134 self .assertEqual (cp_line .counterpart_of_line_id , line )
0 commit comments