Some users may be allowed to unlink invoices without billing access,
but with current code, they are not able, as the asset line check is
done without sudo, and other users except billing or higher ones
aren't allowed to access to that model.
TT49673
Previous to this fix, the functionality was working when an invoice was posted when called from action_post. But in cases as reversals action_post is not used for posting the reversal invoice, _post function is used directly.
To solve the issue, the funcionality is moved from action_post to _post, to ensure it's being executed in all invoice post scenarios.
As it was, the information put was like:
```
Error mientras se procesa el activo '....': <class 'odoo.exceptions.UserError'>
```
Now, it is:
```
Error mientras se procesa el activo '....': UserError("No puedes usar esta cuenta (...) en este diario, consulta la sección 'Control-Acceso' en la pestaña 'Configuración avanzada' en el diario relacionado.")
```
TT46362
This PR enables the configuration of salvage value in the asset profile.
Users can configure it with a fixed amount or a percentage of the salvage value.
Steps to reproduce the problem:
- User (Not accountant) create an invoice.
- Create invoice plan with Deposit on 1st Invoice
- Confirm Order > Register Deposit > Create and View bills
- It throws a permission error
That's because the search on asset lines is done always for each write on the account.move
if certain fields (like the date) are written.
When updating assets massively the performance when searching for deprecation_lines_ids is very low.
It is a difficult problem to detect since massive asset updates are not common.
Indexing in this field dramatically improves the timing performance.
For example, to update 3000 records it took 30 sec. With this index it takes to 2 seconds.
To start, the context `company_id` is no longer used in v14. Instead, we use `with_company`.
OTOH, it doesn't make much sense because in case you have several companies enabled in your context, not necessarily your main one is gonna be the one that should be used for the asset. Instead, it should be the move company always, or consistency rules will fail.
Altered forward port of https://github.com/OCA/account-financial-tools/pull/1223.
@Tecnativa TT31311
2 related fixes:
- When removing an asset line depreciation move, we have to pass it
first to draft, or we won't be able to remove it even with the
context.
- When removing a move, the check for removing the linked asset should
be only for purchase documents, not for "not sale" documents.