odoo/addons/membership/models/product.py

28 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class Product(models.Model):
_inherit = 'product.template'
membership = fields.Boolean(help='Check if the product is eligible for membership.')
membership_date_from = fields.Date(string='Membership Start Date',
help='Date from which membership becomes active.')
membership_date_to = fields.Date(string='Membership End Date',
help='Date until which membership remains active.')
_sql_constraints = [
('membership_date_greater', 'check(membership_date_to >= membership_date_from)', 'Error ! Ending Date cannot be set before Beginning Date.')
]
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
if self._context.get('product') == 'membership_product':
if view_type == 'form':
view_id = self.env.ref('membership.membership_products_form').id
else:
view_id = self.env.ref('membership.membership_products_tree').id
return super(Product, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)