Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged

Hi! im trying to replicate e one2one relation in odoo and i've got something similar, my problem is that when i want to delete the value of the file field in the publication form(example below) it keeps reassigning the previous value, how can I fix this ? ideas?


publication class:


classPublication(models.Model):_

​name = 'gestion_jardin.publication'

​_description = 'gestion_jardin.publication'

file =fields.Many2one('gestion_jardin.file',compute='compute_file',inverse='file_inverse')
def compute_file(self):for b in self:b.file=self.env['gestion_jardin.file'].search([('publication.id','=',b.id)]).id
def file_inverse(self):

o = self.file.id

self.env['gestion_jardin.file'].search([('id','=',o)]).write({'publication':self.id}) 

file class:

classFile(models.Model):

_name = 'gestion_jardin.file'

_description = 'gestion_jardin.file'
name = fields.Char()

publication = fields.Many2one('gestion_jardin.publication', unique=True, string='Publicación')

file = fields.Binary(required=True, string='Archivo')

_sql_constraints = [ ('unique_publication', 'unique(publication)', 'A Publication record can only have one associated File record.') ]

@api.model

defcreate(self, vals):

if self.search_count([('publication', '=', vals.get('publication'))]):

raise ValidationError('A Publication record can only have one associated File record.')

returnsuper().create(vals)

defwrite(self, vals):

if self.search_count([('publication', '=', vals.get('publication'))]) > 1:

raiseValidationError('A Publication record can only have one associated File record.')

returnsuper().write(vals)

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
pro 24
6532
2
čvn 24
11635
1
čvc 21
3611
3
úno 24
7025
1
srp 25
2052