From adfa9a4fcff8342432458ef8d9ab0b9fbe131a46 Mon Sep 17 00:00:00 2001 From: "Mathias Mathy (MAMA)" Date: Fri, 18 Aug 2023 15:13:26 +0200 Subject: [PATCH] [FIX] repair : editable destination locations on picking type As the `default_remove_location_dest_id` field of the stock.picking.type model is required, it is intended to be set by the user, and so it must be editable rather than readonly. Moreover, for accounting purpose, we want the ability to modify `default_location_dest_id`. Finally, we ensure to set a default value on all locations when selecting 'repair_operation' as code. closes odoo/odoo#134587 X-original-commit: 7504484ba2ebc93963bc0dec6441e351caee2638 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Mathias Mathy (mama) --- addons/repair/models/stock_picking.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/repair/models/stock_picking.py b/addons/repair/models/stock_picking.py index 710221b7625..4aed20a423a 100644 --- a/addons/repair/models/stock_picking.py +++ b/addons/repair/models/stock_picking.py @@ -23,7 +23,7 @@ class PickingType(models.Model): default_remove_location_dest_id = fields.Many2one( 'stock.location', 'Default Remove Destination Location', - check_company=True, readonly=True, + check_company=True, help="This is the default remove destination location when you create a repair order with this operation type.") default_recycle_location_dest_id = fields.Many2one( @@ -77,6 +77,21 @@ class PickingType(models.Model): if not(picking_type.code == 'incoming' and picking_type.return_type_of_ids): picking_type.is_repairable = False + @api.onchange('code') + def _onchange_picking_code(self): + super()._onchange_picking_code() + + if self.code == 'repair_operation': + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.company_id.id)], limit=1) + stock_location = warehouse.lot_stock_id + prod_location = self.env['stock.location'].search([('usage', '=', 'production'), ('company_id', '=', self.company_id.id)], limit=1) + scrap_location = self.env['stock.location'].search([('scrap_location', '=', True), ('company_id', 'in', [self.company_id.id, False])], limit=1) + + self.default_location_src_id = stock_location.id + self.default_location_dest_id = prod_location.id + self.default_remove_location_dest_id = scrap_location.id + self.default_recycle_location_dest_id = stock_location.id + def get_repair_stock_picking_action_picking_type(self): action = self.env["ir.actions.actions"]._for_xml_id('repair.action_picking_repair') if self: