sale_order.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- encoding: utf-8 -*-
  2. #################################################################################
  3. # #
  4. # product_genre for OpenERP #
  5. # Author: Victor Obrist #
  6. # contact: victor@paraguayenlaweb.com #
  7. # #
  8. # This program is free software: you can redistribute it and/or modify #
  9. # it under the terms of the GNU Affero General Public License as #
  10. # published by the Free Software Foundation, either version 3 of the #
  11. # License, or (at your option) any later version. #
  12. # #
  13. # This program is distributed in the hope that it will be useful, #
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  16. # GNU Affero General Public License for more details. #
  17. # #
  18. # You should have received a copy of the GNU Affero General Public License #
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  20. # #
  21. #################################################################################
  22. from openerp import api, fields, models
  23. class SaleOrder(models.Model):
  24. _inherit = 'sale.order'
  25. production_count = fields.Integer(
  26. compute='_compute_production_count')
  27. @api.multi
  28. def _compute_production_count(self):
  29. mrp_production_model = self.env['mrp.production']
  30. for sale in self:
  31. domain = [('sale_order_id', '=', sale.id)]
  32. sale.production_count = mrp_production_model.search_count(domain)
  33. @api.multi
  34. def action_view_production(self):
  35. action = self.env.ref('mrp.mrp_production_action').read()[0]
  36. productions = self.env['mrp.production'].search(
  37. [('sale_order_id', 'in', self.ids)])
  38. if len(productions) > 1:
  39. action['domain'] = [('id', 'in', productions.ids)]
  40. else:
  41. action['views'] = [
  42. (self.env.ref('mrp.mrp_production_form_view').id, 'form')]
  43. action['res_id'] = productions.id
  44. return action