mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
Steps to reproduce: - Enter a product. - Navigate to stock on hand. - Adjust quantity and rebase discrepancy limit. - Accept the discrepancy popup. You get an error as the ID to be tried to adjust is the product one, not the quant one. We need to overwrite active_ids context with the quant IDs to be handled on the wizard popup. TT43947 stock_inventory_discrepancy 15.0.1.0.1 Translated using Weblate (Spanish) Currently translated at 100.0% (31 of 31 strings) Translation: stock-logistics-warehouse-15.0/stock-logistics-warehouse-15.0-stock_inventory_discrepancy Translate-URL: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_inventory_discrepancy/es/ [UPD] README.rst
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
# Copyright 2023 Tecnativa - Ernesto Tejeda
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class StockQuant(models.Model):
|
|
_inherit = "stock.quant"
|
|
|
|
discrepancy_percent = fields.Float(
|
|
string="Discrepancy percent (%)",
|
|
compute="_compute_discrepancy",
|
|
digits=(3, 2),
|
|
help="The discrepancy expressed in percent with theoretical quantity "
|
|
"as basis",
|
|
group_operator="avg",
|
|
store=True,
|
|
compute_sudo=True,
|
|
)
|
|
discrepancy_threshold = fields.Float(
|
|
string="Threshold (%)",
|
|
digits=(3, 2),
|
|
help="Maximum Discrepancy Rate Threshold",
|
|
compute="_compute_discrepancy_threshold",
|
|
)
|
|
has_over_discrepancy = fields.Boolean(
|
|
compute="_compute_has_over_discrepancy",
|
|
)
|
|
|
|
@api.depends("quantity", "inventory_quantity")
|
|
def _compute_discrepancy(self):
|
|
for quant in self:
|
|
if not quant.quantity or not quant.inventory_quantity_set:
|
|
quant.discrepancy_percent = 0
|
|
else:
|
|
quant.discrepancy_percent = abs(
|
|
100 * (quant.inventory_diff_quantity) / quant.quantity
|
|
)
|
|
|
|
def _compute_discrepancy_threshold(self):
|
|
for quant in self:
|
|
whs = quant.location_id.warehouse_id
|
|
if quant.location_id.discrepancy_threshold > 0.0:
|
|
quant.discrepancy_threshold = quant.location_id.discrepancy_threshold
|
|
elif whs.discrepancy_threshold > 0.0:
|
|
quant.discrepancy_threshold = whs.discrepancy_threshold
|
|
else:
|
|
quant.discrepancy_threshold = False
|
|
|
|
def _compute_has_over_discrepancy(self):
|
|
for rec in self:
|
|
rec.has_over_discrepancy = (
|
|
rec.discrepancy_percent > rec.discrepancy_threshold
|
|
)
|
|
|
|
def action_apply_inventory(self):
|
|
if self.env.context.get("skip_exceeded_discrepancy", False):
|
|
return super().action_apply_inventory()
|
|
over_discrepancy = self.filtered(lambda r: r.has_over_discrepancy)
|
|
if over_discrepancy:
|
|
action = self.env["ir.actions.act_window"]._for_xml_id(
|
|
"stock_inventory_discrepancy.confirm_discrepancy_action"
|
|
)
|
|
action["context"] = dict(
|
|
self._context.copy(),
|
|
discrepancy_quant_ids=over_discrepancy.ids,
|
|
active_ids=self.ids,
|
|
)
|
|
return action
|
|
return super().action_apply_inventory()
|