[ADD] stock_reception_usability

This commit is contained in:
Kevin.roche
2021-11-29 13:24:24 +01:00
parent 99dd4de4f7
commit a22f79ef44
6 changed files with 128 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from . import stock_move
from . import stock_picking

View File

@@ -0,0 +1,36 @@
# Copyright (C) 2021 Akretion (<http://www.akretion.com>).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockMove(models.Model):
_inherit = "stock.move"
location_dest_list = fields.Text(
string="Locations", compute="_compute_locations_dest_list"
)
@api.depends(
"move_line_ids", "move_line_ids.location_dest_id", "move_line_ids.qty_done"
)
def _compute_locations_dest_list(self):
for move in self:
data = []
separator = ", "
dest_list = move.move_line_ids.location_dest_id
for dest in dest_list:
lines_qty = move.move_line_ids.search(
[("move_id", "=", move.id), ("location_dest_id", "=", dest.id)]
).mapped("qty_done")
quantity = int(sum(lines_qty))
location = dest.name
data.append("{}: {}".format(quantity, location))
move.location_dest_list = separator.join(data)
def _compute_is_quantity_done_editable(self):
super()._compute_is_quantity_done_editable()
for move in self:
if len(move.move_line_ids) == 1 and move.show_details_visible:
move.is_quantity_done_editable = True

View File

@@ -0,0 +1,38 @@
# Copyright (C) 2021 Akretion (<http://www.akretion.com>).
# @author Kévin Roche <kevin.roche@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockPicking(models.Model):
_inherit = "stock.picking"
def action_fill_quantity_done(self):
self.ensure_one()
for move in self.move_ids_without_package:
if move.move_line_ids:
first_line = move.move_line_ids[0]
else:
first_line = False
if move.quantity_done == 0 and first_line:
qty = move.product_uom_qty
if first_line.qty_done == 0:
first_line.write(
{
"qty_done": qty,
}
)
elif move.quantity_done < move.product_uom_qty or (
move.quantity_done == 0 and not first_line
):
qty = move.product_uom_qty - move.quantity_done
self.env["stock.move.line"].create(
{
"move_id": move.id,
"location_dest_id": move.location_dest_id.id,
"location_id": move.location_id.id,
"product_uom_id": move.product_uom.id,
"qty_done": qty,
}
)