From 519640cd0885d245815ccb272a3ec5c9ca9c2ceb Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Thu, 13 Nov 2014 16:28:55 +0100 Subject: [PATCH] [mod] added qty control --- stock_quant_manual_assign/__init__.py | 20 +++++ stock_quant_manual_assign/__openerp__.py | 35 ++++++++ .../views/stock_move_view.xml | 16 ++++ stock_quant_manual_assign/wizard/__init__.py | 20 +++++ .../wizard/assign_manual_quants.py | 86 +++++++++++++++++++ .../wizard/assign_manual_quants_view.xml | 40 +++++++++ 6 files changed, 217 insertions(+) create mode 100644 stock_quant_manual_assign/__init__.py create mode 100644 stock_quant_manual_assign/__openerp__.py create mode 100644 stock_quant_manual_assign/views/stock_move_view.xml create mode 100644 stock_quant_manual_assign/wizard/__init__.py create mode 100644 stock_quant_manual_assign/wizard/assign_manual_quants.py create mode 100644 stock_quant_manual_assign/wizard/assign_manual_quants_view.xml diff --git a/stock_quant_manual_assign/__init__.py b/stock_quant_manual_assign/__init__.py new file mode 100644 index 000000000..307ef6e12 --- /dev/null +++ b/stock_quant_manual_assign/__init__.py @@ -0,0 +1,20 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from . import wizard diff --git a/stock_quant_manual_assign/__openerp__.py b/stock_quant_manual_assign/__openerp__.py new file mode 100644 index 000000000..e69ea98d6 --- /dev/null +++ b/stock_quant_manual_assign/__openerp__.py @@ -0,0 +1,35 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +{ + "name": "Manual assignment of quants", + "version": "1.0", + "depends": ["base", "stock"], + "author": "OdooMRP team", + "contributors": ["Mikel Arregi "], + "category": "quant", + "description": """ + This module provide : + With this module, user can change manualy the automatic selection of quants + """, + 'data': ['wizard/assign_manual_quants_view.xml', + 'views/stock_move_view.xml'], + "installable": True, + "auto_install": False, +} diff --git a/stock_quant_manual_assign/views/stock_move_view.xml b/stock_quant_manual_assign/views/stock_move_view.xml new file mode 100644 index 000000000..a8193b0f0 --- /dev/null +++ b/stock_quant_manual_assign/views/stock_move_view.xml @@ -0,0 +1,16 @@ + + + + + stock.move.form + stock.move + + + + + + + + diff --git a/stock_quant_manual_assign/wizard/__init__.py b/stock_quant_manual_assign/wizard/__init__.py new file mode 100644 index 000000000..fa7e09bfa --- /dev/null +++ b/stock_quant_manual_assign/wizard/__init__.py @@ -0,0 +1,20 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from . import assign_manual_quants diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py new file mode 100644 index 000000000..86d017493 --- /dev/null +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -0,0 +1,86 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from openerp import fields, models, api, exceptions, _ + + +class AssignManualQuants(models.TransientModel): + _name = 'assign.manual.quants' + _rec_name = 'quants_lines' + + @api.one + @api.constrains('quants_lines') + def check_qty(self): + total_qty = 0 + for line in self.quants_lines: + if line.selected: + total_qty += line.qty + move = self.env['stock.move'].browse(self.env.context['active_id']) + if total_qty > move.product_uom_qty: + raise exceptions.Warning(_('Error'), _('Quantity is excessive')) + + quants_lines = fields.One2many('assign.manual.quants.lines', + 'assign_wizard', string='Quants') + + @api.multi + @api.model + def assign_quants(self): + move = self.env['stock.move'].browse(self.env.context['active_id']) + quants = [] + for quant_id in move.reserved_quant_ids.ids: + move.write({'reserved_quant_ids': [[3, quant_id]]}) + for line in self.quants_lines: + if line.selected: + quants.append([line.quant, line.qty]) + self.pool['stock.quant'].quants_reserve( + self.env.cr, self.env.uid, quants, move, context=self.env.context) + return {} + + def default_get(self, cr, uid, var_fields, context=None): + move = self.pool['stock.move'].browse( + cr, uid, context['active_id'], context=context) + available_quants_ids = self.pool['stock.quant'].search( + cr, uid, [ + '|', ('location_id', '=', move.location_id.id), + ('location_id', 'in', move.location_id.child_ids.ids), + ('product_id', '=', move.product_id.id), + ('qty', '>', 0), + ('reservation_id', '=', False)], context=context) + available_quants = [{'quant': x} for x in available_quants_ids] + available_quants.extend( + {'quant': x.id, + 'selected': True, + 'qty': x.qty + } for x in move.reserved_quant_ids) + return {'quants_lines': available_quants} + + +class AssignManualQuantsLines(models.TransientModel): + _name = 'assign.manual.quants.lines' + _rec_name = 'quant' + + @api.onchange('selected') + def onchange_selected(self): + if not self.selected: + self.qty = False + + assign_wizard = fields.Many2one('assign.manual.quants', string='Move') + quant = fields.Many2one('stock.quant', string="Quant") + qty = fields.Float(string='QTY') + selected = fields.Boolean(string="Select") diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml new file mode 100644 index 000000000..25836fb84 --- /dev/null +++ b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml @@ -0,0 +1,40 @@ + + + + + assign.manual.quants.form + assign.manual.quants + +
+ + + + + + + + + + + + + +
+
+
+ +
+
+ + + +
+
+