From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/stock_picking_batch/wizard/__init__.py | 5 +++ .../wizard/stock_package_destination.py | 25 +++++++++++++++ .../wizard/stock_picking_to_batch.py | 31 +++++++++++++++++++ .../wizard/stock_picking_to_batch_views.xml | 36 ++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 addons/stock_picking_batch/wizard/__init__.py create mode 100644 addons/stock_picking_batch/wizard/stock_package_destination.py create mode 100644 addons/stock_picking_batch/wizard/stock_picking_to_batch.py create mode 100644 addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml (limited to 'addons/stock_picking_batch/wizard') diff --git a/addons/stock_picking_batch/wizard/__init__.py b/addons/stock_picking_batch/wizard/__init__.py new file mode 100644 index 00000000..cfb88076 --- /dev/null +++ b/addons/stock_picking_batch/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import stock_picking_to_batch +from . import stock_package_destination diff --git a/addons/stock_picking_batch/wizard/stock_package_destination.py b/addons/stock_picking_batch/wizard/stock_package_destination.py new file mode 100644 index 00000000..05b60cf0 --- /dev/null +++ b/addons/stock_picking_batch/wizard/stock_package_destination.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class ChooseDestinationLocation(models.TransientModel): + _inherit = "stock.package.destination" + + def _compute_move_line_ids(self): + destination_without_batch = self.env['stock.package.destination'] + for destination in self: + if not destination.picking_id.batch_id: + destination_without_batch |= destination + continue + destination.move_line_ids = destination.picking_id.batch_id.move_line_ids.filtered(lambda l: l.qty_done > 0 and not l.result_package_id) + super(ChooseDestinationLocation, destination_without_batch)._compute_move_line_ids() + + def action_done(self): + if self.picking_id.batch_id: + # set the same location on each move line and pass again in action_put_in_pack + self.move_line_ids.location_dest_id = self.location_dest_id + return self.picking_id.batch_id.action_put_in_pack() + else: + return super().action_done() diff --git a/addons/stock_picking_batch/wizard/stock_picking_to_batch.py b/addons/stock_picking_batch/wizard/stock_picking_to_batch.py new file mode 100644 index 00000000..f4f50f02 --- /dev/null +++ b/addons/stock_picking_batch/wizard/stock_picking_to_batch.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +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', 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): + self.ensure_one() + 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 new file mode 100644 index 00000000..5483f40a --- /dev/null +++ b/addons/stock_picking_batch/wizard/stock_picking_to_batch_views.xml @@ -0,0 +1,36 @@ + + + + + + stock.picking.to.batch.form + stock.picking.to.batch + +
+ + + + + +
+
+
+
+
+ + + Add to batch + stock.picking.to.batch + form + new + + list + + +
-- cgit v1.2.3