diff --git a/addons/stock/models/stock_production_lot.py b/addons/stock/models/stock_production_lot.py index 493e9cc4c4c..03c146aeb0d 100644 --- a/addons/stock/models/stock_production_lot.py +++ b/addons/stock/models/stock_production_lot.py @@ -1,51 +1,38 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from openerp.osv import fields, osv -from openerp.tools.translate import _ +from odoo import api, fields, models, _ -class stock_production_lot(osv.osv): +class ProductionLot(models.Model): _name = 'stock.production.lot' _inherit = ['mail.thread'] _description = 'Lot/Serial' - _columns = { - 'name': fields.char('Serial Number', required=True, help="Unique Serial Number"), - 'ref': fields.char('Internal Reference', help="Internal reference number in case it differs from the manufacturer's serial number"), - 'product_id': fields.many2one('product.product', 'Product', required=True, domain=[('type', 'in', ['product', 'consu'])]), - 'quant_ids': fields.one2many('stock.quant', 'lot_id', 'Quants', readonly=True), - 'create_date': fields.datetime('Creation Date'), - } - _defaults = { - 'name': lambda x, y, z, c: x.pool.get('ir.sequence').next_by_code(y, z, 'stock.lot.serial'), - 'product_id': lambda x, y, z, c: c.get('product_id', False), - } + + name = fields.Char( + 'Serial Number', default=lambda self: self.env['ir.sequence'].next_by_code('stock.lot.serial'), + required=True, help="Unique Serial Number") + ref = fields.Char('Internal Reference', help="Internal reference number in case it differs from the manufacturer's serial number") + product_id = fields.Many2one( + 'product.product', 'Product', + domain=[('type', 'in', ['product', 'consu'])], required=True) + quant_ids = fields.One2many('stock.quant', 'lot_id', 'Quants', readonly=True) + create_date = fields.Datetime('Creation Date') + _sql_constraints = [ ('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'), ] - def action_traceability(self, cr, uid, ids, context=None): - """ It traces the information of lots - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param ids: List of IDs selected - @param context: A standard dictionary - @return: A dictionary of values - """ - quant_obj = self.pool.get("stock.quant") - quants = quant_obj.search(cr, uid, [('lot_id', 'in', ids)], context=context) - moves = set() - for quant in quant_obj.browse(cr, uid, quants, context=context): - moves |= {move.id for move in quant.history_ids} - if moves: - return { - 'domain': "[('id','in',[" + ','.join(map(str, list(moves))) + "])]", - 'name': _('Traceability'), - 'view_mode': 'tree,form', - 'view_type': 'form', - 'context': {'tree_view_ref': 'stock.view_move_tree'}, - 'res_model': 'stock.move', - 'type': 'ir.actions.act_window', - } - return False + @api.multi + def action_traceability(self): + move_ids = self.mapped('quant_ids').mapped('history_ids').ids + if not move_ids: + return False + return { + 'domain': [('id', 'in', move_ids)], + 'name': _('Traceability'), + 'view_mode': 'tree,form', + 'view_type': 'form', + 'context': {'tree_view_ref': 'stock.view_move_tree'}, + 'res_model': 'stock.move', + 'type': 'ir.actions.act_window'}