Skip to Content
Menu
This question has been flagged
5 Replies
7058 Views

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.

Avatar
Discard

in which model you define field member_price?

Best Answer

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


Avatar
Discard
Best Answer

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                                                                                                                                                               

Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Mar 15
3098
1
Feb 23
1377
1
Nov 16
9592
3
Jul 16
6692
1
Mar 15
4070