Skip to content

[19.0][FIX] partner_address_street3: copy street3 to child contacts#2352

Open
fsmw wants to merge 7 commits into
OCA:19.0from
fsmw:19.0-fix-partner-address-street3-child-context
Open

[19.0][FIX] partner_address_street3: copy street3 to child contacts#2352
fsmw wants to merge 7 commits into
OCA:19.0from
fsmw:19.0-fix-partner-address-street3-child-context

Conversation

@fsmw
Copy link
Copy Markdown
Contributor

@fsmw fsmw commented May 18, 2026

When creating a child contact via the 'Contacts & Addresses' kanban view, the street3 field was not being copied from the parent company.

This is because street3 was missing from the child_ids context defaults. Overwriting the view context attribute via XML view inheritance has a high risk of conflicting with other modules doing the same.

Fix

Implement a Python-only default_get override in res.partner to copy street3 (and other address fields in _address_fields()) from the parent partner when creating a child contact (i.e. when default_parent_id is present in the context).

Changes

  • models/res_partner.py: Override default_get to populate address fields from parent if default_parent_id is set
  • tests/test_street_3.py: Regression test verifying street3 is copied when creating child contacts via default_get

Fixes #2298

@OCA-git-bot OCA-git-bot added series:19.0 mod:partner_address_street3 Module partner_address_street3 labels May 18, 2026
@fsmw fsmw force-pushed the 19.0-fix-partner-address-street3-child-context branch from eea1d95 to c42b297 Compare May 18, 2026 22:00
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='child_ids']" position="attributes">
<attribute name="context">{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoid overwriting context from XML, instead use default_get

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain how you would do that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just Move all the logic to python side using default_get method and in this method, add default value for street3 field

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Check my comment :- #2327 (review)

@fsmw fsmw force-pushed the 19.0-fix-partner-address-street3-child-context branch from 150c436 to 9614333 Compare May 20, 2026 13:27
for field in self._address_fields():
if (
field in default_fields
and field in parent._fields
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is indeed redundant

@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented May 20, 2026

Removed the redundant field in parent._fields check — _address_fields() returns res.partner field names so the guard is always True. Good catch @NL66278 and @BhaveshHeliconia.

@fsmw fsmw force-pushed the 19.0-fix-partner-address-street3-child-context branch 2 times, most recently from 66849a0 to a4472c0 Compare May 21, 2026 19:28
@fsmw fsmw force-pushed the 19.0-fix-partner-address-street3-child-context branch from 0a47e09 to 5ee6df1 Compare May 29, 2026 17:57
res.append("street3")
return res

@api.onchange("parent_id")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will result in onchange_parent_id being called twice. First under its own name, then through the super() call here.

Copy link
Copy Markdown
Contributor

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

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

Please leave the module partner_category_description intact.

fsmw added a commit to fsmw/partner-contact that referenced this pull request Jun 3, 2026
The street3 fix PR (OCA#2352) accidentally removed this module via a
cherry-pick mis-merge. Restore it to its previous 19.0 state so the
PR diff is scoped to partner_address_street3 only.

Reported-by: @NL66278
@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented Jun 3, 2026

@NL66278 thanks for the catch — both issues addressed in 2 new commits on top of the branch:

1. partner_category_description restored (d7d68f2dc) — full module brought back from the previous 19.0 state. That deletion was an artefact of a messy cherry-pick, not a deliberate change. Apologies for the noise.

2. Replaced the onchange override with default_get (2a60585f5) — you were right that the onchange override was the wrong layer. The actual bug from #2298 (street3 not prefilled in the inline "Add in Contacts & Addresses" dialog) never went through the onchange path: in that flow Odoo passes default_parent_id in the context, not via a user-driven onchange. So the previous PR did not actually fix the reported issue.

New approach: default_get reads default_parent_id from context and copies address fields, guarded by if not values.get(field) so explicit defaults win. Tests rewritten to cover the inline create context and the no-clobber guarantee.

Re-requesting your review.

fsmw and others added 6 commits June 3, 2026 19:14
…t_view for street3 copy

Replace the default_get override (which fails with unsaved parents/NewId)
and the get_view override (which injected default_street3 into child_ids
context via lxml) with a simple onchange("parent_id") that extends
base's onchange_parent_id to ensure street3 is always copied.

The base onchange_parent_id already copies all _address_fields(), but
the explicit setdefault guarantees street3 is included even when it's
the only address field set on the parent.

Co-authored-by: BhaveshHeliconia <bhavesh@heliconia.io>
In Odoo 19, onchange_parent_id() returns {} instead of None.
Move the 'or {}' fallback after the parent_id check so the
method preserves the base return value when there is no parent.
Update tests to assert no street3 is added rather than asserting
exact return type, making them compatible across Odoo versions.
The street3 fix PR (OCA#2352) accidentally removed this module via a
cherry-pick mis-merge. Restore it to its previous 19.0 state so the
PR diff is scoped to partner_address_street3 only.

Reported-by: @NL66278
…arent_id

The previous onchange("parent_id") override never ran in the inline
"Add in Contacts & Addresses" form, because parent_id is delivered
via default_parent_id in the context, not via an interactive onchange.
That is why the original issue (OCA#2298) — street3 not prefilled in the
inline create dialog — was not actually fixed.

Replace the onchange override with a default_get that reads
default_parent_id from the context and copies the address fields,
guarded by 'if not values.get(field)' so explicit defaults are not
clobbered. This matches the suggestion from BhaveshHeliconia and
addresses the 'onchange_parent_id called twice' concern raised by
NL66278 (the override was redundant with the base behaviour anyway).

Tests rewritten around default_get to cover the inline create context
and the no-clobber guarantee.
@fsmw fsmw force-pushed the 19.0-fix-partner-address-street3-child-context branch from 2a60585 to 16282c0 Compare June 3, 2026 23:14
@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented Jun 3, 2026

Conflicts resolved. Rebased on top of upstream/19.0 (HEAD f4d6c91d7). Only the setup/_metapackage/pyproject.toml version bump needed manual resolution — kept the upstream version 19.0.20260531.0.

CI is now running on the rebased branch.

@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented Jun 3, 2026

@NL66278 @BhaveshHeliconia — el rebase 16282c088854b7 también arregla el lint de ruff E501 (línea 113 del test) que estaba bloqueando el merge. La nueva línea 113-117 ahora pasa ruff. CI re-corrida.

@BhaveshHeliconia
Copy link
Copy Markdown
Contributor

@NL66278 @BhaveshHeliconia — el rebase 16282c088854b7 también arregla el lint de ruff E501 (línea 113 del test) que estaba bloqueando el merge. La nueva línea 113-117 ahora pasa ruff. CI re-corrida.

Could you please explain this in English?

@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented Jun 4, 2026

@BhaveshHeliconia sorry, slipped into Spanish by mistake. Here's the English version:

The rebase 16282c088854b7 also fixes the ruff E501 lint (line 113 of the test) that was blocking the merge. The new lines 113-117 now pass ruff. CI has been re-run.

fsmw added a commit to fsmw/partner-contact that referenced this pull request Jun 4, 2026
…r street3 copy

The onchange("parent_id") override (commit f524e12) does not fire in the
inline 'Add in Contacts & Addresses' form: that flow passes default_parent_id
in the context and never triggers a user-driven onchange, so street3 was
still not copied when adding a contact to an unsaved parent (as confirmed
by BhaveshHeliconia on 2026-05-21).

Replace the onchange with a default_get override that reads default_parent_id
from the context and copies all _address_fields() (including street3),
guarded by 'if not values.get(field)' so explicit defaults still win.

This mirrors the approach used in the 19.0 sister PR OCA#2352 (commit 16282c0),
which was reviewed and validated in the same scenario.
@fsmw
Copy link
Copy Markdown
Contributor Author

fsmw commented Jun 4, 2026

Hi @NL66278 — gentle ping. Your CHANGES_REQUESTED from 2026-05-30 asked to leave the partner_category_description module intact. That module has been restored in commit f754852 (full module brought back from the previous 19.0 state, see the commit diff).

Subsequent commits on top:

  • 16282c0 — replaced the onchange override with default_get (your earlier hint that the onchange layer was the wrong one)
  • 88854b7 — fixed the ruff E501 line-length that was blocking the merge
  • f754852 — restored partner_category_description

CI is green on the rebased branch. Mind taking another look to clear the CHANGES_REQUESTED? Happy to address any further feedback.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants