Skip to content

[18.0][FIX] contract: show smart buttons when partner has contracts#1416

Open
shamnaskoyani wants to merge 1 commit into
OCA:18.0from
shamnaskoyani:18.0-fix-contract-partner-smart-button-visibility
Open

[18.0][FIX] contract: show smart buttons when partner has contracts#1416
shamnaskoyani wants to merge 1 commit into
OCA:18.0from
shamnaskoyani:18.0-fix-contract-partner-smart-button-visibility

Conversation

@shamnaskoyani
Copy link
Copy Markdown

Summary

  • The Sale Contracts and Purchase Contracts smart buttons on the partner form were hidden whenever customer_rank == 0 / supplier_rank == 0. Partners created outside the Sales / Purchase flows (e.g. via the Contacts module) keep those ranks at 0, so users could not reach existing contracts from the partner form.
  • Extended the invisible expression on each button to also consider sale_contract_count / purchase_contract_count (which are already rendered by the statinfo widget on the button). A button now shows whenever the partner has contracts of that type, regardless of rank. No change in behaviour when the rank is non-zero.

Test plan

  • Install contract on a clean 18.0 database.
  • Create a contact from the Contacts module (do not create any sale order / vendor bill for them, so customer_rank and supplier_rank stay at 0).
  • Create a sale contract for that contact → open the partner form → the Sale Contracts smart button is visible with count 1; the Purchase Contracts button stays hidden.
  • Create a purchase contract for the same contact → both smart buttons are now visible with count 1.
  • Verify a contact with rank 0 and no contracts still shows neither button (no regression).
  • Added unit test test_smart_button_visible_on_rank_zero_partner in contract/tests/test_contract.py.

Module maturity

  • Production/Stable

Closes #1412

@shamnaskoyani
Copy link
Copy Markdown
Author

CI is red on a pre-existing flake unrelated to this PR. Summary from the failed run:

  • Tests themselves: 0 failed, 0 error(s) of 282 tests — all pass, including the new test_smart_button_visible_on_rank_zero_partner.
  • The failure trigger is checklog-odoo picking up a WARNING ... TestContractPortal.test_tour: Killing chrome descendants-or-self of 341: 5 remaining followed by 5 leaked chrome (zombie) processes.
  • test_tour is an HttpCase in contract/tests/test_portal.py that drives headless Chrome through contract_portal_tour. This PR does not touch the portal, the tour, or any HTTP test — only contract/views/res_partner_view.xml (admin smart-button visibility) and a unit test in contract/tests/test_contract.py.
  • The chrome-zombie warning is a known intermittent issue with headless Chrome in Odoo CI; it does not indicate a real test failure.

Could a maintainer please re-run the failed jobs? I don't have rerun permissions on OCA.

Copy link
Copy Markdown
Contributor

@carlosdauden carlosdauden left a comment

Choose a reason for hiding this comment

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

Related with:
#1413

Copy link
Copy Markdown
Member

@flotho flotho left a comment

Choose a reason for hiding this comment

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

easy code review
LGTM

@pedrobaeza pedrobaeza added this to the 18.0 milestone Apr 27, 2026
Comment thread contract/tests/test_contract.py Outdated
"There was an error and the view couldn't be opened.",
)

def test_smart_button_visible_on_rank_zero_partner(self):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This tests is useless, so please remove it.

@shamnaskoyani
Copy link
Copy Markdown
Author

Thanks for the review @pedrobaeza — removed the test in fa54560. You're right, it was just asserting on the literal XML I had just written; the existing test_contract_count already covers count computation, and the visibility behaviour is purely a view-arch concern that doesn't add value as a Python test.

@pedrobaeza
Copy link
Copy Markdown
Member

Please squash the commits into one. We don't want history that doesn't add value.

The "Sale Contracts" and "Purchase Contracts" smart buttons on the
partner form were hidden when customer_rank == 0 / supplier_rank == 0.
Partners created outside the Sales/Purchase flows (e.g. via the
Contacts module) keep these ranks at 0, so users could not reach
linked contracts from the partner form even when they existed.

Extend the invisible expression to also consider sale_contract_count
and purchase_contract_count, which are already rendered by the
statinfo widget on each button. A button is now shown whenever the
partner has contracts of that type, regardless of rank.

Closes OCA#1412
@shamnaskoyani shamnaskoyani force-pushed the 18.0-fix-contract-partner-smart-button-visibility branch from fa54560 to ffee8f2 Compare April 27, 2026 12:16
@shamnaskoyani
Copy link
Copy Markdown
Author

Done — squashed into a single commit (ffee8f2). Thanks @pedrobaeza.

@pedrobaeza
Copy link
Copy Markdown
Member

Reviewing the content, this avoids the direct creation of a contract for the partners. Isn't that what you was against in #1413 (comment), @carlosdauden ?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[18.0][BUG] contract: future contracts smart button is hidden on contacts without customer_rank or supplier_rank

6 participants