Skip to content

Commit 6181843

Browse files
committed
stock_reception_usability: support internal and outgoing type
1 parent f2172a5 commit 6181843

File tree

5 files changed

+74
-17
lines changed

5 files changed

+74
-17
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import stock_move
2-
2+
from . import stock_picking
3+
from . import stock_picking_type

stock_reception_usability/models/stock_move.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,43 @@
22
# @author Kévin Roche <kevin.roche@akretion.com>
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5+
from collections import defaultdict
56
from odoo import api, fields, models
67

78

89
class StockMove(models.Model):
910
_inherit = "stock.move"
1011

1112
location_dest_list = fields.Text(
12-
string="Locations", compute="_compute_locations_dest_list"
13+
string="Dest. Locations", compute="_compute_locations_list"
14+
)
15+
16+
location_src_list = fields.Text(
17+
string="Src. Locations", compute="_compute_locations_list"
1318
)
1419

1520
@api.depends(
16-
"move_line_ids", "move_line_ids.location_dest_id", "move_line_ids.qty_done"
21+
"move_line_ids.location_dest_id",
22+
"move_line_ids.location_id",
23+
"move_line_ids.qty_done",
1724
)
18-
def _compute_locations_dest_list(self):
25+
def _compute_locations_list(self):
26+
def format_loc(data):
27+
return "\n ".join([
28+
f"{int(qty) if qty.is_integer() else qty}: {location.name}"
29+
for location, qty in data.items()
30+
])
1931
for move in self:
20-
data = []
21-
separator = ", "
22-
dest_list = move.move_line_ids.location_dest_id
23-
for dest in dest_list:
24-
lines_qty = move.move_line_ids.search(
25-
[("move_id", "=", move.id), ("location_dest_id", "=", dest.id)]
26-
).mapped("qty_done")
27-
quantity = int(sum(lines_qty))
28-
location = dest.name
29-
data.append("{}: {}".format(quantity, location))
30-
move.location_dest_list = separator.join(data)
32+
dest = defaultdict(int)
33+
src = defaultdict(int)
34+
for line in move.move_line_ids:
35+
dest[line.location_dest_id] += line.qty_done
36+
src[line.location_id] += line.qty_done
37+
move.location_src_list = format_loc(src)
38+
move.location_dest_list = format_loc(dest)
3139

3240
def _compute_is_quantity_done_editable(self):
3341
super()._compute_is_quantity_done_editable()
3442
for move in self:
35-
if len(move.move_line_ids) == 1 and move.show_details_visible:
43+
if len(move.move_line_ids) <= 1:
3644
move.is_quantity_done_editable = True
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo import _, api, fields, models
7+
8+
9+
10+
class StockPicking(models.Model):
11+
_inherit = 'stock.picking'
12+
13+
show_src_location = fields.Boolean(compute="_compute_show_location")
14+
show_dest_location = fields.Boolean(compute="_compute_show_location")
15+
16+
@api.depends("picking_type_id.code", "location_id", "location_dest_id")
17+
def _compute_show_location(self):
18+
for picking in self:
19+
picking.show_src_location = (
20+
picking.picking_type_id.code != "incoming"
21+
and picking.location_id.child_ids
22+
)
23+
picking.show_dest_location = (
24+
picking.picking_type_id.code != "outgoing"
25+
and picking.location_dest_id.child_ids
26+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2024 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo import _, api, fields, models
7+
8+
9+
class StockPickingType(models.Model):
10+
_inherit = 'stock.picking.type'
11+
12+
def _default_show_operations(self):
13+
# super is not called as we want to always force the value to False
14+
# super()._default_show_operations()
15+
return False
16+
17+
show_operations = fields.Boolean(default=lambda s: s._default_show_operations())

stock_reception_usability/views/stock_picking.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
<field name="model">stock.picking</field>
55
<field name="inherit_id" ref="stock.view_picking_form" />
66
<field name="arch" type="xml">
7+
<field name="picking_type_code" position="after">
8+
<field name="show_src_location" invisible="1"/>
9+
<field name="show_dest_location" invisible="1"/>
10+
</field>
711
<xpath expr="//field[@name='product_uom']" position="after">
8-
<field name="location_dest_list" />
12+
<field name="location_src_list" attrs="{'column_invisible': [('parent.show_src_location', '=', False)]}"/>
13+
<field name="location_dest_list" attrs="{'column_invisible': [('parent.show_dest_location', '=', False)]}"/>
914
</xpath>
1015
<xpath expr="//field[@name='product_uom_qty']" position="attributes">
1116
<attribute

0 commit comments

Comments
 (0)