mrp_production.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: 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 MrpProduction(models.Model):
  24. _inherit = 'mrp.production'
  25. partner_id = fields.Many2one(
  26. comodel_name='res.partner', string='Customer', store=True,
  27. related='move_prod_id.procurement_id.sale_line_id.order_id.partner_id')
  28. sale_order_id = fields.Many2one(
  29. comodel_name='sale.order', string='Sale Order', store=True,
  30. related='move_prod_id.procurement_id.sale_line_id.order_id')
  31. sale_line_id = fields.Many2one(
  32. comodel_name='sale.order.line', string='Sale Line', store=True,
  33. related='move_prod_id.procurement_id.sale_line_id')
  34. class Sale(models.Model):
  35. _inherit = 'sale.order'
  36. production_ids = fields.One2many(comodel_name='mrp.production', inverse_name='sale_order_id', string='Production')
  37. production_count = fields.Integer(compute="_get_production_count")
  38. @api.one
  39. def _get_production_count(self):
  40. if self.production_ids:
  41. self.production_count = len(self.production_ids)