inventory return autofill

This commit is contained in:
ronozoro 2024-10-27 17:02:03 -07:00
parent 8518b3c3d3
commit ba44af973d
No known key found for this signature in database
GPG Key ID: 7C2BDED35C62C0F3
7 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import wizard

View File

@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
{
'name': "Return Autofill",
'summary': """auto fill return picking""",
'category': 'Inventory',
'description': """
Inventory auto fill return picking
""",
'version': '0.1',
'depends': ['stock'],
}

View File

@ -0,0 +1 @@
from . import stock_picking_return

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
from odoo import api, models
from odoo.exceptions import UserError
from odoo.tools.translate import _
class ReturnPicking(models.TransientModel):
_inherit = 'stock.return.picking'
@api.onchange('picking_id')
def _onchange_picking_id(self):
move_dest_exists = False
product_return_moves = [(5,)]
if self.picking_id and self.picking_id.state != 'done':
raise UserError(_("You may only return Done pickings."))
# In case we want to set specific default values (e.g. 'to_refund'), we must fetch the
# default values for creation.
line_fields = [f for f in self.env['stock.return.picking.line']._fields.keys()]
product_return_moves_data_tmpl = self.env['stock.return.picking.line'].default_get(line_fields)
for move in self.picking_id.move_lines:
if move.state == 'cancel':
continue
if move.move_dest_ids:
move_dest_exists = True
product_return_moves_data = dict(product_return_moves_data_tmpl)
product_return_moves_data.update(self._prepare_stock_return_picking_line_vals_from_move(move))
product_return_moves.append((0, 0, product_return_moves_data))
if self.picking_id and not product_return_moves:
raise UserError(
_("No products to return (only lines in Done state and not fully returned yet can be returned)."))
if self.picking_id:
self.product_return_moves = product_return_moves
self.move_dest_exists = move_dest_exists
self.parent_location_id = self.picking_id.picking_type_id.warehouse_id and self.picking_id.picking_type_id.warehouse_id.view_location_id.id or self.picking_id.location_id.location_id.id
self.original_location_id = self.picking_id.location_id.id
location_id = self.picking_id.location_id.id
if self.picking_id.picking_type_id.return_picking_type_id.default_location_dest_id.return_location:
location_id = self.picking_id.picking_type_id.return_picking_type_id.default_location_dest_id.id
self.location_id = location_id