[FIX] stock_buffer_sales_analysis: attending the code review

Several changes were done because of the code review:
* The category of the module is now "Warehouse", in alignment
  with the categories user in OCA (https://odoo-community.org/shop)
* The list of fields in the depends() for the method
  _compute_last_inventory_date() missed several fields, that are
  now listed as dependencies.
* A new unit test has been added to account for the concern of the
  functional needing a compute_sudo in its definition, just in case
  a non privileged stock user was stuck into permission problems.
This commit is contained in:
Carlos Serra-Toro
2021-01-29 13:40:35 +01:00
committed by Hai Lang
parent 1defa0acc6
commit 8d973477f3
5 changed files with 55 additions and 7 deletions

View File

@@ -5,7 +5,7 @@
"summary": "Show the last inventory date for a leaf location", "summary": "Show the last inventory date for a leaf location",
"version": "13.0.1.0.0", "version": "13.0.1.0.0",
"development_status": "Alpha", "development_status": "Alpha",
"category": "Warehouse Management", "category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-warehouse", "website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Camptocamp, Odoo Community Association (OCA)", "author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",

View File

@@ -4,10 +4,8 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 13.0+e\n" "Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-25 15:06+0000\n"
"PO-Revision-Date: 2021-01-25 15:06+0000\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"

View File

@@ -29,10 +29,13 @@ class StockLocation(models.Model):
) )
@api.depends( @api.depends(
"usage",
"child_ids",
"validated_inventory_ids", "validated_inventory_ids",
"validated_inventory_ids.date", "validated_inventory_ids.date",
"validated_inventory_ids.usage", "validated_inventory_ids.state",
"validated_inventory_ids.child_ids", "validated_inventory_ids.location_ids.usage",
"validated_inventory_ids.location_ids.child_ids",
) )
def _compute_last_inventory_date(self): def _compute_last_inventory_date(self):
"""Store date of the last inventory for each leaf location""" """Store date of the last inventory for each leaf location"""

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Stock Location Last Inventory Date</title> <title>Stock Location Last Inventory Date</title>
<style type="text/css"> <style type="text/css">

View File

@@ -1,5 +1,7 @@
# Copyright 2021 Camptocamp SA # Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import fields
from odoo.exceptions import AccessError
from odoo.tests import SavepointCase from odoo.tests import SavepointCase
@@ -11,6 +13,51 @@ class TestStockLocation(SavepointCase):
cls.leaf_location = cls.env.ref("stock.location_refrigerator_small") cls.leaf_location = cls.env.ref("stock.location_refrigerator_small")
cls.top_location = cls.leaf_location.location_id cls.top_location = cls.leaf_location.location_id
def _create_user(self, name, groups):
return (
self.env["res.users"]
.with_context({"no_reset_password": True})
.create(
{
"name": name.capitalize(),
"password": "password",
"login": name,
"email": "{}@test.com".format(name.lower()),
"groups_id": [(6, 0, groups.ids)],
"company_ids": [(6, 0, self.env["res.company"].search([]).ids)],
}
)
)
def test_leaf_location_non_privileged_user(self):
stock_user = self._create_user(
"Stock Normal", self.env.ref("stock.group_stock_user")
)
stock_manager = self._create_user(
"Stock Admin", self.env.ref("stock.group_stock_manager")
)
inventory = self.env["stock.inventory"].create(
{
"name": "Inventory Adjustment",
"product_ids": [(4, self.product.id)],
"location_ids": [(4, self.leaf_location.id)],
}
)
inventory.with_user(stock_user).action_start()
inventory.with_user(stock_manager).action_validate()
self.assertEqual(
self.leaf_location.with_user(stock_user).validated_inventory_ids.ids,
[inventory.id],
)
self.assertEqual(
self.leaf_location.with_user(stock_user).last_inventory_date, inventory.date
)
try:
# Triggers the computation indirectly, `date` is in the depends.
inventory.with_user(stock_user).date = fields.Datetime.now()
except AccessError:
self.fail("A non-privileged user could not trigger the recomputation.")
def test_leaf_location(self): def test_leaf_location(self):
self.assertFalse(self.leaf_location.child_ids) self.assertFalse(self.leaf_location.child_ids)
self.assertFalse(self.leaf_location.validated_inventory_ids) self.assertFalse(self.leaf_location.validated_inventory_ids)