Skip to content

[FIX] partner_address_street3: copy street3 from parent when creating contact#2327

Open
fsmw wants to merge 3 commits into
OCA:18.0from
fsmw:fix/2298-street3-copy-from-parent
Open

[FIX] partner_address_street3: copy street3 from parent when creating contact#2327
fsmw wants to merge 3 commits into
OCA:18.0from
fsmw:fix/2298-street3-copy-from-parent

Conversation

@fsmw
Copy link
Copy Markdown
Contributor

@fsmw fsmw commented Apr 19, 2026

Summary

When creating a contact inside a company using the "Add" button in Contacts & Addresses, the street3 field was not being copied from the parent company, unlike other address fields (street, street2, zip, city, etc.).

Fix

Override default_get to copy all address fields (including street3) from the parent company when creating a child contact.

Steps to reproduce

  1. Create a company contact and set a value in the Street 3 field
  2. Click Add in Contacts & Addresses to create a contact in the company
  3. The Create Contact dialog shows an empty Street 3 field

Expected behavior

The Street 3 value should be copied from the parent company.

Fixes

Closes #2298

Copilot AI review requested due to automatic review settings April 19, 2026 02:18
@OCA-git-bot OCA-git-bot added series:18.0 mod:partner_address_street3 Module partner_address_street3 labels Apr 19, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_get override on res.partner to copy address fields (including street3) from the parent when parent_id is 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:
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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)
):

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +30
@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
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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:
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
if field in default_fields and field in parent._fields:
if field in default_fields:

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

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

The street3 field still doesn’t seem to be copied.

Image

@fsmw fsmw force-pushed the fix/2298-street3-copy-from-parent branch 2 times, most recently from 73761fd to 0af6287 Compare April 30, 2026 11:56
Copy link
Copy Markdown
Contributor

@BhaveshHeliconia BhaveshHeliconia left a comment

Choose a reason for hiding this comment

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

  • 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_get after this.

  • This works for v17+.

@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.

Copy link
Copy Markdown
Contributor

@BhaveshHeliconia BhaveshHeliconia left a comment

Choose a reason for hiding this comment

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

It’s still not working in this case. Did you check my suggestion?
Steps to Reproduce:

  • Open Contact form
  • Set street3 field
  • Click on 'Add' button under Contacts & Addresses without saving parent contact
  • Now, observe that street3 is not being set in child contact form.

@fsmw fsmw force-pushed the fix/2298-street3-copy-from-parent branch 2 times, most recently from 829d402 to abe1aaa Compare May 21, 2026 19:28
@OCA-git-bot OCA-git-bot added mod:animal Module animal mod:base_location_nuts Module base_location_nuts mod:partner_external_map Module partner_external_map mod:account_partner_company_group Module account_partner_company_group mod:partner_pricelist_tracking Module partner_pricelist_tracking mod:sale_partner_company_group Module sale_partner_company_group mod:partner_multi_relation Module partner_multi_relation mod:partner_company_group Module partner_company_group mod:partner_contact_address_default Module partner_contact_address_default mod:partner_identification_eori Module partner_identification_eori mod:partner_firstname Module partner_firstname mod:partner_company_default Module partner_company_default mod:partner_contact_tags_in_popup Module partner_contact_tags_in_popup mod:partner_identification Module partner_identification mod:partner_property Module partner_property labels May 21, 2026
@OCA-git-bot OCA-git-bot added mod:base_country_state_translatable Module base_country_state_translatable mod:base_partner_sequence Module base_partner_sequence mod:partner_second_lastname Module partner_second_lastname mod:partner_priority Module partner_priority mod:partner_email_check Module partner_email_check mod:partner_category_type Module partner_category_type mod:partner_contact_access_link Module partner_contact_access_link mod:partner_deduplicate_acl Module partner_deduplicate_acl mod:partner_category_description Module partner_category_description mod:partner_contact_nationality Module partner_contact_nationality mod:partner_contact_role Module partner_contact_role mod:partner_is_company_auth_signup Module partner_is_company_auth_signup mod:base_location_geonames_import Module base_location_geonames_import mod:partner_manual_rank Module partner_manual_rank mod:partner_contact_birthplace Module partner_contact_birthplace mod:partner_company_type Module partner_company_type mod:partner_deduplicate_filter Module partner_deduplicate_filter mod:partner_contact_age_range Module partner_contact_age_range mod:partner_identification_unique_by_category Module partner_identification_unique_by_category mod:partner_supplier_ref_sequence Module partner_supplier_ref_sequence mod:partner_category_security Module partner_category_security mod:base_location Module base_location mod:crm_partner_company_group Module crm_partner_company_group labels May 21, 2026
fsmw and others added 2 commits May 29, 2026 13:56
…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>
@fsmw fsmw force-pushed the fix/2298-street3-copy-from-parent branch from 596d718 to f524e12 Compare May 29, 2026 17:57
…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

Update: switched from onchange to default_get (mirrors the 19.0 fix in #2352)

@BhaveshHeliconia @NL66278 @luisDIXMIT

You were right — the @api.onchange("parent_id") override from commit f524e12 does not fire in the inline "Add in Contacts & Addresses" form, because that flow passes default_parent_id in the context and never triggers a user-driven onchange. I was able to reproduce the issue described in BhaveshHeliconia's review of 2026-05-21 ("It's still not working in this case") on the unsaved-parent path.

New approach (commit 9c2df1fb): override default_get instead. It reads default_parent_id from the context (falling back to values.get("parent_id")) and copies all _address_fields() (including street3) from the parent, with a if not values.get(field) guard so explicit defaults still win.

This is the same approach we just landed in the 19.0 sister PR #2352 (commit 16282c0), where it was reviewed and CI-validated. Both branches now share the same shape, which should make backports easier.

Tests updated:

  • test_default_get_copies_street3_from_default_parent_id — replicates the inline form context (default_parent_id in context).
  • test_default_get_does_not_overwrite_explicit_value — explicit defaults win.
  • test_default_get_no_parent — no parent, no copy.

Pre-commit passes locally. Could you re-review when you have a moment? 🙏

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

Labels

mod:account_partner_company_group Module account_partner_company_group mod:animal Module animal mod:base_country_state_translatable Module base_country_state_translatable mod:base_location_geonames_import Module base_location_geonames_import mod:base_location_nuts Module base_location_nuts mod:base_location Module base_location mod:base_partner_sequence Module base_partner_sequence mod:crm_partner_company_group Module crm_partner_company_group mod:partner_address_street3 Module partner_address_street3 mod:partner_category_description Module partner_category_description mod:partner_category_security Module partner_category_security mod:partner_category_type Module partner_category_type mod:partner_company_default Module partner_company_default mod:partner_company_group Module partner_company_group mod:partner_company_type Module partner_company_type mod:partner_contact_access_link Module partner_contact_access_link mod:partner_contact_address_default Module partner_contact_address_default mod:partner_contact_age_range Module partner_contact_age_range mod:partner_contact_birthplace Module partner_contact_birthplace mod:partner_contact_nationality Module partner_contact_nationality mod:partner_contact_role Module partner_contact_role mod:partner_contact_tags_in_popup Module partner_contact_tags_in_popup mod:partner_deduplicate_acl Module partner_deduplicate_acl mod:partner_deduplicate_filter Module partner_deduplicate_filter mod:partner_email_check Module partner_email_check mod:partner_external_map Module partner_external_map mod:partner_firstname Module partner_firstname mod:partner_identification_eori Module partner_identification_eori mod:partner_identification_unique_by_category Module partner_identification_unique_by_category mod:partner_identification Module partner_identification mod:partner_is_company_auth_signup Module partner_is_company_auth_signup mod:partner_manual_rank Module partner_manual_rank mod:partner_multi_relation Module partner_multi_relation mod:partner_pricelist_tracking Module partner_pricelist_tracking mod:partner_priority Module partner_priority mod:partner_property Module partner_property mod:partner_second_lastname Module partner_second_lastname mod:partner_supplier_ref_sequence Module partner_supplier_ref_sequence mod:sale_partner_company_group Module sale_partner_company_group series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

partner_address_street3: Street 3 field is not copied when a contact is created inside a company

5 participants