odoo/odoo#200870

Created by fw-bot
Merged at 2dbc946ca5f100c3cbd5416aefc2319e71edb45c

Statuses:

label
odoo-dev:master-17.0-opw-4554639-sudo_check_invoice_state-sile-421419-fw
head
1c561f6ec17a14eb421e29681e6c6d5c7f9cafe7
merged
7 months ago by Bugfix, Levi Siuzdak
odoo/odoo
17.0 #200722
saas-17.4 #200833
18.0 #200847
saas-18.1 #200860
saas-18.2 #200867
saas-18.3
saas-18.4
19.0
master #200870

[FW][FIX] sale: sudo check invoice state in wizard

Versions

  • 17.0+

Steps

  1. Log in as admin;
  2. have a user with access to Sales: Own Documents but not Invoicing;
  3. assign them as a salesperson to a sales order;
  4. create a draft invoice for the order;
  5. assign admin as salesperson on the invoice;
  6. log in as user;
  7. create invoice for the sales order.

Issue

  • No existing draft warning is displayed.
  • Trying to create a draft results in an access error.

Cause

The wizards starts out as a newId. Consequently, its sale_order_ids field is also newId with the actual order id as its origin. When trying to read the invoice_ids of a pseudo-record, it will ignore any records you don't have access to. This is why you don't see an exisiting draft invoice warning.

Then when creating the invoice, the check is done again, but no longer as pseudo-records. Now it does get an invoice to check, and throws an error because it's assigned to a different user.

Solution

Use _origin.sudo() to ensure access to the state field of the invoices.

opw-4554639

Forward-Port-Of: #200722