hi am new to odoo development, this may be something simple but I can't figure it out
I added a new field subscription_tier
to the sale.subscription
model
class subscription_tire_set(models.Model):
_inherit = 'sale.subscription'
@api.depends('recurring_invoice_line_ids.product_id')
def _compute_subscription_tire(self):
# code for computing
n_subscription.subscription_tier = result
subscription_tier = fields.Char(string='Subscription Tier', readonly=True, compute='_compute_subscription_tire')
In my custom model, I added
@api.onchange('user_name')
def onchange_test_domain_fiedl(self):
obj = self.search([])
available_ids = []
for i in obj:
available_ids.append(i.user_name.id)
return {'domain': {'user_name': [&,|,('id', 'not in', available_ids),(('subscription_tier','=','tier_i'),('subscription_tier','=','tier_ii'),('subscription_tier','=','tier_iii'))]}}
user_name = fields.Many2one('sale.subscription', string='Name')
Instead of using multiple OR
on one field, you can use domain in
operator so the following domain:
['|', ('subscription_tier','=','tier_i'),'|', ('subscription_tier','=','tier_ii'),('subscription_tier','=','tier_iii')]
Can be reduced to :
[('subscription_tier','in', ['tier_i', 'tier_ii', 'tier_iii'])]
Computed fields are not stored by default, they are computed and returned when requested. Setting store=True
will store them in the database and automatically enable searching. searching on a computed field can also be enabled by setting the search parameter.
Try to set subscription_tier store
attribute to True
to enable searching.