[FIX] partner_address_street3: copy street3 from parent when creating contact#2327
[FIX] partner_address_street3: copy street3 from parent when creating contact#2327fsmw wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a UI defaulting gap in partner_address_street3: when creating a child contact from a company via Contacts & Addresses, the street3 value wasn’t prefilled from the parent company.
Changes:
- Add a
default_getoverride onres.partnerto copy address fields (includingstreet3) from the parent whenparent_idis set. - Reuse
_address_fields()as the source of fields to copy.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| parent = self.browse(values.get("parent_id")) | ||
| address_fields = self._address_fields() | ||
| for field in address_fields: | ||
| if field in default_fields and field in parent._fields: |
There was a problem hiding this comment.
default_get currently overwrites any default values already provided by super().default_get()/context for the address fields (e.g., default_street, default_city, etc.). This can change existing behavior outside the “create contact under company” flow. Consider only filling fields that are missing/empty (e.g., via setdefault or a if not values.get(field) guard) so explicit defaults aren’t clobbered.
| if field in default_fields and field in parent._fields: | |
| if ( | |
| field in default_fields | |
| and field in parent._fields | |
| and not values.get(field) | |
| ): |
| @api.model | ||
| def default_get(self, default_fields): | ||
| values = super().default_get(default_fields) | ||
| if "parent_id" in default_fields and values.get("parent_id"): | ||
| parent = self.browse(values.get("parent_id")) | ||
| address_fields = self._address_fields() | ||
| for field in address_fields: | ||
| if field in default_fields and field in parent._fields: | ||
| values[field] = parent[field] | ||
| return values |
There was a problem hiding this comment.
There’s test coverage for street3 syncing on create()/write(), but this PR changes the default_get behavior (the regression reported in the UI happens before record creation). Please add/adjust a test that asserts default_get (or a Form created with default_parent_id in context) pre-fills street3 from the parent company.
| parent = self.browse(values.get("parent_id")) | ||
| address_fields = self._address_fields() | ||
| for field in address_fields: | ||
| if field in default_fields and field in parent._fields: |
There was a problem hiding this comment.
field in parent._fields is redundant here because parent is a res.partner record and _address_fields() returns partner field names; removing this extra check would simplify the loop (and avoids hiding problems if _address_fields() ever returns an invalid entry).
| if field in default_fields and field in parent._fields: | |
| if field in default_fields: |
73761fd to
0af6287
Compare
BhaveshHeliconia
left a comment
There was a problem hiding this comment.
-
We can use this code snippet to avoid context overwrite in XML:
@api.onchange("parent_id")
def onchange_parent_id(self):
result = super().onchange_parent_id() or {}
if self.parent_id:
result.setdefault("value", {})["street3"] = self.parent_id.street3
return result -
Also, there would be no need of
default_getafter this. -
This works for v17+.
a64ec64 to
aa33215
Compare
|
Removed the redundant |
BhaveshHeliconia
left a comment
There was a problem hiding this comment.
It’s still not working in this case. Did you check my suggestion?
Steps to Reproduce:
- Open
Contactform - Set
street3field - Click on 'Add' button under
Contacts & Addresseswithout saving parent contact - Now, observe that
street3is not being set in child contact form.
829d402 to
abe1aaa
Compare
…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>
596d718 to
f524e12
Compare
…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.
Update: switched from onchange to default_get (mirrors the 19.0 fix in #2352)@BhaveshHeliconia @NL66278 @luisDIXMIT You were right — the New approach (commit This is the same approach we just landed in the 19.0 sister PR #2352 (commit Tests updated:
Pre-commit passes locally. Could you re-review when you have a moment? 🙏 |

Summary
When creating a contact inside a company using the "Add" button in Contacts & Addresses, the
street3field was not being copied from the parent company, unlike other address fields (street, street2, zip, city, etc.).Fix
Override
default_getto copy all address fields (includingstreet3) from the parent company when creating a child contact.Steps to reproduce
Street 3fieldExpected behavior
The Street 3 value should be copied from the parent company.
Fixes
Closes #2298