İçereği Atla
Menü
Bu soru işaretlendi
1818 Görünümler

many2many restrict selection based on a object property if similar object previously selected.

so i have a ranks records and those ranks are getting picked in  contact info


contact module: 

from odoo import models, fields, api, _
from odoo.exceptions import UserError


class res_partner_rank(models.Model):
_inherit = 'res.partner'
_description = 'ranking system inherit field'

rank = fields.Many2many('ranks.system', string='Rank')
def check_selection(self):
for rec in self:
cats = []
if len(rec.rank) > 0:
for i, rank in enumerate(rec.rank):
if len(rank[i].category_id) > 0:

this method should check if user has any rank that got the same product category.


rank module :

from odoo import models, fields, api, _
from odoo.exceptions import UserError


class ranks_system(models.Model):
_name = 'ranks.system'
name = fields.Char()
description = fields.Text()
priority = fields.Selection([('0', 'Public'), ('1', 'Bronze'), ('2', 'Silver'), ('3', "Gold"), ('4', "Platinum")])
category_id = fields.Many2many('product.category', string='Category Satisfies The Discount')
discount = fields.Float()
rank_start_from = fields.Float(default=0, string='Class Ratio Starts From',
help='Class ratio start from how much the Customer will pay')
rank_ends_to = fields.Float(default=1, string='Class Ratio Ends To',
help='Class ratio end to how much the Customer will pay')

@api.onchange('rank_inv_to')
def rank_check(self):
for rec in self:
if rec.rank_ends_to < rec.rank_start_from:
raise UserError(_("Class " + str(rec.name) + " invoicing End " + str(
rec.rank_ends_to) + " Can't be less than Invoicing Start " + str(rec.rank_start_from)))


Avatar
Vazgeç
Üretici

basically i dont want user to pick the contact class/rank where he has already a rank/class with the same product category , i tried different ways but neither really worked.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Tem 22
2044
0
Şub 23
157
3
Ağu 22
9177
1
Tem 22
5221
0
Tem 22
2213