mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -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:
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user