Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
8151 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ

in which model you define field member_price?

Câu trả lời hay nhất

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')
---------------------------------------------------------------------


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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                                                                                                                                                               

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
4123
1
thg 2 23
2504
1
thg 11 16
10741
3
thg 7 16
7949
1
thg 3 15
5199