File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ def _compute_can_be_sold(self):
26
26
for record in self :
27
27
record .can_be_sold = record .packaging_type_id .can_be_sold
28
28
29
+ # This shouldn't be required due to the compute method.
30
+ # However, we experienced some cases where nested form inside the product
31
+ # form fails to update the flag without this onchange.
32
+ @api .onchange ("packaging_type_id" )
33
+ def _onchange_packaging_type (self ):
34
+ for record in self :
35
+ record .can_be_sold = record .packaging_type_id .can_be_sold
36
+
29
37
def write (self , vals ):
30
38
if "active" in vals and vals ["active" ] is False :
31
39
vals ["can_be_sold" ] = False
Original file line number Diff line number Diff line change 1
1
# Copyright 2020 Camptocamp SA
2
2
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
3
+
3
4
from odoo .exceptions import ValidationError
5
+ from odoo .tests .common import Form
4
6
5
7
from .common import Common
6
8
@@ -43,3 +45,18 @@ def test_product_packaging_can_be_sold(self):
43
45
# Changing the can_be_sold on the packaging_type does not update the packaging
44
46
self .packaging_type_cannot_be_sold .can_be_sold = True
45
47
self .assertEqual (self .packaging_cannot_be_sold .can_be_sold , False )
48
+
49
+
50
+ class TestPackagingForm (Common ):
51
+ def test_packaging_can_be_sold_default_product_form (self ):
52
+ pkg_type_cannot_be_sold = self .packaging_type_cannot_be_sold .copy ()
53
+ pkg_type_can_be_sold = self .packaging_type_pl .copy ()
54
+ with Form (
55
+ self .env ["product.packaging" ],
56
+ view = "product_packaging_type.view_product_packaging_add_type_form" ,
57
+ ) as pkg :
58
+ pkg .packaging_type_id = pkg_type_can_be_sold
59
+ self .assertTrue (pkg .can_be_sold )
60
+ pkg .packaging_type_id = pkg_type_cannot_be_sold
61
+ self .assertFalse (pkg .can_be_sold )
62
+ pkg .product_id = self .product
You can’t perform that action at this time.
0 commit comments