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.
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.
If the assets are created before posting the invoice, they wouldn't have a name and the "code" field of the assets will be empty, but they would have the invoice name.
* account_asset: Do not loop on all the lines to search for one linked asset
Before this change, the use of `mapped` on self did loop on all the move
lines that are included in self to get the assets, what could be very
costly for a simple write on a lot of move lines. As the goal is to raise
an error only if at least one move is linked to an asset, we break the
loop if the condition is fulfilled.
* performance improvement
* [RMV] - Remove useless dependency
In 12.0 account_fiscal_year is a standard feature no need to depend on oca
module account_fiscal_year