[FIX] stock: stock_picking_type create without WH
Avoid raising an error if `warehouse_id` isn't in the vals. Steps to reproduce : Inventory -> Configuration -> Operation Types -> Create a new Operation Type. Then, either the warehouse field is empty because it doesn't appear due to the multi-warehouse not being activated yet, or its saved when the field is empty. Changes the onchange into a compute to have a better consistency between the frontend and the backend. Part of task-2985735 X-original-commit: 2421619ecb0c2076f1d1694a30a724c92ff94c87 Part-of: odoo/odoo#106039
This commit is contained in:
@@ -48,7 +48,7 @@ class PickingType(models.Model):
|
||||
check_company=True)
|
||||
show_entire_packs = fields.Boolean('Move Entire Packages', help="If ticked, you will be able to select entire packages to move")
|
||||
warehouse_id = fields.Many2one(
|
||||
'stock.warehouse', 'Warehouse', ondelete='cascade',
|
||||
'stock.warehouse', 'Warehouse', compute='_compute_warehouse_id', store=True, readonly=False, ondelete='cascade',
|
||||
check_company=True)
|
||||
active = fields.Boolean('Active', default=True)
|
||||
use_create_lots = fields.Boolean(
|
||||
@@ -100,7 +100,7 @@ class PickingType(models.Model):
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
if 'sequence_id' not in vals or not vals['sequence_id']:
|
||||
if vals['warehouse_id']:
|
||||
if vals.get('warehouse_id'):
|
||||
wh = self.env['stock.warehouse'].browse(vals['warehouse_id'])
|
||||
vals['sequence_id'] = self.env['ir.sequence'].sudo().create({
|
||||
'name': wh.name + ' ' + _('Sequence') + ' ' + vals['sequence_code'],
|
||||
@@ -207,8 +207,10 @@ class PickingType(models.Model):
|
||||
}
|
||||
}
|
||||
|
||||
@api.onchange('company_id')
|
||||
def _onchange_company_id(self):
|
||||
@api.depends('company_id')
|
||||
def _compute_warehouse_id(self):
|
||||
if self.warehouse_id:
|
||||
return
|
||||
if self.company_id:
|
||||
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.company_id.id)], limit=1)
|
||||
self.warehouse_id = warehouse
|
||||
|
||||
Reference in New Issue
Block a user