From 1785614f98eb7b12730fc4b5426f633db16da225 Mon Sep 17 00:00:00 2001 From: Steve Campbell <39602586+osi-scampbell@users.noreply.github.com> Date: Thu, 14 Mar 2019 16:29:49 -0700 Subject: [PATCH] [IMP] fieldservice_repair (#158) * [IMP] fieldservice_repair --- fieldservice_repair/models/fsm_order.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fieldservice_repair/models/fsm_order.py b/fieldservice_repair/models/fsm_order.py index ca495f57f1..297496676e 100644 --- a/fieldservice_repair/models/fsm_order.py +++ b/fieldservice_repair/models/fsm_order.py @@ -3,6 +3,8 @@ from odoo import api, fields from odoo.addons.base_geoengine import geo_model +from odoo import _ +from odoo.exceptions import ValidationError class FSMOrder(geo_model.GeoModel): @@ -18,7 +20,8 @@ def create(self, vals): # create a repair order order = super(FSMOrder, self).create(vals) if order.type == 'repair': - if order.equipment_id: + if (order.equipment_id and + order.equipment_id.current_stock_location_id): equipment = order.equipment_id repair_id = self.env['mrp.repair'].create({ 'name': order.name or '', @@ -28,7 +31,7 @@ def create(self, vals): equipment.current_stock_location_id.id or False, 'location_dest_id': equipment.current_stock_location_id and equipment.current_stock_location_id.id or False, - 'lot_id': equipment.lot_id and equipment.lot_id.name or '', + 'lot_id': equipment.lot_id.id or '', 'product_qty': 1, 'invoice_method': 'none', 'internal_notes': order.description, @@ -36,4 +39,9 @@ def create(self, vals): False, }) order.repair_id = repair_id + elif not order.equipment_id.current_stock_location_id: + raise ValidationError(_("Cannot create Repair " + + "Order because Equipment does " + + "not have a Current Inventory " + + "Location")) return order