11# (c) 2015 Alfredo de la Fuente - AvanzOSC
22# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33
4+
45from odoo import Command
56
67from odoo .addons .base .tests .common import BaseCommon
@@ -13,18 +14,49 @@ def setUpClass(cls):
1314 cls .parameter_model = cls .env ["ir.config_parameter" ].sudo ()
1415 cls .bom_model = cls .env ["mrp.bom" ].with_context (test_mrp_bom_version = True )
1516 cls .company = cls .env .ref ("base.main_company" )
17+
18+ default_fields = [
19+ field
20+ for field in ("sale_line_warn" , "purchase_line_warn" )
21+ if field in cls .env ["product.template" ]._fields
22+ ]
23+ tmpl_vals = {
24+ ** cls .env ["product.template" ].default_get (default_fields ),
25+ "name" : "Test Kit Product (mrp_bom_version)" ,
26+ "detailed_type" : "consu" ,
27+ }
28+ cls .kit_product_tmpl = cls .env ["product.template" ].create (tmpl_vals )
29+
30+ component_1_tmpl_vals = {
31+ ** cls .env ["product.template" ].default_get (default_fields ),
32+ "name" : "Test Component 1 (mrp_bom_version)" ,
33+ "detailed_type" : "product" ,
34+ }
35+ component_2_tmpl_vals = {
36+ ** cls .env ["product.template" ].default_get (default_fields ),
37+ "name" : "Test Component 2 (mrp_bom_version)" ,
38+ "detailed_type" : "product" ,
39+ }
40+ cls .component_product_1 = (
41+ cls .env ["product.template" ].create (component_1_tmpl_vals ).product_variant_id
42+ )
43+ cls .component_product_2 = (
44+ cls .env ["product.template" ].create (component_2_tmpl_vals ).product_variant_id
45+ )
46+
47+ stock_location = cls .env .ref ("stock.stock_location_stock" )
48+ cls .env ["stock.quant" ]._update_available_quantity (
49+ cls .component_product_1 , stock_location , 10
50+ )
51+ cls .env ["stock.quant" ]._update_available_quantity (
52+ cls .component_product_2 , stock_location , 10
53+ )
1654 vals = {
1755 "company_id" : cls .company .id ,
18- "product_tmpl_id" : cls .env .ref (
19- "product.product_product_11_product_template"
20- ).id ,
56+ "product_tmpl_id" : cls .kit_product_tmpl .id ,
2157 "bom_line_ids" : [
22- Command .create (
23- {"product_id" : cls .env .ref ("product.product_product_5" ).id }
24- ),
25- Command .create (
26- {"product_id" : cls .env .ref ("product.product_product_6" ).id }
27- ),
58+ Command .create ({"product_id" : cls .component_product_1 .id }),
59+ Command .create ({"product_id" : cls .component_product_2 .id }),
2860 ],
2961 }
3062 cls .mrp_bom = cls .bom_model .create (vals )
@@ -104,35 +136,35 @@ def test_historical_bom_still_used_in_picking(self):
104136 "location_dest_id" : self .env .ref ("stock.stock_location_customers" ).id ,
105137 }
106138 )
107- bom_line_5 = self .mrp_bom .bom_line_ids .filtered (
108- lambda l : l .product_id == self .env . ref ( "product.product_product_5" )
139+ bom_line_1 = self .mrp_bom .bom_line_ids .filtered (
140+ lambda line : line .product_id == self .component_product_1
109141 )
110- bom_line_6 = self .mrp_bom .bom_line_ids .filtered (
111- lambda l : l .product_id == self .env . ref ( "product.product_product_6" )
142+ bom_line_2 = self .mrp_bom .bom_line_ids .filtered (
143+ lambda line : line .product_id == self .component_product_2
112144 )
113145
114146 self .env ["stock.move" ].create (
115147 {
116148 "name" : "Kit Move – compo 5" ,
117- "product_id" : self .env . ref ( "product.product_product_5" ) .id ,
149+ "product_id" : self .component_product_1 .id ,
118150 "product_uom_qty" : 1 ,
119151 "product_uom" : kit_product .uom_id .id ,
120152 "picking_id" : picking .id ,
121153 "location_id" : picking .location_id .id ,
122154 "location_dest_id" : picking .location_dest_id .id ,
123- "bom_line_id" : bom_line_5 .id ,
155+ "bom_line_id" : bom_line_1 .id ,
124156 }
125157 )
126158 self .env ["stock.move" ].create (
127159 {
128160 "name" : "Kit Move – compo 6" ,
129- "product_id" : self .env . ref ( "product.product_product_6" ) .id ,
161+ "product_id" : self .component_product_2 .id ,
130162 "product_uom_qty" : 1 ,
131163 "product_uom" : kit_product .uom_id .id ,
132164 "picking_id" : picking .id ,
133165 "location_id" : picking .location_id .id ,
134166 "location_dest_id" : picking .location_dest_id .id ,
135- "bom_line_id" : bom_line_6 .id ,
167+ "bom_line_id" : bom_line_2 .id ,
136168 }
137169 )
138170
0 commit comments