mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
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.
28 lines
962 B
Python
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
|