mirror of
https://github.com/OCA/stock-logistics-reporting.git
synced 2025-02-16 17:13:21 +02:00
[MIG] stock_quantity_history_location: Migration to 17.0
- refactored .js code by inheriting `get_views` method to display a different button text for those users having the Multi Locations group enabled. Added a test case to cover the change
This commit is contained in:
@@ -39,7 +39,14 @@ report by location, for a past date or for current date.
|
||||
Usage
|
||||
=====
|
||||
|
||||
- Go to: *Inventory / Reporting / Inventory or Inventory Valuation*
|
||||
First, you need to activate Storage Locations. To do so, go to Inventory
|
||||
/ Configuration / Settings / Warehouse and activate it.
|
||||
|
||||
To use this module, go to:
|
||||
|
||||
- *Inventory / Reporting / Locations*
|
||||
|
||||
- Select Inventory at Date & Location
|
||||
|
||||
- Filter by location
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
from . import wizards
|
||||
from . import models
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{
|
||||
"name": "Stock Quantity History Location",
|
||||
"summary": "Provides stock quantity by location on past date",
|
||||
"version": "16.0.1.0.1",
|
||||
"version": "17.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||
"maintainers": [
|
||||
@@ -15,12 +15,4 @@
|
||||
"website": "https://github.com/OCA/stock-logistics-reporting",
|
||||
"depends": ["stock"],
|
||||
"data": ["wizards/stock_quantity_history.xml"],
|
||||
"assets": {
|
||||
"web.assets_backend": [
|
||||
"stock_quantity_history_location/static/src/components"
|
||||
"/inventory_report/inventory_report.esm.js",
|
||||
"stock_quantity_history_location/static/src/components/"
|
||||
"inventory_report/inventory_report.xml",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
1
stock_quantity_history_location/models/__init__.py
Normal file
1
stock_quantity_history_location/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_quant
|
||||
25
stock_quantity_history_location/models/stock_quant.py
Normal file
25
stock_quantity_history_location/models/stock_quant.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# Copyright 2024 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class StockQuant(models.Model):
|
||||
_inherit = "stock.quant"
|
||||
|
||||
@api.model
|
||||
def get_views(self, views, options=None):
|
||||
res = super().get_views(views, options=options)
|
||||
user_has_group = self.user_has_groups("stock.group_stock_multi_locations")
|
||||
list_view = res.get("views", {}).get("list", {})
|
||||
if user_has_group and list_view:
|
||||
arch = list_view.get("arch", "")
|
||||
arch_tree = etree.XML(arch)
|
||||
buttons = arch_tree.xpath('//button[@name="action_inventory_at_date"]')
|
||||
for button in buttons:
|
||||
button.set("string", "Inventory at Date & Location")
|
||||
new_arch = etree.tostring(arch_tree, encoding="unicode")
|
||||
list_view["arch"] = new_arch
|
||||
return res
|
||||
@@ -1,9 +1,15 @@
|
||||
- Go to: *Inventory / Reporting / Inventory or Inventory Valuation*
|
||||
First, you need to activate Storage Locations. To do so, go to
|
||||
Inventory / Configuration / Settings / Warehouse and activate it.
|
||||
|
||||
To use this module, go to:
|
||||
- *Inventory / Reporting / Locations*
|
||||
|
||||
- Select Inventory at Date & Location
|
||||
|
||||
- Filter by location
|
||||
|
||||
- **Optionally: Mark if you want to include child location**
|
||||
|
||||
- Choose a moment in time:
|
||||
- Choose a moment in time:
|
||||
- Current Inventory
|
||||
- At a Specific Date
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@@ -387,8 +386,12 @@ report by location, for a past date or for current date.</p>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
|
||||
<p>First, you need to activate Storage Locations. To do so, go to Inventory
|
||||
/ Configuration / Settings / Warehouse and activate it.</p>
|
||||
<p>To use this module, go to:</p>
|
||||
<ul class="simple">
|
||||
<li>Go to: <em>Inventory / Reporting / Inventory or Inventory Valuation</em></li>
|
||||
<li><em>Inventory / Reporting / Locations</em></li>
|
||||
<li>Select Inventory at Date & Location</li>
|
||||
<li>Filter by location</li>
|
||||
<li><strong>Optionally: Mark if you want to include child location</strong></li>
|
||||
<li>Choose a moment in time:<ul>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {InventoryReportListController} from "@stock/views/list/inventory_report_list_controller";
|
||||
import {patch} from "@web/core/utils/patch";
|
||||
const {onWillStart} = owl;
|
||||
|
||||
patch(InventoryReportListController.prototype, "inventory_report_list_controller", {
|
||||
setup() {
|
||||
this._super(...arguments);
|
||||
this.multi_location = false;
|
||||
onWillStart(async () => {
|
||||
this.multi_location = await this.userService.hasGroup(
|
||||
"stock.group_stock_multi_locations"
|
||||
);
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-inherit="stock.InventoryReport.Buttons" t-inherit-mode="extension" owl="1">
|
||||
<xpath expr="//button[contains(@t-if, 'stock.quant')]" position="before">
|
||||
<t t-if="multi_location" t-set="text_multi_location">
|
||||
Inventory at Date & Location
|
||||
</t>
|
||||
<t t-else="" t-set="text_multi_location">Inventory at Date</t>
|
||||
</xpath>
|
||||
<xpath expr="//button[contains(@t-if, 'stock.quant')]" position="attributes">
|
||||
<attribute name="t-out">text_multi_location</attribute>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -22,7 +22,8 @@ class TestCommon(TransactionCase):
|
||||
)
|
||||
move._action_confirm()
|
||||
move._action_assign()
|
||||
move_line = move.move_line_ids[0]
|
||||
move_line.qty_done = qty
|
||||
for move_line in move.move_line_ids:
|
||||
move_line.quantity = qty
|
||||
move_line.picked = True
|
||||
move._action_done()
|
||||
return move
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
# Copyright 2021 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from lxml import etree
|
||||
|
||||
from odoo import Command, fields
|
||||
|
||||
from .common import TestCommon
|
||||
|
||||
@@ -30,6 +32,7 @@ class TestStockQuantityHistoryLocation(TestCommon):
|
||||
}
|
||||
)
|
||||
cls._create_stock_move(cls, location_dest_id=cls.child_test_stock_loc, qty=100)
|
||||
cls.group_multi_locations = cls.env.ref("stock.group_stock_multi_locations")
|
||||
|
||||
def test_01_wizard_past_date(self):
|
||||
wizard = self.env["stock.quantity.history"].create(
|
||||
@@ -63,3 +66,29 @@ class TestStockQuantityHistoryLocation(TestCommon):
|
||||
action = wizard.with_context().open_at_date()
|
||||
self.assertEqual(action["context"]["compute_child"], True)
|
||||
self.assertEqual(action["context"]["location"], self.test_stock_loc.id)
|
||||
|
||||
def test_03_get_stock_quant_list_view(self):
|
||||
# 1. Get Stock Quant list view without the `group_stock_multi_locations` group
|
||||
self.env.user.write(
|
||||
{"groups_id": [Command.unlink(self.group_multi_locations.id)]}
|
||||
)
|
||||
views = [[False, "list"]]
|
||||
sq_views = self.env["stock.quant"].get_views(views=views)
|
||||
list_view = sq_views.get("views", {}).get("list", {})
|
||||
arch = list_view.get("arch", "")
|
||||
arch_tree = etree.XML(arch)
|
||||
buttons = arch_tree.xpath('//button[@name="action_inventory_at_date"]')
|
||||
for button in buttons:
|
||||
self.assertEqual(button.get("string"), "Inventory at Date")
|
||||
# 2. Now, with the group
|
||||
self.env.user.write(
|
||||
{"groups_id": [Command.link(self.group_multi_locations.id)]}
|
||||
)
|
||||
views = [[False, "list"]]
|
||||
sq_views = self.env["stock.quant"].get_views(views=views)
|
||||
list_view = sq_views.get("views", {}).get("list", {})
|
||||
arch = list_view.get("arch", "")
|
||||
arch_tree = etree.XML(arch)
|
||||
buttons = arch_tree.xpath('//button[@name="action_inventory_at_date"]')
|
||||
for button in buttons:
|
||||
self.assertEqual(button.get("string"), "Inventory at Date & Location")
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<odoo>
|
||||
|
||||
<record id="view_stock_quantity_history_location" model="ir.ui.view">
|
||||
<field name="name">Inventory Report</field>
|
||||
<field
|
||||
name="name"
|
||||
>stock.quantity.history.form - stock_quantity_history_location</field>
|
||||
<field name="model">stock.quantity.history</field>
|
||||
<field name="inherit_id" ref="stock.view_stock_quantity_history" />
|
||||
<field name="arch" type="xml">
|
||||
@@ -10,7 +12,7 @@
|
||||
<field name="location_id" groups="stock.group_stock_multi_locations" />
|
||||
<field
|
||||
name="include_child_locations"
|
||||
attrs="{'invisible': [('location_id', '=', False)]}"
|
||||
invisible="not location_id"
|
||||
groups="stock.group_stock_multi_locations"
|
||||
/>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user