Skip to content

[FIX] construction_developer: mark uom of WI required if no product#1869

Closed
assh-odoo wants to merge 1 commit intoodoo:19.0from
odoo-dev:19.0-sentry-7339061587-work-items-assh
Closed

[FIX] construction_developer: mark uom of WI required if no product#1869
assh-odoo wants to merge 1 commit intoodoo:19.0from
odoo-dev:19.0-sentry-7339061587-work-items-assh

Conversation

@assh-odoo
Copy link
Contributor

@assh-odoo assh-odoo commented Mar 17, 2026

Currently, an error occurs when a user creates a work item.

Steps to Reproduce:

  • Install the construction_developer.
  • Go to Sales > Products > Work Items.
  • Create a new record by entering only the name and save.

Error:

ValueError: ValueError('NotNullViolation(\'null value in column "uom_id" of relation "product_template" violates not-null constraint\\n
DETAIL:  Failing row contains (83, 1, null, null, null, null, 2, 2, service, no, null, {"en_US": "sadsa"}, null, null, null, null, 0.0, null, null, f, t, t, t, null, null, null, 2026-03-17 06:18:40.850849, 2026-03-17 06:18:40.850849, null, null, 15, null, {"1": 2}, null, null, null, null, null, null, purchase, null, null, null, manual, no, order, null, null, null, null, null, null, null, 0.9).\\n\') 
while evaluating\n\'for wi in records:\\n    new_product = env[\\\'product.product\\\'].create({\\n        \\\'name\\\': wi.x_name,\\n        \\\'default_code\\\': wi.x_reference,\\n        \\\'type\\\': \\\'service\\\',\\n        \\\'service_policy\\\': "delivered_manual",\\n        \\\'list_price\\\': wi.x_unit_price,\\n        \\\'standard_price\\\': wi.x_unit_cost,\\n        \\\'uom_id\\\': wi.x_unit_custom_id.id,\\n    })\\n    wi.write({\\\'x_product_id\\\': new_product.id})\'') while evaluating
'record.x_unit_cost'

This error occurs because when a product is not set on the work item, a new product
is created using the work item name. During this process, the system tries to assign
uom_id from x_unit_custom_id 1, which is empty if the user has not selected any unit,
causing the error.

This commit ensures that the field x_unit_custom_id is set as required
at the view level.

[2]-

<field name="x_unit_custom_id" class="oe_inline" string="Unit" force_save="1" options="{'no_open': True}" placeholder="" invisible="x_product_id"/>

sentry-7339061587

@robodoo
Copy link
Collaborator

robodoo commented Mar 17, 2026

Pull request status dashboard

@assh-odoo assh-odoo requested a review from maan-odoo March 17, 2026 11:46
Copy link
Contributor

@maan-odoo maan-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maan-odoo maan-odoo marked this pull request as ready for review March 17, 2026 11:57
@C3POdoo C3POdoo requested a review from a team March 17, 2026 12:11
@maan-odoo maan-odoo requested a review from vava-odoo March 17, 2026 12:15
@vava-odoo vava-odoo requested a review from dhrs-odoo March 17, 2026 12:17
@assh-odoo assh-odoo force-pushed the 19.0-sentry-7339061587-work-items-assh branch from 280095f to 11a8da2 Compare March 17, 2026 13:00
@dhrs-odoo
Copy link
Contributor

@vava-odoo LGTM 🚀

Currently, an error occurs when a user creates a work item.

Steps to Reproduce:

 - Install the construction_developer.
 - Go to Sales > Products > Work Items.
 - Create a new record by entering only the name and save.

ValueError: ValueError('NotNullViolation(\'null value in column "uom_id" of relation "product_template" violates not-null constraint\\nDETAIL:  Failing row contains (83, 1, null, null, null, null, 2, 2, service, no, null, {"en_US": "sadsa"}, null, null, null, null, 0.0, null, null, f, t, t, t, null, null, null, 2026-03-17 06:18:40.850849, 2026-03-17 06:18:40.850849, null, null, 15, null, {"1": 2}, null, null, null, null, null, null, purchase, null, null, null, manual, no, order, null, null, null, null, null, null, null, 0.9).\\n\') while evaluating\n\'for wi in records:\\n    new_product = env[\\\'product.product\\\'].create({\\n        \\\'name\\\': wi.x_name,\\n        \\\'default_code\\\': wi.x_reference,\\n        \\\'type\\\': \\\'service\\\',\\n        \\\'service_policy\\\': "delivered_manual",\\n        \\\'list_price\\\': wi.x_unit_price,\\n        \\\'standard_price\\\': wi.x_unit_cost,\\n        \\\'uom_id\\\': wi.x_unit_custom_id.id,\\n    })\\n    wi.write({\\\'x_product_id\\\': new_product.id})\'') while evaluating
'record.x_unit_cost'

This error occurs because when a product is not set on the work item,
a new product is created using the work item name. During this process,
the system tries to assign uom_id from x_unit_custom_id [1], which is empty
if the user has not selected any unit, causing the error.

This commit ensures that the field x_unit_custom_id is set as required
at the view level when no product is set on the work item.

[1]: https://github.com/odoo/industry/blob/92cd04cc4f35007e232ae1bddafc75a3fe1b4732/construction_developer/data/ir_actions_server.xml#L164

[2]: https://github.com/odoo/industry/blob/92cd04cc4f35007e232ae1bddafc75a3fe1b4732/construction_developer/data/ir_ui_view.xml#L156

sentry-7339061587
@assh-odoo assh-odoo force-pushed the 19.0-sentry-7339061587-work-items-assh branch from 11a8da2 to ef5b322 Compare March 18, 2026 05:24
@vava-odoo vava-odoo changed the title [FIX] construction_developer: prevent error when creating work items [FIX] construction_developer: mark uom of WI required if no product Mar 18, 2026
Copy link
Collaborator

@vava-odoo vava-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robodoo r+ squash

@robodoo
Copy link
Collaborator

robodoo commented Mar 18, 2026

Merge method set to squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants