Files
odoo_source/addons/stock_picking_batch/models/stock_picking.py
T
Victor FeyensandSteve Van Essche 8acfc6b965 [FIX] stock_picking_batch: wrong sanity check on picking creation.
1) Wrong use of self.batch_id in an api.model method.
2) Fix demo datas which didn't pass the sanity check (after the fix)

Avoid to put draft picking into non-draft batch picking and use batch's
actions instead of picking's actions for confirmation and reservation.

closes odoo/odoo#55254

X-original-commit: 9e9f50169ba4d4698ce64b0865db4cc6b4833b0e
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: Steve Van Essche <svs@odoo.com>
2020-07-31 10:13:08 +00:00

35 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class StockPicking(models.Model):
_inherit = "stock.picking"
batch_id = fields.Many2one(
'stock.picking.batch', string='Batch Transfer',
check_company=True,
states={'done': [('readonly', True)], 'cancel': [('readonly', True)]},
help='Batch associated to this transfer', copy=False)
@api.model
def create(self, vals):
res = super().create(vals)
if vals.get('batch_id'):
res.batch_id._sanity_check()
return res
def write(self, vals):
res = super().write(vals)
if vals.get('batch_id'):
if not self.batch_id.picking_type_id:
self.batch_id.picking_type_id = self.picking_type_id[0]
self.batch_id._sanity_check()
return res
def _should_show_transfers(self):
if len(self.batch_id) == 1 and self == self.batch_id.picking_ids:
return False
return super()._should_show_transfers()