[IMP] stock_picking_batch: add to batch wizard improvements

We check the selected pickings are compatible to be attached to an
existing batch transfer.

We add the possibility to create on the fly a batch picking to attach
the selected pickings.

task-2069646
This commit is contained in:
Simon Lejeune
2020-01-31 10:22:14 +00:00
committed by svs-odoo
parent d644e4d72d
commit 2105895bb6
2 changed files with 30 additions and 9 deletions
@@ -1,17 +1,31 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import fields, models, _
from odoo.exceptions import UserError
class StockPickingToBatch(models.TransientModel):
_name = 'stock.picking.to.batch'
_description = 'Batch Transfer Lines'
batch_id = fields.Many2one('stock.picking.batch', string='Batch Transfer')
batch_id = fields.Many2one('stock.picking.batch', string='Batch Transfer', domain="[('state', '=', 'draft')]")
mode = fields.Selection([('existing', 'an existing batch transfer'), ('new', 'a new batch transfer')], default='existing')
user_id = fields.Many2one('res.users', string='Responsible', help='Person responsible for this batch transfer')
def attach_pickings(self):
# use active_ids to add picking line to the selected batch
self.ensure_one()
picking_ids = self.env.context.get('active_ids')
return self.env['stock.picking'].browse(picking_ids).write({'batch_id': self.batch_id.id})
pickings = self.env['stock.picking'].browse(self.env.context.get('active_ids'))
if self.mode == 'new':
company = pickings.company_id
if len(company) > 1:
raise UserError(_("The selected pickings should belong to an unique company."))
batch = self.env['stock.picking.batch'].create({
'user_id': self.user_id.id,
'company_id': company.id,
'picking_type_id': pickings[0].picking_type_id.id,
})
else:
batch = self.batch_id
pickings.write({'batch_id': batch.id})
@@ -6,11 +6,18 @@
<field name="name">stock.picking.to.batch.form</field>
<field name="model">stock.picking.to.batch</field>
<field name="arch" type="xml">
<form string="Add pickings to batch">
<separator string="Select a batch"/>
<field name="batch_id" class="oe_inline" required="1" options="{'no_create_edit': True, 'no_open': True}"/>
<form string="Add pickings to">
<group>
<group>
<label for="mode" string="Add to"/>
<field name="mode" widget="radio" nolabel="1"/>
<field name="batch_id" options="{'no_create_edit': True, 'no_open': True}" attrs="{'invisible': [('mode', '=', 'new')], 'required': [('mode', '=', 'existing')]}"/>
<field name="user_id" options="{'no_create_edit': True}" attrs="{'invisible': [('mode', '=', 'existing')]}"/>
</group>
</group>
<footer>
<button name="attach_pickings" type="object" string="Add to Batch" class="btn-primary"/>
<button name="attach_pickings" type="object" string="Confirm" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>