OCA / sale-workflow

Odoo Sales, Workflow and Organization
GNU Affero General Public License v3.0
295 stars 1.03k forks source link

[16] sale_order_type - Error when posting an expense #2551

Open elarapuntsistemes opened 1 year ago

elarapuntsistemes commented 1 year ago

## Module sale_order_type

## Describe the bug Traceback (most recent call last): File "/opt/odoo/odoo/api.py", line 984, in get cache_value = field_cache[record._ids[0]] KeyError: 17

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/fields.py", line 1160, in get value = env.cache.get(record, self) File "/opt/odoo/odoo/api.py", line 991, in get raise CacheMiss(record, field) odoo.exceptions.CacheMiss: 'account.move(17,).company_currency_id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/api.py", line 984, in get cache_value = field_cache[record._ids[0]] KeyError: 44

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/fields.py", line 1160, in get value = env.cache.get(record, self) File "/opt/odoo/odoo/api.py", line 991, in get raise CacheMiss(record, field) odoo.exceptions.CacheMiss: 'account.move.line(44,).compute_all_tax'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/api.py", line 984, in get cache_value = field_cache[record._ids[0]] KeyError: 44

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/fields.py", line 1160, in get value = env.cache.get(record, self) File "/opt/odoo/odoo/api.py", line 991, in get raise CacheMiss(record, field) odoo.exceptions.CacheMiss: 'account.move.line(44,).currency_rate'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/odoo/odoo/http.py", line 1584, in _serve_db return service_model.retrying(self._serve_ir_http, self.env) File "/opt/odoo/odoo/service/model.py", line 133, in retrying result = func() File "/opt/odoo/odoo/http.py", line 1611, in _serve_ir_http response = self.dispatcher.dispatch(rule.endpoint, args) File "/opt/odoo/odoo/http.py", line 1809, in dispatch result = self.request.registry['ir.http']._dispatch(endpoint) File "/opt/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch result = endpoint(request.params) File "/opt/odoo/odoo/http.py", line 697, in route_wrapper result = endpoint(self, *args, *params_ok) File "/opt/odoo/addons/web/controllers/dataset.py", line 46, in call_button action = self._call_kw(model, method, args, kwargs) File "/opt/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/opt/odoo/odoo/api.py", line 461, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/opt/odoo/odoo/api.py", line 448, in _call_kw_multi result = method(recs, args, kwargs) File "/opt/odoo/addons/hr_expense/models/hr_expense.py", line 1058, in action_sheet_move_create res = expense_line_ids.with_context(clean_context(self.env.context)).action_move_create() File "/opt/odoo/addons/sale_expense/models/hr_expense.py", line 58, in action_move_create return super(Expense, self).action_move_create() File "/opt/odoo/addons/hr_expense/models/hr_expense.py", line 605, in action_move_create return self.sheet_id._do_create_moves() # backport File "/opt/odoo/addons/hr_expense/models/hr_expense.py", line 1078, in _do_create_moves .create([sheet._prepare_payment_vals() for sheet in company_account_sheets]) File "", line 2, in create File "/opt/odoo/odoo/api.py", line 410, in _model_create_multi return create(self, arg) File "/opt/odoo/addons/account/models/account_payment.py", line 714, in create pay.move_id.write(to_write) File "/opt/odoo/addons/account/models/account_move.py", line 2272, in write )).write(vals) File "/opt/odoo/addons/mail/models/mail_thread.py", line 315, in write result = super(MailThread, self).write(values) File "/opt/odoo/addons/mail/models/mail_activity_mixin.py", line 241, in write return super(MailActivityMixin, self).write(vals) File "/opt/odoo/odoo/models.py", line 3762, in write self.modified(vals) File "/opt/odoo/odoo/models.py", line 6039, in modified for field, records, create in tocompute: File "/opt/odoo/odoo/models.py", line 6111, in _modified_triggers yield from records._modified_triggers(subtree) File "/opt/odoo/odoo/models.py", line 6106, in _modified_triggers records = model.search([(field.name, 'in', real_records.ids)], order='id') File "/opt/odoo/odoo/models.py", line 1508, in search res = self._search(domain, offset=offset, limit=limit, order=order, count=count) File "/opt/odoo/odoo/models.py", line 4637, in _search self._flush_search(domain, order=order) File "/opt/odoo/odoo/models.py", line 4615, in _flush_search self.env[model_name].flush_model(field_names) File "/opt/odoo/odoo/models.py", line 5569, in flush_model self._flush(fnames) File "/opt/odoo/odoo/models.py", line 5638, in _flush value = field.convert_to_column(value, record) File "/opt/odoo/odoo/fields.py", line 1613, in convert_to_column currency = record[:1].with_context(prefetch_fields=False)[currency_field_name] File "/opt/odoo/odoo/models.py", line 5868, in getitem return self._fields[key].get(self, type(self)) File "/opt/odoo/odoo/fields.py", line 2795, in get return super().get(records, owner) File "/opt/odoo/odoo/fields.py", line 1209, in get self.compute_value(recs) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value return super()._compute_field_value(field) File "/opt/odoo/odoo/models.py", line 4203, in _compute_field_value fields.determine(field.compute, self) File "/opt/odoo/odoo/fields.py", line 100, in determine return needle(records, args) File "/opt/odoo/odoo/fields.py", line 689, in _compute_related values = [first(value[name]) for value in values] File "/opt/odoo/odoo/fields.py", line 689, in values = [first(value[name]) for value in values] File "/opt/odoo/odoo/models.py", line 5868, in getitem return self._fields[key].get(self, type(self)) File "/opt/odoo/odoo/fields.py", line 2795, in get return super().get(records, owner) File "/opt/odoo/odoo/fields.py", line 1157, in get self.recompute(record) File "/opt/odoo/odoo/fields.py", line 1365, in recompute apply_except_missing(self.compute_value, recs) File "/opt/odoo/odoo/fields.py", line 1338, in apply_except_missing func(records) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value return super()._compute_field_value(field) File "/opt/odoo/odoo/models.py", line 4208, in _compute_field_value self.filtered('id')._validate_fields(fnames) File "/opt/odoo/odoo/models.py", line 1348, in _validate_fields check(self) File "/opt/odoo/addons/account/models/account_move.py", line 1780, in _validate_taxes_country self._compute_tax_country_id() # We need to ensure this field has been computed, as we use it in our check File "/opt/odoo/addons/account/models/account_move.py", line 1295, in _compute_tax_country_id if record.fiscal_position_id.foreign_vat: File "/opt/odoo/odoo/fields.py", line 2795, in get return super().get(records, owner) File "/opt/odoo/odoo/fields.py", line 1157, in get self.recompute(record) File "/opt/odoo/odoo/fields.py", line 1365, in recompute apply_except_missing(self.compute_value, recs) File "/opt/odoo/odoo/fields.py", line 1338, in apply_except_missing func(records) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value return super()._compute_field_value(field) File "/opt/odoo/odoo/models.py", line 4208, in _compute_field_value self.filtered('id')._validate_fields(fnames) File "/opt/odoo/odoo/models.py", line 1348, in _validate_fields check(self) File "/opt/odoo/addons/account/models/account_move.py", line 1780, in _validate_taxes_country self._compute_tax_country_id() # We need to ensure this field has been computed, as we use it in our check File "/opt/odoo/addons/account/models/account_move.py", line 1298, in _compute_tax_country_id record.tax_country_id = record.company_id.account_fiscal_country_id File "/opt/odoo/odoo/fields.py", line 1320, in set records.write({self.name: write_value}) File "/opt/odoo/addons/account/models/account_move.py", line 2241, in write if (move.name and move.name != '/' and move.sequence_number not in (0, 1) and 'journal_id' in vals and move.journal_id.id != vals['journal_id']): File "/opt/odoo/odoo/fields.py", line 1157, in get self.recompute(record) File "/opt/odoo/odoo/fields.py", line 1365, in recompute apply_except_missing(self.compute_value, recs) File "/opt/odoo/odoo/fields.py", line 1338, in apply_except_missing func(records) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/addons/mail/models/mail_thread.py", line 403, in _compute_field_value return super()._compute_field_value(field) File "/opt/odoo/odoo/models.py", line 4203, in _compute_field_value fields.determine(field.compute, self) File "/opt/odoo/odoo/fields.py", line 97, in determine return needle(args) File "/opt/odoo/addons/account/models/account_move.py", line 702, in _compute_name move._set_next_sequence() File "/opt/odoo/addons/account_sequence/models/sequence_mixin.py", line 55, in _set_next_sequence self._compute_split_sequence() File "/opt/odoo/addons/account/models/sequence_mixin.py", line 105, in _compute_split_sequence record.sequence_prefix = sequence[:matching.start(1)] File "/opt/odoo/odoo/fields.py", line 1320, in set records.write({self.name: write_value}) File "/opt/odoo/addons/account/models/account_move.py", line 2269, in write with self._sync_dynamic_lines(container): File "/usr/lib/python3.10/contextlib.py", line 135, in enter return next(self.gen) File "/opt/odoo/addons/account/models/account_move.py", line 2137, in _sync_dynamic_lines stack.enter_context(self._sync_dynamic_line( File "/usr/lib/python3.10/contextlib.py", line 492, in enter_context result = _cm_type.enter(cm) File "/usr/lib/python3.10/contextlib.py", line 135, in enter return next(self.gen) File "/opt/odoo/addons/account/models/account_move.py", line 2016, in _sync_dynamic_line needed_before = needed() File "/opt/odoo/addons/account/models/account_move.py", line 1990, in needed for computed_needed in container['records'].mapped(needed_vals_fname): File "/opt/odoo/odoo/models.py", line 5372, in mapped recs = recs._fields[name].mapped(recs) File "/opt/odoo/odoo/fields.py", line 1279, in mapped self.get(first(remaining), type(remaining)) File "/opt/odoo/odoo/fields.py", line 1209, in get self.compute_value(recs) File "/opt/odoo/odoo/fields.py", line 2349, in compute_value super().compute_value(records) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/odoo/models.py", line 4203, in _compute_field_value fields.determine(field.compute, self) File "/opt/odoo/odoo/fields.py", line 97, in determine return needle(args) File "/opt/odoo/addons/hr_expense/models/account_move_line.py", line 42, in _compute_all_tax super(AccountMoveLine, expense_lines.with_context(force_price_include=True))._compute_all_tax() File "/opt/odoo-venv/lib/python3.10/site-packages/odoo/addons/account_invoice_triple_discount/models/account_move_line.py", line 111, in _compute_all_tax line.update({"discount": aggregated_discount}) File "/opt/odoo/odoo/models.py", line 5537, in update self[name] = value File "/opt/odoo/odoo/models.py", line 5877, in setitem return self._fields[key].set(self, value) File "/opt/odoo/odoo/fields.py", line 1320, in set records.write({self.name: write_value}) File "/opt/odoo-venv/lib/python3.10/site-packages/odoo/addons/account_payment_partner/models/account_move_line.py", line 43, in write return super().write(vals) File "/opt/odoo/addons/account/models/account_move_line.py", line 1471, in write with self.move_id._check_balanced(move_container),\ File "/usr/lib/python3.10/contextlib.py", line 135, in enter return next(self.gen) File "/opt/odoo/addons/account/models/account_move_line.py", line 1380, in _sync_invoice before = existing() File "/opt/odoo/addons/account/models/account_move_line.py", line 1365, in existing return { File "/opt/odoo/addons/account/models/account_move_line.py", line 1369, in 'currency_rate': line.currency_rate, File "/opt/odoo/odoo/fields.py", line 1209, in get self.compute_value(recs) File "/opt/odoo/odoo/fields.py", line 1387, in compute_value records._compute_field_value(self) File "/opt/odoo/odoo/models.py", line 4203, in _compute_field_value fields.determine(field.compute, self) File "/opt/odoo/odoo/fields.py", line 97, in determine return needle(args) File "/opt/odoo/addons/account/models/account_move_line.py", line 635, in _compute_currency_rate line.currency_rate = get_rate( File "/opt/odoo/addons/account/models/account_move_line.py", line 628, in get_rate return self.env['res.currency']._get_conversion_rate( File "/opt/odoo/odoo/addons/base/models/res_currency.py", line 252, in _get_conversion_rate res = currency_rates.get(to_currency.id) / currency_rates.get(from_currency.id) TypeError: unsupported operand type(s) for /: 'float' and 'NoneType'

