# -*- encoding: utf-8 -*- ################################################################################# # # # product_genre for OpenERP # # Author: Victor Obrist # # contact: victor@paraguayenlaweb.com # # # # 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 . # # # ################################################################################# from openerp import api, fields, models class SaleOrder(models.Model): _inherit = 'sale.order' production_count = fields.Integer( compute='_compute_production_count') @api.multi def _compute_production_count(self): mrp_production_model = self.env['mrp.production'] for sale in self: domain = [('sale_order_id', '=', sale.id)] sale.production_count = mrp_production_model.search_count(domain) @api.multi def action_view_production(self): action = self.env.ref('mrp.mrp_production_action').read()[0] productions = self.env['mrp.production'].search( [('sale_order_id', 'in', self.ids)]) if len(productions) > 1: action['domain'] = [('id', 'in', productions.ids)] else: action['views'] = [ (self.env.ref('mrp.mrp_production_form_view').id, 'form')] action['res_id'] = productions.id return action