From 0de36e0880ef8653e0a135e7f75c3ec42745af7e Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Thu, 20 Nov 2014 16:56:23 +0100 Subject: [PATCH] [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 @@ +