diff options
| author | Simon Lejeune <sle@openerp.com> | 2019-10-21 12:43:14 +0000 |
|---|---|---|
| committer | svs-odoo <svs@odoo.com> | 2020-01-31 10:22:14 +0000 |
| commit | 2105895bb609c871e10acae7fd813b8ccb7c8b24 (patch) | |
| tree | 4ed183e1e2433d21bcf72baeef9c060857536d8f /addons | |
| parent | d644e4d72dcb2ea24ac5262cac2db9430613d926 (diff) | |
[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
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/stock_picking_batch/wizard/stock_picking_to_batch.py | 24 | ||||
| -rw-r--r-- | addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml | 15 |
2 files changed, 30 insertions, 9 deletions
diff --git a/addons/stock_picking_batch/wizard/stock_picking_to_batch.py b/addons/stock_picking_batch/wizard/stock_picking_to_batch.py index 6f310faf129..f4f50f02c81 100644 --- a/addons/stock_picking_batch/wizard/stock_picking_to_batch.py +++ b/addons/stock_picking_batch/wizard/stock_picking_to_batch.py @@ -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}) diff --git a/addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml b/addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml index 5997a49c80a..d021f984031 100644 --- a/addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml +++ b/addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml @@ -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> |
