From 519640cd0885d245815ccb272a3ec5c9ca9c2ceb Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Thu, 13 Nov 2014 16:28:55 +0100 Subject: [PATCH 01/31] [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 + +
+ + + + + + + + + + + + + +
+
+
+ +
+
+ + + +
+
+ From d144614c36f38561df0c50fb66a82990e107172d Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Fri, 14 Nov 2014 11:21:31 +0100 Subject: [PATCH 02/31] [mod] _rec_name --- stock_quant_manual_assign/README.rst | 1 + stock_quant_manual_assign/__openerp__.py | 4 ---- .../wizard/assign_manual_quants.py | 12 +++++++----- .../wizard/assign_manual_quants_view.xml | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 stock_quant_manual_assign/README.rst diff --git a/stock_quant_manual_assign/README.rst b/stock_quant_manual_assign/README.rst new file mode 100644 index 000000000..ba96c8f7f --- /dev/null +++ b/stock_quant_manual_assign/README.rst @@ -0,0 +1 @@ +With this module, user can change manually the automatic selection of quants \ No newline at end of file diff --git a/stock_quant_manual_assign/__openerp__.py b/stock_quant_manual_assign/__openerp__.py index e69ea98d6..eff067fe7 100644 --- a/stock_quant_manual_assign/__openerp__.py +++ b/stock_quant_manual_assign/__openerp__.py @@ -24,10 +24,6 @@ "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, diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 86d017493..06e8d2586 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -22,7 +22,6 @@ 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') @@ -33,13 +32,15 @@ class AssignManualQuants(models.TransientModel): 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')) + raise exceptions.Warning(_('Error'), + _('Quantity is higher' + ' than the needed one')) + name = fields.Char(string='Name') 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 = [] @@ -80,7 +81,8 @@ class AssignManualQuantsLines(models.TransientModel): if not self.selected: self.qty = False - assign_wizard = fields.Many2one('assign.manual.quants', string='Move') - quant = fields.Many2one('stock.quant', string="Quant") + assign_wizard = fields.Many2one('assign.manual.quants', string='Move', + required=True) + quant = fields.Many2one('stock.quant', string="Quant", required=True) 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 index 25836fb84..250930255 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml +++ b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml @@ -11,7 +11,7 @@ - +
From 0de36e0880ef8653e0a135e7f75c3ec42745af7e Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Thu, 20 Nov 2014 16:56:23 +0100 Subject: [PATCH 03/31] [mod] new_api --- stock_quant_manual_assign/__openerp__.py | 5 ++- .../views/stock_move_view.xml | 16 ++++++-- .../wizard/assign_manual_quants.py | 39 ++++++++++++------- .../wizard/assign_manual_quants_view.xml | 7 ++-- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/stock_quant_manual_assign/__openerp__.py b/stock_quant_manual_assign/__openerp__.py index eff067fe7..f1f5d89a9 100644 --- a/stock_quant_manual_assign/__openerp__.py +++ b/stock_quant_manual_assign/__openerp__.py @@ -22,7 +22,10 @@ "version": "1.0", "depends": ["base", "stock"], "author": "OdooMRP team", - "contributors": ["Mikel Arregi "], + "contributors": [ + "Ana Juaristi Olalde ", + "Pedro Manuel Baeza Romero " + "Mikel Arregi "], "category": "quant", 'data': ['wizard/assign_manual_quants_view.xml', 'views/stock_move_view.xml'], diff --git a/stock_quant_manual_assign/views/stock_move_view.xml b/stock_quant_manual_assign/views/stock_move_view.xml index a8193b0f0..3fda53a08 100644 --- a/stock_quant_manual_assign/views/stock_move_view.xml +++ b/stock_quant_manual_assign/views/stock_move_view.xml @@ -6,11 +6,21 @@ stock.move - + + + + + stock.move.form + stock.move + + + - diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants.py b/stock_quant_manual_assign/wizard/assign_manual_quants.py index 06e8d2586..fbc6947f1 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants.py +++ b/stock_quant_manual_assign/wizard/assign_manual_quants.py @@ -23,20 +23,30 @@ from openerp import fields, models, api, exceptions, _ class AssignManualQuants(models.TransientModel): _name = 'assign.manual.quants' - @api.one - @api.constrains('quants_lines') - def check_qty(self): + def lines_qty(self): total_qty = 0 for line in self.quants_lines: if line.selected: total_qty += line.qty + return total_qty + + @api.one + @api.constrains('quants_lines') + def check_qty(self): + total_qty = self.lines_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 higher' ' than the needed one')) + @api.depends('quants_lines') + def get_move_qty(self): + move = self.env['stock.move'].browse(self.env.context['active_id']) + self.move_qty = move.product_uom_qty - self.lines_qty() + name = fields.Char(string='Name') + move_qty = fields.Float(string="Remaining qty", compute="get_move_qty") quants_lines = fields.One2many('assign.manual.quants.lines', 'assign_wizard', string='Quants') @@ -53,17 +63,16 @@ class AssignManualQuants(models.TransientModel): 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] + @api.model + def default_get(self, var_fields): + move = self.env['stock.move'].browse(self.env.context['active_id']) + available_quants_ids = self.env['stock.quant'].search( + ['|', ('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)]) + available_quants = [{'quant': x.id} for x in available_quants_ids] available_quants.extend( {'quant': x.id, 'selected': True, @@ -80,6 +89,8 @@ class AssignManualQuantsLines(models.TransientModel): def onchange_selected(self): if not self.selected: self.qty = False + if self.selected and self.qty == 0: + self.qty = self.quant.qty assign_wizard = fields.Many2one('assign.manual.quants', string='Move', required=True) diff --git a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml index 250930255..c634bb57e 100644 --- a/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml +++ b/stock_quant_manual_assign/wizard/assign_manual_quants_view.xml @@ -11,7 +11,7 @@ - + @@ -19,6 +19,7 @@ +