product.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. class Product(models.Model):
  5. _inherit = 'product.template'
  6. membership = fields.Boolean(help='Check if the product is eligible for membership.')
  7. membership_date_from = fields.Date(string='Membership Start Date',
  8. help='Date from which membership becomes active.')
  9. membership_date_to = fields.Date(string='Membership End Date',
  10. help='Date until which membership remains active.')
  11. _sql_constraints = [
  12. ('membership_date_greater', 'check(membership_date_to >= membership_date_from)', 'Error ! Ending Date cannot be set before Beginning Date.')
  13. ]
  14. @api.model
  15. def get_view(self, view_id=None, view_type='form', **options):
  16. if self._context.get('product') == 'membership_product':
  17. if view_type == 'form':
  18. view_id = self.env.ref('membership.membership_products_form').id
  19. else:
  20. view_id = self.env.ref('membership.membership_products_tree').id
  21. return super().get_view(view_id, view_type, **options)