odoo / odoo

Odoo. Open Source Apps To Grow Your Business.
https://www.odoo.com
Other
38.75k stars 25.1k forks source link

[13.0][14.0] clear for reference fields in onchange method doesn't work #69806

Open dreamhunter2333 opened 3 years ago

dreamhunter2333 commented 3 years ago

Impacted versions: [13.0][14.0]

Steps to reproduce: clear the value of reference field in onchange methods

return None for no value record and use empty dict for one2many fields to compare None with None

https://github.com/odoo/odoo/blob/14.0/odoo/fields.py#L2461

https://github.com/odoo/odoo/blob/14.0/odoo/models.py#L6123

https://github.com/odoo/odoo/blob/14.0/odoo/models.py#L6091

It makes clear for reference in one2many field doesn't work

why not reference field return False for no value record

image

Current behavior: clear for reference doesn't work

Expected behavior: clear for reference work

Video/Screenshot link (optional):

Support ticket number submitted via odoo.com/help (optional):

dreamhunter2333 commented 3 years ago
class A(models.Model):
    _name = 'a'

    char = fields.Char()
    lines = fields.One2many('a.line')

    @api.onchange('char'):
    def onchange_char(self):
        self.lines[reference_field] = False

class ALine(models.Model):
    _name = 'a.line'

    parent_id = fields.Many2one('a')
    reference_field = fields.Reference([('res.uses', 'users')])
BraveEggTart commented 3 years ago

Impacted versions: [13.0][14.0]

Steps to reproduce: clear the value of reference field in onchange methods

return None for no value record and use empty dict for one2many fields to compare None with None

https://github.com/odoo/odoo/blob/14.0/odoo/fields.py#L2461

https://github.com/odoo/odoo/blob/14.0/odoo/models.py#L6123

https://github.com/odoo/odoo/blob/14.0/odoo/models.py#L6091

It makes clear for reference in one2many field doesn't work

why not reference field return False for no value record

image

Current behavior: clear for reference doesn't work

Expected behavior: clear for reference work

Video/Screenshot link (optional):

Support ticket number submitted via odoo.com/help (optional):

I ran into the same problem :(

dreamhunter2333 commented 3 years ago

Hi @pedrobaeza ,here is the video link

https://user-images.githubusercontent.com/32295532/116351414-3832a980-a826-11eb-9be7-ea34ac3c1568.mp4

pedrobaeza commented 3 years ago

The video is not helping, doing a lot of unexplained things very fast I'm afraid.

dreamhunter2333 commented 3 years ago

The video is not helping, doing a lot of unexplained things very fast I'm afraid.

Sorry, I'm not very good at this

I recorded a new vedio, please

https://user-images.githubusercontent.com/32295532/116496851-8f915200-a8d8-11eb-9eaf-b6f21e556d74.mp4

pedrobaeza commented 3 years ago

I think the problem is with the assignation itself. Use:

self.lines.update({"reference_field": False})
dreamhunter2333 commented 3 years ago

I think the problem is with the assignation itself. Use:

self.lines.update({"reference_field": False})

use update method

image

It doesn't work, onchange snapshot diff method still compare None with None

image

pedrobaeza commented 3 years ago

And what about using self.lines.update({"reference_field": ""})?

dreamhunter2333 commented 3 years ago

And what about using self.lines.update({"reference_field": ""})?

"" is Odoo Server Error

image

In convert_to_record method of class Reference

    def convert_to_record(self, value, record):
        # value in [False, None], return None, what make onchange diff doesn't work
        if value:
            res_model, res_id = value.split(',')
            return record.env[res_model].browse(int(res_id))
        return None

What is the impact of return false in convert_to_record method of class Reference ?