You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from openerp.addons.decimal_precision import decimal_precision as dp
  4. from openerp.exceptions import ValidationError
  5. from openerp.tools.translate import _
  6. from openerp.osv import fields as old_fields
  7. class AccountAnalyticInvoiceLine(models.Model):
  8. _inherit = "account.analytic.invoice.line"
  9. def _amount_line(self, cr, uid, ids, prop, unknow_none, unknow_dict,
  10. context=None):
  11. res = super(AccountAnalyticInvoiceLine, self)._amount_line(
  12. cr, uid, ids, prop, unknow_none, unknow_dict, context=context)
  13. for line in self.browse(cr, uid, ids, context=context):
  14. discount = (line.discount or 0) / 100
  15. res[line.id] = res[line.id] * (1 - discount)
  16. return res
  17. discount = fields.Float(
  18. string='Discount (%)',
  19. digits=dp.get_precision('Discount'),
  20. copy=True,
  21. help='Discount that is applied in generated invoices.'
  22. ' It should be less or equal to 100')
  23. _columns = {
  24. 'price_subtotal': old_fields.function(
  25. _amount_line, string='Sub Total',
  26. type="float",
  27. digits_compute=dp.get_precision('Account')),
  28. }
  29. @api.one
  30. @api.constrains('discount')
  31. def _check_discount(self):
  32. if self.discount > 100:
  33. raise ValidationError(_("Discount should be less or equal to 100"))
  34. class AccountAnalyticAccount(models.Model):
  35. _inherit = 'account.analytic.account'
  36. @api.model
  37. def _prepare_invoice_line(self, line, fiscal_position):
  38. res = super(AccountAnalyticAccount, self)._prepare_invoice_line(
  39. line, fiscal_position)
  40. res['discount'] = line.discount or 0
  41. return res