The above server error caused the following client error: RPC_ERROR: Odoo Server Error RPCError@http://oca-sale-workflow-16-0-ccc833785bae.runboat.odoo-community.org/web/assets/680-ab4a683/web.assets_backend.min.js:969:274 makeErrorFromResponse@http://oca-sale-workflow-16-0-ccc833785bae.runboat.odoo-community.org/web/assets/680-ab4a683/web.assets_backend.min.js:973:163 jsonrpc/promise</<@http://oca-sale-workflow-16-0-ccc833785bae.runboat.odoo-community.org/web/assets/680-ab4a683/web.assets_backend.min.js:981:34

## To Reproduce V16

Steps to reproduce the behavior:

  1. Install Expenses and sale_order_type.
  2. Create a new expense, pay by the Company, select a bank journal.
  3. Create report, submit to manager, approve and post journal entries.

Expected behavior Post new account move.

Additional context Tested on runboat

rousseldenis commented 1 year ago

@elarapuntsistemes @igallart I can confirm modifying account_move.company_currency_id field to stored one is fixing your problem.

Nevertheless, you maybe should write a test with standard modules installed to reproduce it, then propose the fix to Odoo

antoniocanovas commented 1 year ago

Standard modules haven't this issue, it's only when install sale_order_type. Odoo support just told: "unistall sale_order_type and it works" weeks ago.

Let's approve this solution to go ahead ... @pedrobaeza was working on it in Spanish oca days too. Thank you