invoice.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2011-2012 E-MIPS Electronica e Informatica
  6. # All Rights Reserved (<http://www.e-mips.com.ar>).
  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 models, fields, api
  23. from openerp.tools.translate import _
  24. class AccountInvoice(models.Model):
  25. _name = "account.invoice"
  26. _inherit = "account.invoice"
  27. amount_untaxed = fields.Float(compute='_compute_amount_all')
  28. amount_tax = fields.Float(compute='_compute_amount_all')
  29. amount_total = fields.Float(compute='_compute_amount_all')
  30. @api.depends('invoice_line.price_subtotal')
  31. def _compute_amount_all(self):
  32. for order in self:
  33. amount_tax = amount_untaxed = 0.0
  34. currency = order.currency_id.with_context(date=order.date_invoice or fields.Date.context_today(order))
  35. for line in order.invoice_line:
  36. amount_untaxed += line.price_subtotal
  37. amount_tax += (line.quantity * line.price_unit) - line.price_subtotal
  38. order.amount_tax = currency.round(amount_tax)
  39. order.amount_untaxed = currency.round(amount_untaxed)
  40. order.amount_total = currency.round(amount_tax + amount_untaxed)