sale.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 sale_order_line(models.Model):
  8. _inherit = 'sale.order.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. price_unit_readonly = fields.Float(
  13. related='price_unit',
  14. )
  15. tax_id_readonly = fields.Many2many(
  16. related='tax_id',
  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('tax_id_readonly')
  28. def onchange_tax_id_readonly(self):
  29. self.tax_id = self.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('price_security.group_restrict_prices')
  36. and not self.product_can_modify_prices
  37. ):
  38. self.env.user.check_discount(
  39. self.discount,
  40. self.order_id.pricelist_id.id)
  41. class sale_order(models.Model):
  42. _inherit = 'sale.order'
  43. @api.one
  44. @api.constrains(
  45. 'pricelist_id',
  46. 'payment_term',
  47. 'partner_id')
  48. def check_priority(self):
  49. if not self.user_has_groups('price_security.group_restrict_prices'):
  50. return True
  51. if (
  52. self.partner_id.property_product_pricelist and
  53. self.pricelist_id and
  54. self.partner_id.property_product_pricelist.sequence <
  55. self.pricelist_id.sequence):
  56. raise Warning(_(
  57. 'Selected pricelist priority can not be higher than pircelist '
  58. 'configured on partner'
  59. ))
  60. if (
  61. self.partner_id.property_payment_term and
  62. self.payment_term and
  63. self.partner_id.property_payment_term.sequence <
  64. self.payment_term.sequence):
  65. raise Warning(_(
  66. 'Selected payment term priority can not be higher than '
  67. 'payment term configured on partner'
  68. ))