Skip to Content
Menu
This question has been flagged
2 Replies
3275 Views

Hello, this is my code:


class clinicaservicio(models.Model):
    _name = 'clinica.servicio'
    name = fields.Integer('Id servicio', required=True)
    precio = fields.Float('Precio')

class clinicafactura(models.Model):
    _name = 'clinica.factura'
    servicio = fields.Many2one('clinica.servicio','ID Servicio', required = True)
    precio = fields.Float(string = 'precio', related = 'servicio.precio', store = True, readonly = True)
    iva = fields.Float(string='IVA',compute='_iva')
    total = fields.Float(string='Total',compute='_total')
   
   
    @api.depends('precio', 'iva')
    def _total(self):

        for record in self:
            record.total = record.precio + record.iva


    @api.depends('precio')
    def _iva(self):

             for record in self:
                record.iva =record.precio *(10/100)



My error:


Error:
Odoo Server Error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
    result = request.dispatch()
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 682, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 358, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 346, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 911, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 530, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1317, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1336, in do_search_read
    return Model.web_search_read(domain, fields, offset=offset, limit=limit, order=sort)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/models/models.py", line 53, in web_search_read
    records = self.search_read(domain, fields, offset=offset, limit=limit, order=order)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4798, in search_read
    result = records.read(fields)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3001, in read
    return self._read_format(fnames=fields, load=load)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3021, in _read_format
    vals[name] = convert(record[name], record, use_name_get)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 5620, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 973, in __get__
    self.compute_value(recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1112, in compute_value
    records._compute_field_value(self)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4020, in _compute_field_value
    getattr(self, field.compute)()
  File "/usr/lib/python3/dist-packages/odoo/addons/clinica_definitivo/models/clinica.py", line 93, in _iva
    self.iva =self.precio *(10/100)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 927, in __get__
    record.ensure_one()
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4946, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 638, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 314, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ValueError: Expected singleton: clinica.factura(1, 2)



I dont know how to solve this, thanks for your help!

Avatar
Discard
Author Best Answer

I already tried this and keep giving error :(

Thanks for ur help

Avatar
Discard
Best Answer

Rewrite the function as Follows


@api.depends('precio', 'iva')
    def _total(self):

    for record in self:
        record.total = record.precio + record.iva


@api.depends('precio')
    def _iva(self):

    for record in self:
            record.iva =record.precio *(10/100)

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 23
3722
1
Aug 22
12616
4
Aug 22
16244
4
Jul 21
39118
4
Feb 21
17752