-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathproduct_template.py
More file actions
32 lines (26 loc) · 1 KB
/
product_template.py
File metadata and controls
32 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
def _compute_quantities_dict(self):
prod_available = super()._compute_quantities_dict()
for template in self:
free_qty = 0
for p in template.with_context(active_test=False).product_variant_ids:
free_qty += p.free_qty
prod_available[template.id]["free_qty"] = free_qty
return prod_available
def _compute_quantities(self):
super()._compute_quantities()
res = self._compute_quantities_dict()
for template in self:
template.free_qty = res[template.id]["free_qty"]
return
def _search_free_qty(self, operator, value):
return [("product_variant_ids.free_qty", operator, value)]
free_qty = fields.Float(
"Free Quantity",
compute="_compute_quantities",
search="_search_free_qty",
compute_sudo=False,
digits="Product Unit of Measure",
)