123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- # -*- 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 <http://www.gnu.org/licenses/>. #
- # #
- #################################################################################
- 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
|