Merge PR #2145 into 16.0

Signed-off-by LoisRForgeFlow
This commit is contained in:
OCA-git-bot
2024-08-27 13:06:17 +00:00
2 changed files with 42 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
# Copyright 2023 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class StockQuant(models.Model):
@@ -23,9 +24,29 @@ class StockQuant(models.Model):
compute="_compute_discrepancy_threshold",
)
has_over_discrepancy = fields.Boolean(
compute="_compute_has_over_discrepancy",
compute="_compute_has_over_discrepancy", search="_search_has_over_discrepancy"
)
def _search_has_over_discrepancy(self, operator, value):
if operator not in ["=", "!="]:
raise UserError(_("This operator is not supported"))
if value == "True":
value = True
elif value == "False":
value = False
if not isinstance(value, bool):
raise UserError(_("Value should be True or False (not %s)") % value)
ids = []
for quant in self.search([]):
has_over_discrepancy = (
quant.discrepancy_percent > quant.location_id.discrepancy_threshold
)
if (operator == "=" and has_over_discrepancy == value) or (
operator == "!=" and has_over_discrepancy != value
):
ids.append(quant.id)
return [("id", "in", ids)]
@api.depends("quantity", "inventory_quantity")
def _compute_discrepancy(self):
for quant in self:

View File

@@ -36,4 +36,23 @@
</xpath>
</field>
</record>
<record id="quant_search_last_has_over_discrepancy" model="ir.ui.view">
<field name="name">stock.quant.last_has_over_discrepancy.search</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.quant_search_view" />
<field eval="10" name="priority" />
<field name="arch" type="xml">
<field name="owner_id" position="after">
<field name="has_over_discrepancy" />
</field>
<filter name="internal_loc" position="after">
<filter
name='has_over_discrepancy'
string="Over Discrepancy"
domain="[('has_over_discrepancy','=', True)]"
/>
</filter>
</field>
</record>
</odoo>