Skip to Content
Menu
This question has been flagged
1 Reply
3897 Views

Hello Community,

I want to generate a sequence in my sequence_field as per the selection of my country.

Example:

Class TempTemp(models.Model)

_name = 'temp.temp'
  country_id = fields.Many2one('res.country','Country')
sequence_field = fields.Char()

Any idea how to do this?

Thanks.

Avatar
Discard
Best Answer

Hi

Do you mean you would like to record the country_id that has been assigned to your model?

e.g. First when "Belgium" is selected, sequence_field will show "Belgium" and after "Canada" is select, sequence_field will show "Belgium Canada"?

If this is the case, you many try to make the sequence_field  a compute field.


Example

Class TempTemp(models.Model)

_name = 'temp.temp'
  country_id = fields.Many2one('res.country','Country')
sequence_field = fields.Char(compute='_get_sequence')

@api.depends('country_id')
def _get_sequence(self):
self.sequence_field += self.country_id.name
Avatar
Discard
Author

Hi Tim Lai,

Thank you for your response but my question is bit different.

For example if I select Belgium as a country then my sequence field should generate the country code like BE/something and if I update it to Canada then it shall display CA/something.

*something is the postfix of the sequence field.

So can you please help me with that?

Hi,

It will be quite similar to my above solution. You could try to remove the compute attribute and change @api.depends('country_id') to @api.onchange('country_id'). You could also access the country code by self.country_id.code.

Related Posts Replies Views Activity
2
Nov 24
25101
2
May 24
5524
3
Mar 24
4967
0
Mar 24
264
3
Feb 24
11421