@@ -93,10 +93,14 @@ def update(self, instance, validated_data):
9393 categories = validated_data .pop ("categories" , None )
9494 recommended_products = validated_data .pop ("recommended_products" , None )
9595 children = validated_data .pop ("children" , None )
96+ structure = validated_data .get ("structure" , instance .structure )
9697 # Child products are not supposed to have a product class, their product
9798 # class comes from the parent product.
98- if instance .is_child :
99- validated_data .pop ("product_class" , None )
99+ if structure == Product .CHILD :
100+ validated_data ["product_class" ] = None
101+ else :
102+ # Parent and standalone products are not supposed to have a parent
103+ validated_data ["parent" ] = None
100104
101105 with transaction .atomic (): # it is all or nothing!
102106 # update instance
@@ -118,6 +122,9 @@ def update(self, instance, validated_data):
118122 else :
119123 _categories .set (categories )
120124
125+ if instance .is_child :
126+ instance .categories .all ().delete ()
127+
121128 if recommended_products is not None :
122129 with fake_autocreated (
123130 instance .recommended_products
@@ -148,11 +155,17 @@ def update(self, instance, validated_data):
148155 self .update_relation ("options" , _product_options , new_options )
149156
150157 self .update_relation ("images" , instance .images , images )
151- self .update_relation ("stockrecords" , instance .stockrecords , stockrecords )
152158 self .update_relation (
153159 "attributes" , instance .attribute_values , attribute_values
154160 )
155161
162+ if instance .is_parent :
163+ instance .stockrecords .all ().delete ()
164+ else :
165+ self .update_relation (
166+ "stockrecords" , instance .stockrecords , stockrecords
167+ )
168+
156169 if (
157170 self .partial
158171 ): # we need to clean up all the attributes with wrong product class
0 commit comments