1
1
# Copyright 2023 Moduon Team S.L.
2
2
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)
3
- from contextlib import suppress
4
3
5
- from odoo import api , fields , models
4
+ from odoo import api , models
6
5
7
6
8
7
class SaleOrderLine (models .Model ):
@@ -19,37 +18,37 @@ def onchange(self, values, field_name, field_onchange):
19
18
_self = self .with_context (changing_fields = names )
20
19
return super (SaleOrderLine , _self ).onchange (values , field_name , field_onchange )
21
20
22
- @api .depends ("product_id" , "product_uom_qty" , "product_uom" )
23
- def _compute_product_packaging_id (self ):
24
- """Set a default packaging for sales if possible."""
25
- for line in self :
26
- if line .product_id != line .product_packaging_id .product_id :
27
- line .product_packaging_id = line ._get_default_packaging (line .product_id )
28
- result = super ()._compute_product_packaging_id ()
29
- # If there's no way to package the desired qty, remove the packaging.
30
- # It is only done when the user is currently manually setting
31
- # `product_uom_qty` to zero. In other cases, we are maybe getting
32
- # default values and this difference will get fixed by other compute
33
- # methods later.
34
- if (
35
- self .env .context .get ("changing_fields" )
36
- and "product_uom_qty" not in self .env .context ["changing_fields" ]
37
- ):
38
- return result
39
- for line in self :
40
- with suppress (ZeroDivisionError ):
41
- if (
42
- line .product_uom_qty
43
- and line .product_uom_qty % line .product_packaging_id .qty
44
- ):
45
- line .product_packaging_id = False
46
- return result
47
-
48
- @api .model
49
- def _get_default_packaging (self , product ):
50
- return fields .first (
51
- product .packaging_ids .filtered_domain ([("sales" , "=" , True )])
52
- )
21
+ # @api.depends("product_id", "product_uom_qty", "product_uom")
22
+ # def _compute_product_packaging_id(self):
23
+ # """Set a default packaging for sales if possible."""
24
+ # for line in self:
25
+ # if line.product_id != line.product_packaging_id.product_id:
26
+ # line.product_packaging_id = line._get_default_packaging(line.product_id)
27
+ # result = super()._compute_product_packaging_id()
28
+ # # If there's no way to package the desired qty, remove the packaging.
29
+ # # It is only done when the user is currently manually setting
30
+ # # `product_uom_qty` to zero. In other cases, we are maybe getting
31
+ # # default values and this difference will get fixed by other compute
32
+ # # methods later.
33
+ # if (
34
+ # self.env.context.get("changing_fields")
35
+ # and "product_uom_qty" not in self.env.context["changing_fields"]
36
+ # ):
37
+ # return result
38
+ # for line in self:
39
+ # with suppress(ZeroDivisionError):
40
+ # if (
41
+ # line.product_uom_qty
42
+ # and line.product_uom_qty % line.product_packaging_id.qty
43
+ # ):
44
+ # line.product_packaging_id = False
45
+ # return result
46
+ #
47
+ # @api.model
48
+ # def _get_default_packaging(self, product):
49
+ # return fields.first(
50
+ # product.packaging_ids.filtered_domain([("sales", "=", True)])
51
+ # )
53
52
54
53
@api .depends ("product_packaging_id" , "product_uom" , "product_uom_qty" )
55
54
def _compute_product_packaging_qty (self ):
0 commit comments