invoice.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # For copyright and license notices, see __openerp__.py file in module root
  4. # directory
  5. ##############################################################################
  6. from openerp import fields, models, api
  7. class account_invoice_line(models.Model):
  8. _inherit = 'account.invoice.line'
  9. # we add this fields instead of making original readonly because we need
  10. # on change to change values, we make readonly in view because sometimes
  11. # we want them to be writeable
  12. invoice_line_tax_id_readonly = fields.Many2many(
  13. related='invoice_line_tax_id',
  14. )
  15. price_unit_readonly = fields.Float(
  16. related='price_unit',
  17. )
  18. product_can_modify_prices = fields.Boolean(
  19. related='product_id.can_modify_prices',
  20. readonly=True,
  21. string='Product Can modify prices')
  22. @api.one
  23. @api.onchange('price_unit_readonly')
  24. def onchange_price_unit_readonly(self):
  25. self.price_unit = self.price_unit_readonly
  26. @api.one
  27. @api.onchange('invoice_line_tax_id_readonly')
  28. def onchange_invoice_line_tax_id_readonly(self):
  29. self.invoice_line_tax_id = self.invoice_line_tax_id_readonly
  30. @api.one
  31. @api.constrains(
  32. 'discount', 'product_can_modify_prices')
  33. def check_discount(self):
  34. if (
  35. self.user_has_groups(
  36. 'price_security.group_restrict_prices') and
  37. not self.product_can_modify_prices and self.invoice_id
  38. ):
  39. self.env.user.check_discount(
  40. self.discount,
  41. self.invoice_id.partner_id.property_product_pricelist.id)