account_invoice.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author Vincent Renaville. Copyright 2015 Camptocamp SA
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp import models, api, exceptions, _
  21. class AccountInvoice(models.Model):
  22. _inherit = "account.invoice"
  23. @api.multi
  24. def test_invoice_line_tax(self):
  25. errors = []
  26. error_template = _("Invoice has a line with product %s with no taxes")
  27. for invoice in self:
  28. for invoice_line in invoice.invoice_line:
  29. if not invoice_line.invoice_line_tax_id:
  30. error_string = error_template % (invoice_line.name)
  31. errors.append(error_string)
  32. if errors:
  33. errors_full_string = ','.join(x for x in errors)
  34. raise exceptions.Warning(_('No Taxes Defined!'),
  35. errors_full_string)
  36. else:
  37. return True
  38. @api.multi
  39. def invoice_validate(self):
  40. self.test_invoice_line_tax()
  41. res = super(AccountInvoice, self).invoice_validate()
  42. return res