Files
stock-logistics-warehouse/stock_location_last_inventory_date/models/stock_location.py
Thierry Ducrest 7fe3180497 [13.0][FIX] stock_location_last_inventory_date
The prevoius implementation was only taking into account the last inventory
specific to the location.
This change includes also inventories done on parents location.

Also display the computed last inventory date in the form view.
2021-09-24 15:04:27 +07:00

28 lines
962 B
Python

# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import fields, models
class StockLocation(models.Model):
_inherit = "stock.location"
last_inventory_date = fields.Datetime(
"Last Inventory Date",
compute="_compute_last_inventory_date",
help="Indicates the last inventory date for the location, "
"including inventory done on parents location.",
)
def _compute_last_inventory_date(self):
for location in self:
location_ids = [
int(location_id)
for location_id in location.parent_path.rstrip("/").split("/")
]
last_inventory = self.env["stock.inventory"].search(
[("location_ids", "in", location_ids), ("state", "=", "done")],
order="date desc",
limit=1,
)
location.last_inventory_date = last_inventory.date