Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
5 Ответы
8153 Представления

I have a list with type of member and how many each category have to pay per year. It looks like this:

NAME

PRICE

Actif

90.00

Actif jeune

45.00

Sympathisant

100.00

In the view "res.partner" I put a many2one member_type field who point on the column name and I want a second field member_price which take the PRICE value according to the value in the field member_type .

Example: I choose Actif in member_type,  I want to show 90.00 in the field member_price.

Аватар
Отменить

in which model you define field member_price?

Лучший ответ

Hi,

I suggest you 2 or 3 diffrent ways to do that :

1. With related field

in res.partner class add a related field "member_price" below the field "member_type", the related field declaration should be like the following :

member_price  = fields.Float(related="member_type.price") 

2. With functions :

      2. a. Compute function :

@api.depends('member_type') def compute_price(self): if self.member_type: self.member_price = self.member_type.price member_price = fields.Float(compute="compute_price")

      2. b. Onchange function :
!Important: this function wont be usefull if the field "member_price" that you declare is on readonly.
@api.onchange('member_type')
def onchange_member_type(self):
	if self.member_type:
		self.member_price = self.member_type.price
member_price  = fields.Float('member price')
---------------------------------------------------------------------


Аватар
Отменить
Лучший ответ

write this on your code

@api.onchange(' member_type')

def _onchange_member_price(self):

    for rec in self:

        if rec.member_type:

            rec.member_price=rec.member_type.price                                                                                                                                                               

Аватар
Отменить
Лучший ответ

You should use products for that purpose, maybe together with the membership module.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мар. 15
4127
1
февр. 23
2511
1
нояб. 16
10744
3
июл. 16
7951
1
мар. 15
5200