-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] stock_location_last_inventory_date: Make last_inventory_date st…
…oreable This allows to search this field
- Loading branch information
1 parent
46c9883
commit dcdb125
Showing
9 changed files
with
125 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from .hooks import post_init_hook | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
import logging | ||
|
||
from odoo import SUPERUSER_ID, api | ||
from odoo.tools import groupby | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def set_initial_last_inventory_date(env): | ||
inventory_lines = env["stock.inventory.line"].search( | ||
[("inventory_id.state", "=", "done")] | ||
) | ||
lines_by_location = groupby(inventory_lines, key=lambda line: line.location_id) | ||
for location, lines in lines_by_location: | ||
last_inventory_date = max([line.inventory_id.date for line in lines]) | ||
location.write({"last_inventory_date": last_inventory_date}) | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
logger.info("Calculate last inventory date for locations") | ||
env = api.Environment(cr, SUPERUSER_ID, dict()) | ||
set_initial_last_inventory_date(env) |
12 changes: 12 additions & 0 deletions
12
stock_location_last_inventory_date/migrations/14.0.1.0.1/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import SUPERUSER_ID, api | ||
|
||
from odoo.addons.stock_location_last_inventory_date.hooks import ( | ||
set_initial_last_inventory_date, | ||
) | ||
|
||
|
||
def migrate(cr, version): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
set_initial_last_inventory_date(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Copyright 2021 Camptocamp SA | ||
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from . import stock_location | ||
from . import stock_inventory |
14 changes: 14 additions & 0 deletions
14
stock_location_last_inventory_date/models/stock_inventory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2024 Michael Tietz (MT Software) <mtietz@mt-software.de> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
from odoo import models | ||
|
||
|
||
class StockInventory(models.Model): | ||
_inherit = "stock.inventory" | ||
|
||
def _action_done(self): | ||
super()._action_done() | ||
for inventory in self: | ||
last_inventory_date = inventory.date | ||
done_locations = inventory.line_ids.location_id | ||
done_locations.write({"last_inventory_date": last_inventory_date}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* Carlos Serra-Toro <carlos.serra@camptocamp.com> | ||
* `Trobz <https://trobz.com>`_: | ||
* Michael Tietz (MT Software) <mtietz@mt-software.de> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters