Skip to Content
Menu
This question has been flagged
1707 Views

In my odoo module I have a internal_division model and a cover model. Every internal divisiom has a cover (Many2One field) and a cover can be a forest ('is_forest' boolean field) . Internal division also has a with_forest_cover boolean field. Every time the 'with_forest_cover' changes to True, the cover_id field must change its domain to those having 'is_forest'=True, and the other way around. I was trying to do it using:

cover_id = fields.Many2one('cusaf.cover', string='Cobertura',domain="[('is_forest', '=', with_forest_cover)]")

But for some reson this is only working when creating a new internal_division. When I edit an existing internal division and select / deselect the 'with_forest_cover' check box, the cover_id field is not changing its domain. This is only happening when editing an existed internal division. Why is this happening. I am working with odoo v14 Here is my code

class InternalDivision(models.Model):
    _name = 'cusaf.internal_division'
    _description = 'División interna'
    _inherit = ['mail.thread', 'mail.activity.mixin']

    name = fields.Char(string='Identificador externo', required=True)
    _sql_constraints = [
        ('name_uniq', 'unique (name)',
         "Error: Ya existe una división interna con el mismo identificador externo") ]

    with_forest_cover = fields.Boolean(string='Área con cobertura de bosques naturales', default=False)

    cover_id = fields.Many2one('cusaf.cover', string='Cobertura',domain="[('is_forest', '=', with_forest_cover)]")
    cover_other = fields.Char(string='Otra cobertura')
    cover_name = fields.Char(string='', related="cover_id.name")

    @api.onchange('with_forest_cover')
    def _with_forest_cover_onchange(self):
        self.cover_id=None


class Cover(models.Model):
    _name = 'cusaf.cover'
    _description = 'Tipo de cobertura'

    name = fields.Char(string='Nombre', required=True)
    _sql_constraints = [
        ('name_uniq', 'unique (name)',
         "Error: Ya existe un tipo de cobertura con el mismo nombre")
    ]
    description = fields.Text(string='Descripción')
    is_forest = fields.Boolean(string='Es bosque')


Avatar
Discard

Try taking out the quotations

Author

where?

Related Posts Replies Views Activity
2
Mar 24
569
0
Feb 24
1196
0
Jan 23
702
1
Nov 22
1759
0
Aug 22
1052