OpusVL / mtd

Repository for Making Tax Digital Odoo modules
GNU Affero General Public License v3.0
2 stars 6 forks source link

[8.0]Error `Expected singleton: account.account.type(25, 37)` creating "Accounting Set-Up" #20

Open Nick-OpusVL opened 5 years ago

Nick-OpusVL commented 5 years ago

How to reproduce

What should happen

Should not have an error, so we can fill in fields.

What happens

In the GUI we see Odoo Warning dialogue with body Expected singleton: account.account.type(25, 37)

In the logs, we see this:

openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 546, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 583, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 319, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 316, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 812, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 412, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5998, in onchange
    newval = record[name]
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5654, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 838, in __get__
    self.determine_draft_value(record)
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 946, in determine_draft_value
    self._compute_value(record)
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 885, in _compute_value
    self.compute(records)
  File "/mnt/extra-addons-bundles/OpusVL_mtd/account_mtd_vat/models/hmrc_posting_configuration.py", line 39, in _compute_company_id
    ('name', '=', 'Output Tax')])
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 851, in __set__
    value = self.convert_to_cache(value, record)
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 1051, in convert_to_cache
    return int(value or 0)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5624, in __int__
    return self.id
  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 1909, in __get__
    return record.ensure_one()._ids[0]
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5320, in ensure_one
    raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: account.account.type(25, 37)')
Nick-OpusVL commented 5 years ago

Consider whether this is likely to be an issue in:

Fix the issue in:

Nick-OpusVL commented 5 years ago

Effectively, there are at least two taxes that satisfy the following condition in the database in question:

        self.output_account_type = self.env['account.account.type'].search([
            ('code', '=', 'Output Tax'),
            ('name', '=', 'Output Tax')])

but when assigning to a many2one there can only be zero or one records (this makes sense if you think about it).

There's a possibility the line below it might also suffer the same fate, which does similar in the same way but looks for Input Tax.

We need to decide if it's a data bug or it's reasonable to have this situation and therefore should handle it in the code. If it's a data bug, we could at least trap the >2 matches case and throw a more user-friendly error message.