procurement_order.py 778 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 Alex Comba - Agile Business Group
  3. # Copyright 2016-2018 Akretion
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. from openerp import api, models, exceptions, _
  6. class ProcurementOrder(models.Model):
  7. _inherit = 'procurement.order'
  8. @api.model
  9. def _prepare_mo_vals(self, bom):
  10. vals = super(ProcurementOrder, self)._prepare_mo_vals(bom)
  11. if self.group_id:
  12. sales = self.env['sale.order'].search(
  13. [('procurement_group_id', '=', self.group_id.id)])
  14. if len(sales) > 1:
  15. raise exceptions.ValidationError(
  16. _('More than 1 sale order found for this group'))
  17. vals['sale_order_id'] = sales.id
  18. return vals