Skip to main content

Auto-assign CRM teams to partners based on ZIP code patterns

Project description

Odoo Community Association

CRM Team ZIP Assignment

Beta License: AGPL-3 OCA/crm Translate me on Weblate Try me on Runboat

Auto-assign CRM teams to partners based on ZIP code patterns using regular expressions.

https://raw.githubusercontent.com/OCA/crm/16.0/crm_team_zip_assign/static/description/crm_team_form_view.png

Features

  • Auto-assign CRM teams to partners based on ZIP code patterns

  • Support for Python regular expressions with validation constraints

  • Multi-company support

  • Geographic filtering by countries and states

  • Priority-based assignment when multiple teams match

  • Exclusion flag for partners who should not be auto-assigned

  • Real-time regex pattern validation prevents invalid patterns

  • Contextual action for manual assignment from partner views

  • Conditional assignment using pre-zip match conditions: teams can specify a domain expression (Odoo domain syntax) that must be satisfied by the partner before ZIP regex matching is performed. This allows for advanced filtering, e.g., only assign if the partner is a company or meets other criteria.

Assignment Logic

The assignment is triggered on partner create/write when ZIP, company, country, state, or exclusion flag changes. A contextual action is also available from partner views for manual assignment. The system:

  1. Finds all active teams with ZIP assignment enabled in the partner’s company

  2. Filters teams by matching countries and states (if specified)

  3. For each eligible team, evaluates the optional pre-zip match condition (Odoo domain expression). If the partner does not satisfy the condition, the team is skipped.

  4. Tests each remaining team’s regex patterns against the partner’s ZIP code

  5. Selects the team with highest priority if multiple matches exist

  6. Logs assignment activity for audit purposes

Assignment Rules

  1. Only active teams with “Active ZIP Assignment” enabled are considered

  2. Only teams in the same company as the partner are considered

  3. Teams must have matching countries (partner’s country must be in team’s countries)

  4. Teams must have matching states (partner’s state must be in team’s states, if team has states defined)

  5. If a team has a pre-zip match condition, the partner must satisfy the condition (Odoo domain) before ZIP regex matching is performed. If not set, all partners are considered.

  6. Partners without a company, ZIP code, country, or state are not assigned

  7. Partners with “Exclude from ZIP Assignment” checked are not assigned

  8. When multiple teams match, the team with highest priority is selected

  9. Invalid regex patterns are prevented by validation constraints at input time

Table of contents

Usage

Setting up CRM Teams

  1. Go to CRM → Configuration → Sales Teams

  2. Edit or create a CRM team

  3. Enable “Active ZIP Assignment” checkbox

  4. Set “ZIP Assignment Priority” (higher number = higher priority)

  5. Configure geographic coverage: - Select “Countries” where this team operates (required) - Select “States” within those countries (required)

  6. Add ZIP patterns in the “ZIP Patterns” tab

  7. (Optional) Set a “Pre-Zip Match Condition” using Odoo domain syntax to restrict assignment to partners matching specific criteria (e.g., only companies, only certain types, etc.)

Geographic Coverage

  • Countries: Teams will only be considered for partners located in the selected countries

  • States: Teams will only be considered for partners in the selected states

  • Domain Filtering: State selection is automatically filtered based on selected countries

Pre-Zip Match Condition

You can further restrict team assignment by specifying a domain condition in the “Pre-Zip Match Condition” field. This uses Odoo’s domain syntax (e.g., [(‘is_company’, ‘=’, True)]). Only partners matching this condition will be considered for ZIP pattern matching for this team.

Pre-Zip Match Condition Examples

Some example domain conditions:

  • [(‘is_company’, ‘=’, True)] — Only assign to partners that are companies

  • [(‘type’, ‘=’, ‘contact’)] — Only assign to contacts

  • [(‘industry_id’, ‘!=’, False)] — Only assign to partners with an industry set

You can combine multiple conditions, e.g. [(‘is_company’, ‘=’, True), (‘country_id’, ‘=’, ref(‘base.us’))]

ZIP Pattern Examples

All patterns are validated in real-time to ensure they are valid Python regular expressions:

  • ^1[0-5].* - ZIP codes starting with 10-15

  • ^2[0-9].* - ZIP codes starting with 20-29

  • ^751.* - ZIP codes starting with 751

  • .*123$ - ZIP codes ending with 123

  • ^[1-3].* - ZIP codes starting with 1, 2, or 3

  • ^(10|20|30).* - ZIP codes starting with 10, 20, or 30

Pattern Validation

The system validates regex patterns when they are entered:

  • Invalid patterns will show an error message immediately

  • Error messages include the specific regex error for debugging

  • Only valid patterns can be saved to the database

Partner Configuration

Partners have an “Exclude from ZIP Assignment” checkbox to prevent automatic assignment.

Teams can have a “Pre-Zip Match Condition” to restrict assignment to partners matching specific criteria before ZIP pattern matching is performed.

Usage

Automatic Assignment

Partners are automatically assigned to CRM teams when:

  • A partner is created with complete geographic information (ZIP, country, state)

  • A partner’s ZIP code is modified

  • A partner’s country or state is changed

  • A partner’s company is changed

  • The exclusion flag is modified

For each team, if a “Pre-Zip Match Condition” is set, the partner must match this condition before ZIP pattern matching is performed. If not set, all partners are considered for ZIP matching.

Manual Assignment

You can also trigger assignment manually:

  • Use the contextual action available in partner views

  • This is useful for reassigning existing partners after updating team configurations or after addon installation

Assignment Requirements

For automatic assignment to work, partners must have:

  • A ZIP code

  • A country

  • A state

  • A company

  • “Exclude from ZIP Assignment” must be unchecked

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Binhex

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

This module is part of the OCA/crm project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file odoo_addon_crm_team_zip_assign-16.0.1.0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo_addon_crm_team_zip_assign-16.0.1.0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dd46fe315bd18e942d8c3340144bc67d84924b1a3d0b8206b5f211e3c7b5dcbc
MD5 5fe10842714ce92339ff15587fc38a60
BLAKE2b-256 5af8d6b57a8fc597d6e0efd1d01a2586e7f5d2fe2d7125f4fed65bccfa8d6bc7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page