Files
stock-logistics-warehouse/stock_request_direction/models/stock_request_order.py
Patrick Wilson 981fd0c760 [IMP] Warehouse On Change
Since the location and routes depend on the warehouse that is selected on the stock request order, if the warehouse changes then so will the route options. This adds an on change event so if the warehouse changes, then the direction gets cleared and so do the routes on the product lines. This forces the user to properly reset the items using the correct routes for the newly selected warehouse.
2021-04-15 18:53:00 +07:00

39 lines
1.3 KiB
Python

# Copyright (c) 2019 Open Source Integrators
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class StockRequestOrder(models.Model):
_inherit = "stock.request.order"
direction = fields.Selection(
[("outbound", "Outbound"), ("inbound", "Inbound")],
string="Direction",
states={"draft": [("readonly", False)]},
readonly=True,
)
@api.onchange("direction")
def _onchange_location_id(self):
if self.direction == "outbound":
# Stock Location set to Partner Locations/Customers
self.location_id = self.company_id.partner_id.property_stock_customer.id
else:
# Otherwise the Stock Location of the Warehouse
self.location_id = self.warehouse_id.lot_stock_id.id
@api.onchange('warehouse_id')
def _onchange_warehouse_id(self):
if self.direction:
self.direction = False
for stock_request in self.stock_request_ids:
if stock_request.route_id:
stock_request.route_id = False
def change_childs(self):
super().change_childs()
if not self._context.get("no_change_childs", False):
for line in self.stock_request_ids:
line.direction = self.direction