Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] stock: ensure name exists creating location #165941

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented May 17, 2024

Current behavior:
In some instances we will try to create a stock.location
record from a complete_name field value (one such case is
creating from import). When this happens, the creation will fail
due to the not-null constraint on the name field in the table
and display a SQL error in logs.

Expected behavior:
Use part of the complete_name as the name.

Steps to reproduce:

  1. Create an .xlsx document representing a Repair Order to be
    imported, such that the Location cell value does not
    already exist in the database

  2. Install the test-import-export module, go into the Repair app
    and from the favorites action button select import data

  3. Upload the .xlsx file, press 'Test Import', select the
    'Create New' option for offending data points

  4. Observe that the new Location can not be created, and in the
    console logs there is the output of the bad SQL query

Cause of the issue:
The _rec_name field for stock.location is complete_name,
however the name field as also a required field. When we
create the records in this flow, _rec_name is used to infer
which fields need to be included in the query. So name is
never added to the INSERT query and we end up violating the
not-null constraint on this column of the table (bad query).

Fix:
If there is no name in the create vals dict for the location
record, use the end segment of complete_name.

opw-3796010

Forward-Port-Of: #165447
Forward-Port-Of: #163298

@robodoo
Copy link
Contributor

robodoo commented May 17, 2024

@fw-bot
Copy link
Contributor Author

fw-bot commented May 17, 2024

This PR targets saas-16.4 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label May 17, 2024
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label May 17, 2024
@fw-bot
Copy link
Contributor Author

fw-bot commented May 17, 2024

@ethanrobv @Whenrow ci/runbot failed on this forward-port PR

**Current behavior:**
In some instances we will try to create a `stock.location`
record from a `complete_name` field  value (one such case is
creating from import). When this happens, the creation will fail
due to the not-null constraint on the `name` field in the table
and display a SQL error in logs.

**Expected behavior:**
A `stock.location` record can be created via name.

**Steps to reproduce:**
1. Create an .xlsx document representing a Repair Order to be
     imported, such that the `Location` cell value does not
     already exist in the database

2. Install the test-import-export module, go into the Repair app
     and from the favorites action button select import data

3. Upload the .xlsx file, press 'Test Import', select the
     'Create New' option for offending data points

4. Observe that the new location can not be created, and in the
     console logs there is the output of the bad SQL query

**Cause of the issue:**
The `_rec_name` field for `stock.location` is `complete_name`,
however it is not required while the `name` field is. When the
INSERT query is constructed it will not include a name:val
mapping and thus will fail due to the not-null constraint on the
table for this column.

**Fix:**
Override name_create() in `stock.location` to create the record
with `name` instead of `_rec_name`.

opw-3796010

X-original-commit: eb69eee
@ethanrobv ethanrobv force-pushed the saas-16.4-15.0-opw-3796010-import-repair-orders-etvi-Sk7w-fw branch from 183f9ff to 7d47f07 Compare May 21, 2024 09:25
@fw-bot
Copy link
Contributor Author

fw-bot commented May 21, 2024

@ethanrobv @Whenrow this PR was modified / updated and has become a normal PR. It should be merged the normal way (via @robodoo)

@ethanrobv
Copy link
Contributor

@robodoo r+

robodoo pushed a commit that referenced this pull request May 21, 2024
**Current behavior:**
In some instances we will try to create a `stock.location`
record from a `complete_name` field  value (one such case is
creating from import). When this happens, the creation will fail
due to the not-null constraint on the `name` field in the table
and display a SQL error in logs.

**Expected behavior:**
A `stock.location` record can be created via name.

**Steps to reproduce:**
1. Create an .xlsx document representing a Repair Order to be
     imported, such that the `Location` cell value does not
     already exist in the database

2. Install the test-import-export module, go into the Repair app
     and from the favorites action button select import data

3. Upload the .xlsx file, press 'Test Import', select the
     'Create New' option for offending data points

4. Observe that the new location can not be created, and in the
     console logs there is the output of the bad SQL query

**Cause of the issue:**
The `_rec_name` field for `stock.location` is `complete_name`,
however it is not required while the `name` field is. When the
INSERT query is constructed it will not include a name:val
mapping and thus will fail due to the not-null constraint on the
table for this column.

**Fix:**
Override name_create() in `stock.location` to create the record
with `name` instead of `_rec_name`.

opw-3796010

closes #165941

X-original-commit: eb69eee
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Vincent Ethan <etvi@odoo.com>
@robodoo robodoo closed this May 21, 2024
@fw-bot fw-bot deleted the saas-16.4-15.0-opw-3796010-import-repair-orders-etvi-Sk7w-fw branch June 4, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants