diff --git a/partner_identification_kyc/README.rst b/partner_identification_kyc/README.rst new file mode 100644 index 00000000000..1fe01504c1f --- /dev/null +++ b/partner_identification_kyc/README.rst @@ -0,0 +1,169 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================== +Partner Identification KYC +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:10c73c95886256911541d6f9b7ed42f8f1cbddd83a56b784b533ee8334d66525 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github + :target: https://github.com/OCA/partner-contact/tree/19.0/partner_identification_kyc + :alt: OCA/partner-contact +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/partner-contact-19-0/partner-contact-19-0-partner_identification_kyc + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Partner Identification KYC +========================== + +This module adds Know Your Customer (KYC) identification functionality +to the partner identification automation system. It provides a +specialized KYC identification category with associated activities and +workflows to manage customer verification processes. + +**Table of contents** + +.. contents:: + :local: + +Installation +============ + +This module depends on ``partner_identification_automation_activity`` +which must be installed first. The module will automatically create the +KYC identification category and activity type during installation. + +Configuration +============= + +Identification Category +~~~~~~~~~~~~~~~~~~~~~~~ + +The module automatically creates a "KYC" identification category with +the following default settings: + +- Initial Activity Type: "Perform KYC Check" +- Renew Activity Type: "Perform KYC Check" +- Create Activity on New: True +- Default Validity: 1 year +- Renewal Lead Number: 2 +- Renewal Lead Unit: Months + +Activity Types +~~~~~~~~~~~~~~ + +The module creates the "Perform KYC Check" activity type which is +assigned to both the initial and renewal activities for KYC +identification records. + +Filters +~~~~~~~ + +A filter is added to the id_numbers views to allow filtering on the KYC +Category. + +Usage +===== + +Request KYC Button +~~~~~~~~~~~~~~~~~~ + +On the partner form, a "Request KYC" button will appear when: + +- There is no KYC identification record in the 'new', 'running', or + 'to_renew' states +- OR there is no ID number record of the KYC category at all + +The button will be hidden if: + +- There is a 'running' or 'to_renew' KYC record +- OR there is already a 'new' status KYC record (to prevent redundant + records) + +Clicking the button will create a new KYC identification record in the +'new' status, triggering the associated activity for KYC officers to +process. + +API Function +~~~~~~~~~~~~ + +For partners created via API, there is a function to trigger the KYC +process automatically. If no KYC identification record exists for a +partner, calling this function will create a record in the 'new' status. + +Activity Management +------------------- + +KYC identification records are associated with the "Perform KYC Check" +activity type, which appears in the activity views for tracking and +processing by responsible officers. + +Changelog +========= + +[1.0.0] - 2025-01-01 +-------------------- + +Added +~~~~~ + +- Initial implementation of KYC identification category +- "Request KYC" button on partner form +- API function to trigger KYC flow for API-created partners +- Dedicated "Perform KYC Check" activity type +- Filters for KYC category in id_numbers views + +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 +======= + +Contributors +------------ + +- OCA Community +- Emiel van Bokhoven + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/partner-contact `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_identification_kyc/__init__.py b/partner_identification_kyc/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/partner_identification_kyc/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_identification_kyc/__manifest__.py b/partner_identification_kyc/__manifest__.py new file mode 100644 index 00000000000..3f24f7aeb6e --- /dev/null +++ b/partner_identification_kyc/__manifest__.py @@ -0,0 +1,25 @@ +{ + "name": "Partner Identification KYC", + "summary": "Know Your Customer identification for partners", + "version": "19.0.1.0.0", + "category": "Customer Relationship Management", + "author": "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/partner-contact", + "license": "AGPL-3", + "depends": [ + "partner_identification_automation_activity", + "partner_identification", + ], + "data": [ + "data/activity_type_data.xml", + "data/identification_category_data.xml", + "views/res_partner_views.xml", + "views/identification_number_views.xml", + "views/res_partner_id_category_view.xml", + ], + "demo": [ + "demo/identification_number_demo.xml", + ], + "installable": True, + "auto_install": False, +} diff --git a/partner_identification_kyc/data/activity_type_data.xml b/partner_identification_kyc/data/activity_type_data.xml new file mode 100644 index 00000000000..17e4dbcfd6e --- /dev/null +++ b/partner_identification_kyc/data/activity_type_data.xml @@ -0,0 +1,19 @@ + + + + + KYC Identification Sequence + kyc.identification + KYC + 3 + + + + + Perform KYC Check + 2 + days + Perform KYC verification + fa-user-secret + + diff --git a/partner_identification_kyc/data/identification_category_data.xml b/partner_identification_kyc/data/identification_category_data.xml new file mode 100644 index 00000000000..2dbf1f9815a --- /dev/null +++ b/partner_identification_kyc/data/identification_category_data.xml @@ -0,0 +1,16 @@ + + + + + KYC + KYC + + + + 1 + years + 2 + months + + + diff --git a/partner_identification_kyc/demo/identification_number_demo.xml b/partner_identification_kyc/demo/identification_number_demo.xml new file mode 100644 index 00000000000..f8070ec2b52 --- /dev/null +++ b/partner_identification_kyc/demo/identification_number_demo.xml @@ -0,0 +1,103 @@ + + + + + Demo Partner for KYC Testing + demo.kyc@example.com + +1 234 567 8900 + + + + KYC Verification Authority + + info@kyc-authority.example.com + + + + + John KYC Customer + john.customer@example.com + + + + + Jane Running KYC + jane.running@example.com + + + + Bob To-Renew KYC + bob.torenew@example.com + + + + Alice Expired KYC + alice.expired@example.com + + + + + + + + KYC-001-DRAFT + draft + + + + + + + + + + KYC-002-RUNNING + open + + + + + + + + + + KYC-003-TORENEW + pending + + + + + + + + + + KYC-004-EXPIRED + close + + + + + diff --git a/partner_identification_kyc/i18n/de.po b/partner_identification_kyc/i18n/de.po new file mode 100644 index 00000000000..f92fceffa22 --- /dev/null +++ b/partner_identification_kyc/i18n/de.po @@ -0,0 +1,20 @@ +# German translation for partner_identification_kyc +# Copyright (C) 2025 +# This file is distributed under the same license as the partner_identification_kyc module. +#, fuzzy +msgid "" +msgstr "" +"Content-Type: text/plain; charset=utf-8\n" +"Language: de\n" + +#. module: partner_identification_kyc +msgid "Request KYC" +msgstr "KYC anfordern" + +#. module: partner_identification_kyc +msgid "Perform KYC Check" +msgstr "KYC-Prüfung durchführen" + +#. module: partner_identification_kyc +msgid "KYC" +msgstr "KYC" \ No newline at end of file diff --git a/partner_identification_kyc/i18n/es.po b/partner_identification_kyc/i18n/es.po new file mode 100644 index 00000000000..f799f28a612 --- /dev/null +++ b/partner_identification_kyc/i18n/es.po @@ -0,0 +1,20 @@ +# Spanish translation for partner_identification_kyc +# Copyright (C) 2025 +# This file is distributed under the same license as the partner_identification_kyc module. +#, fuzzy +msgid "" +msgstr "" +"Content-Type: text/plain; charset=utf-8\n" +"Language: es\n" + +#. module: partner_identification_kyc +msgid "Request KYC" +msgstr "Solicitar KYC" + +#. module: partner_identification_kyc +msgid "Perform KYC Check" +msgstr "Realizar verificación KYC" + +#. module: partner_identification_kyc +msgid "KYC" +msgstr "KYC" \ No newline at end of file diff --git a/partner_identification_kyc/i18n/fr.po b/partner_identification_kyc/i18n/fr.po new file mode 100644 index 00000000000..0fb1e1f3e06 --- /dev/null +++ b/partner_identification_kyc/i18n/fr.po @@ -0,0 +1,20 @@ +# French translation for partner_identification_kyc +# Copyright (C) 2025 +# This file is distributed under the same license as the partner_identification_kyc module. +#, fuzzy +msgid "" +msgstr "" +"Content-Type: text/plain; charset=utf-8\n" +"Language: fr\n" + +#. module: partner_identification_kyc +msgid "Request KYC" +msgstr "Demander KYC" + +#. module: partner_identification_kyc +msgid "Perform KYC Check" +msgstr "Effectuer une vérification KYC" + +#. module: partner_identification_kyc +msgid "KYC" +msgstr "KYC" \ No newline at end of file diff --git a/partner_identification_kyc/i18n/it.po b/partner_identification_kyc/i18n/it.po new file mode 100644 index 00000000000..43598faec3e --- /dev/null +++ b/partner_identification_kyc/i18n/it.po @@ -0,0 +1,20 @@ +# Italian translation for partner_identification_kyc +# Copyright (C) 2025 +# This file is distributed under the same license as the partner_identification_kyc module. +#, fuzzy +msgid "" +msgstr "" +"Content-Type: text/plain; charset=utf-8\n" +"Language: it\n" + +#. module: partner_identification_kyc +msgid "Request KYC" +msgstr "Richiedi KYC" + +#. module: partner_identification_kyc +msgid "Perform KYC Check" +msgstr "Effettua controllo KYC" + +#. module: partner_identification_kyc +msgid "KYC" +msgstr "KYC" \ No newline at end of file diff --git a/partner_identification_kyc/i18n/nl.po b/partner_identification_kyc/i18n/nl.po new file mode 100644 index 00000000000..8f7dcd1b3ee --- /dev/null +++ b/partner_identification_kyc/i18n/nl.po @@ -0,0 +1,20 @@ +# Dutch translation for partner_identification_kyc +# Copyright (C) 2025 +# This file is distributed under the same license as the partner_identification_kyc module. +#, fuzzy +msgid "" +msgstr "" +"Content-Type: text/plain; charset=utf-8\n" +"Language: nl\n" + +#. module: partner_identification_kyc +msgid "Request KYC" +msgstr "Verzoek KYC" + +#. module: partner_identification_kyc +msgid "Perform KYC Check" +msgstr "Voer KYC-controle uit" + +#. module: partner_identification_kyc +msgid "KYC" +msgstr "KYC" \ No newline at end of file diff --git a/partner_identification_kyc/models/__init__.py b/partner_identification_kyc/models/__init__.py new file mode 100644 index 00000000000..21153e6be40 --- /dev/null +++ b/partner_identification_kyc/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import res_partner_id_category diff --git a/partner_identification_kyc/models/res_partner.py b/partner_identification_kyc/models/res_partner.py new file mode 100644 index 00000000000..46f9dddaf06 --- /dev/null +++ b/partner_identification_kyc/models/res_partner.py @@ -0,0 +1,164 @@ +from odoo import api, fields, models +from odoo.exceptions import UserError + + +class ResPartner(models.Model): + _inherit = "res.partner" + + # Computed field to determine if the KYC button should be visible + show_kyc_button = fields.Boolean( + string="Show KYC Button", + compute="_compute_show_kyc_button", + store=False, + depends=["id_numbers", "id_numbers.category_id", "id_numbers.status"], + ) + + def _compute_show_kyc_button(self): + """Compute whether to show the KYC request button.""" + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category", + raise_if_not_found=False, + ) + if not kyc_category: + for partner in self: + partner.show_kyc_button = False + return + + # Find all partners in self that have an ongoing KYC record + ongoing_kyc_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "in", self.ids), + ("category_id", "=", kyc_category.id), + ("status", "in", ["draft", "open", "pending"]), + ] + ) + + ongoing_kyc_partner_ids = { + record.partner_id.id for record in ongoing_kyc_records + } + + for partner in self: + show_button = True + if not kyc_category.enable_on_child_contacts and not partner.is_company: + show_button = False + + if partner.id in ongoing_kyc_partner_ids: + show_button = False + + partner.show_kyc_button = show_button + + kyc_valid_until = fields.Date( + string="KYC Valid Until", + compute="_compute_kyc_valid_until", + store=True, + ) + + @api.depends( + "id_numbers.valid_until", "id_numbers.category_id", "id_numbers.status" + ) + def _compute_kyc_valid_until(self): + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category", + raise_if_not_found=False, + ) + for partner in self: + valid_until_date = False + if kyc_category: + kyc_records = partner.id_numbers.filtered( + lambda r: r.category_id == kyc_category and r.status == "open" + ) + # Collect valid_until dates from records that have them + valid_dates = [ + rec.valid_until for rec in kyc_records if rec.valid_until + ] + if valid_dates: + valid_until_date = min(valid_dates) + partner.kyc_valid_until = valid_until_date + + def action_view_kyc_records(self): + self.ensure_one() + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category", + raise_if_not_found=False, + ) + return { + "name": "KYC Records", + "type": "ir.actions.act_window", + "res_model": "res.partner.id_number", + "view_mode": "list,form", + "domain": [ + ("partner_id", "=", self.id), + ("category_id", "=", kyc_category.id if kyc_category else False), + ], + } + + def _create_kyc_record(self, partner): + """Private helper method to create a new KYC identification record.""" + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category" + ) + identification_model = self.env["res.partner.id_number"] + sequence_code = ( + self.env["ir.sequence"].next_by_code("kyc.identification") or "001" + ) + return identification_model.create( + { + "partner_id": partner.id, + "category_id": kyc_category.id, + "name": f"KYC-{partner.id}-{sequence_code}", + "status": "draft", + } + ) + + def action_request_kyc(self): + """Create a new KYC identification record in the 'draft' status.""" + self.ensure_one() # Ensure single record operation + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category" + ) + + # Check if there's already any active ('open', 'pending') or 'draft' status + # KYC record to prevent duplicates + existing_kyc = self.id_numbers.filtered( + lambda r: r.category_id == kyc_category + and r.status in ["draft", "open", "pending"] + ) + + if existing_kyc: + raise UserError( + self.env._("A KYC request has already been submitted for this partner.") + ) + + # Create a new identification number record for the KYC category using helper + # method + self._create_kyc_record(self) + + # Return action to trigger a refresh of the view + return { + "type": "ir.actions.client", + "tag": "reload", + } + + def ensure_kyc_record(self): + """ + API function to ensure a KYC record exists for the partner if none currently + exists. + If no active KYC identification record exists for a partner (not in 'draft', + 'open', or 'pending' status), this function creates a record in the 'draft' + status. + """ + kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category" + ) + + for partner in self: + # Check if there's already an active or pending KYC record for this partner + existing_kyc = partner.id_numbers.filtered( + lambda r: r.category_id == kyc_category + and r.status in ["draft", "open", "pending"] + ) + + if not existing_kyc: + # Create a new identification number record for the KYC category using + # helper method + self._create_kyc_record(partner) diff --git a/partner_identification_kyc/models/res_partner_id_category.py b/partner_identification_kyc/models/res_partner_id_category.py new file mode 100644 index 00000000000..0f20acea126 --- /dev/null +++ b/partner_identification_kyc/models/res_partner_id_category.py @@ -0,0 +1,12 @@ +from odoo import fields, models + + +class ResPartnerIdCategory(models.Model): + _inherit = "res.partner.id_category" + + enable_on_child_contacts = fields.Boolean( + string="Enable on Child Contacts", + default=False, + help="If checked, KYC checks can be performed on child contacts of a company.", + ) + responsible_id = fields.Many2one("res.users", string="Responsible") diff --git a/partner_identification_kyc/pyproject.toml b/partner_identification_kyc/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/partner_identification_kyc/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/partner_identification_kyc/readme/CONFIGURE.md b/partner_identification_kyc/readme/CONFIGURE.md new file mode 100644 index 00000000000..ea051ae0271 --- /dev/null +++ b/partner_identification_kyc/readme/CONFIGURE.md @@ -0,0 +1,17 @@ +### Identification Category + +The module automatically creates a "KYC" identification category with the following default settings: +- Initial Activity Type: "Perform KYC Check" +- Renew Activity Type: "Perform KYC Check" +- Create Activity on New: True +- Default Validity: 1 year +- Renewal Lead Number: 2 +- Renewal Lead Unit: Months + +### Activity Types + +The module creates the "Perform KYC Check" activity type which is assigned to both the initial and renewal activities for KYC identification records. + +### Filters + +A filter is added to the id_numbers views to allow filtering on the KYC Category. diff --git a/partner_identification_kyc/readme/CONTRIBUTORS.md b/partner_identification_kyc/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..738bb13829a --- /dev/null +++ b/partner_identification_kyc/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- OCA Community +- Emiel van Bokhoven diff --git a/partner_identification_kyc/readme/DESCRIPTION.md b/partner_identification_kyc/readme/DESCRIPTION.md new file mode 100644 index 00000000000..f6b0efc5548 --- /dev/null +++ b/partner_identification_kyc/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +# Partner Identification KYC + +This module adds Know Your Customer (KYC) identification functionality to the partner identification automation system. It provides a specialized KYC identification category with associated activities and workflows to manage customer verification processes. \ No newline at end of file diff --git a/partner_identification_kyc/readme/HISTORY.md b/partner_identification_kyc/readme/HISTORY.md new file mode 100644 index 00000000000..bc1d3a116e0 --- /dev/null +++ b/partner_identification_kyc/readme/HISTORY.md @@ -0,0 +1,7 @@ +## [1.0.0] - 2025-01-01 +### Added +- Initial implementation of KYC identification category +- "Request KYC" button on partner form +- API function to trigger KYC flow for API-created partners +- Dedicated "Perform KYC Check" activity type +- Filters for KYC category in id_numbers views \ No newline at end of file diff --git a/partner_identification_kyc/readme/INSTALL.md b/partner_identification_kyc/readme/INSTALL.md new file mode 100644 index 00000000000..f19896a1b82 --- /dev/null +++ b/partner_identification_kyc/readme/INSTALL.md @@ -0,0 +1 @@ +This module depends on `partner_identification_automation_activity` which must be installed first. The module will automatically create the KYC identification category and activity type during installation. diff --git a/partner_identification_kyc/readme/USAGE.md b/partner_identification_kyc/readme/USAGE.md new file mode 100644 index 00000000000..35ca3ef580e --- /dev/null +++ b/partner_identification_kyc/readme/USAGE.md @@ -0,0 +1,19 @@ +### Request KYC Button + +On the partner form, a "Request KYC" button will appear when: +- There is no KYC identification record in the 'new', 'running', or 'to_renew' states +- OR there is no ID number record of the KYC category at all + +The button will be hidden if: +- There is a 'running' or 'to_renew' KYC record +- OR there is already a 'new' status KYC record (to prevent redundant records) + +Clicking the button will create a new KYC identification record in the 'new' status, triggering the associated activity for KYC officers to process. + +### API Function + +For partners created via API, there is a function to trigger the KYC process automatically. If no KYC identification record exists for a partner, calling this function will create a record in the 'new' status. + +## Activity Management + +KYC identification records are associated with the "Perform KYC Check" activity type, which appears in the activity views for tracking and processing by responsible officers. diff --git a/partner_identification_kyc/static/description/icon.png b/partner_identification_kyc/static/description/icon.png new file mode 100644 index 00000000000..1dcc49c24f3 Binary files /dev/null and b/partner_identification_kyc/static/description/icon.png differ diff --git a/partner_identification_kyc/static/description/index.html b/partner_identification_kyc/static/description/index.html new file mode 100644 index 00000000000..9908e792397 --- /dev/null +++ b/partner_identification_kyc/static/description/index.html @@ -0,0 +1,513 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Partner Identification KYC

+ +

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

+
+

Partner Identification KYC

+

This module adds Know Your Customer (KYC) identification functionality +to the partner identification automation system. It provides a +specialized KYC identification category with associated activities and +workflows to manage customer verification processes.

+

Table of contents

+
+
+

Installation

+
+

Installation

+

This module depends on partner_identification_automation_activity +which must be installed first. The module will automatically create the +KYC identification category and activity type during installation.

+
+
+
+

Configuration

+
+

Configuration

+
+

Identification Category

+

The module automatically creates a “KYC” identification category with +the following default settings:

+
    +
  • Initial Activity Type: “Perform KYC Check”
  • +
  • Renew Activity Type: “Perform KYC Check”
  • +
  • Create Activity on New: True
  • +
  • Default Validity: 1 year
  • +
  • Renewal Lead Number: 2
  • +
  • Renewal Lead Unit: Months
  • +
+
+
+

Activity Types

+

The module creates the “Perform KYC Check” activity type which is +assigned to both the initial and renewal activities for KYC +identification records.

+
+
+

Filters

+

A filter is added to the id_numbers views to allow filtering on the KYC +Category.

+
+
+
+
+

Usage

+
+

Usage

+
+

Request KYC Button

+

On the partner form, a “Request KYC” button will appear when:

+
    +
  • There is no KYC identification record in the ‘new’, ‘running’, or +‘to_renew’ states
  • +
  • OR there is no ID number record of the KYC category at all
  • +
+

The button will be hidden if:

+
    +
  • There is a ‘running’ or ‘to_renew’ KYC record
  • +
  • OR there is already a ‘new’ status KYC record (to prevent redundant +records)
  • +
+

Clicking the button will create a new KYC identification record in the +‘new’ status, triggering the associated activity for KYC officers to +process.

+
+
+

API Function

+

For partners created via API, there is a function to trigger the KYC +process automatically. If no KYC identification record exists for a +partner, calling this function will create a record in the ‘new’ status.

+
+
+
+

Activity Management

+

KYC identification records are associated with the “Perform KYC Check” +activity type, which appears in the activity views for tracking and +processing by responsible officers.

+
+
+
+

Changelog

+
+

[1.0.0] - 2025-01-01

+
+

Added

+
    +
  • Initial implementation of KYC identification category
  • +
  • “Request KYC” button on partner form
  • +
  • API function to trigger KYC flow for API-created partners
  • +
  • Dedicated “Perform KYC Check” activity type
  • +
  • Filters for KYC category in id_numbers views
  • +
+
+
+
+
+

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

+
+

Contributors

+
+

Contributors

+
    +
  • OCA Community
  • +
  • [Your Name/Company]
  • +
+
+
+
+

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/partner-contact project on GitHub.

+

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

+
+
+
+
+ + diff --git a/partner_identification_kyc/tests/__init__.py b/partner_identification_kyc/tests/__init__.py new file mode 100644 index 00000000000..ec8c19a195d --- /dev/null +++ b/partner_identification_kyc/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_identification_kyc diff --git a/partner_identification_kyc/tests/test_partner_identification_kyc.py b/partner_identification_kyc/tests/test_partner_identification_kyc.py new file mode 100644 index 00000000000..4785e626bbb --- /dev/null +++ b/partner_identification_kyc/tests/test_partner_identification_kyc.py @@ -0,0 +1,923 @@ +import odoo +from odoo import fields +from odoo.tests import common + + +@odoo.tests.tagged("post_install", "-at_install") +class TestPartnerIdentificationKYC(common.TransactionCase): + def setUp(self): + super().setUp() + + # Get the KYC category + self.kyc_category = self.env.ref( + "partner_identification_kyc.kyc_identification_category" + ) + + # Create a test partner + self.test_partner = self.env["res.partner"].create( + { + "name": "Test Partner for KYC", + "email": "test.kyc@example.com", + } + ) + + # Create a test issuer + self.test_issuer = self.env["res.partner"].create( + { + "name": "Test KYC Issuer", + "is_company": True, + } + ) + + def test_kyc_category_creation(self): + """Test that the KYC category was created with correct settings.""" + self.assertEqual(self.kyc_category.name, "KYC") + self.assertEqual(self.kyc_category.code, "KYC") + self.assertTrue(self.kyc_category.create_activity_on_new) + self.assertEqual(self.kyc_category.default_validity_number, 1) + self.assertEqual(self.kyc_category.default_validity_unit, "years") + self.assertEqual(self.kyc_category.renewal_lead_number, 2) + self.assertEqual(self.kyc_category.renewal_lead_unit, "months") + + # Check that activity types are set correctly + activity_type = self.env.ref( + "partner_identification_kyc.activity_type_kyc_check" + ) + self.assertEqual(self.kyc_category.initial_activity_type_id, activity_type) + self.assertEqual(self.kyc_category.renew_activity_type_id, activity_type) + + def test_action_request_kyc_creates_record(self): + """Test that the action_request_kyc creates a new KYC identification record.""" + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + # Call the action + self.test_partner.action_request_kyc() + + # Check that a new record was created + final_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(final_count, initial_count + 1) + + # Get the newly created record + new_record = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ], + order="create_date desc", + limit=1, + ) + + self.assertEqual(new_record.status, "draft") + self.assertTrue(new_record.name.startswith("KYC-")) + + def test_action_request_kyc_duplicate_prevention(self): + """Test that action_request_kyc prevents duplicates when a 'draft' record + already exists.""" + # Create the first KYC record + self.test_partner.action_request_kyc() + + # Verify the first record exists + records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ("status", "=", "draft"), + ] + ) + self.assertEqual(len(records), 1) + + # Try to create another record - should raise an error + with self.assertRaises(odoo.exceptions.UserError): + self.test_partner.action_request_kyc() + + def test_ensure_kyc_record_creates_when_none_exists(self): + """Test that ensure_kyc_record creates a record when none exists.""" + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + # Call the API function + self.test_partner.ensure_kyc_record() + + # Check that a new record was created + final_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(final_count, initial_count + 1) + + # Verify the status is 'draft' + new_record = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ], + order="create_date desc", + limit=1, + ) + + self.assertEqual(new_record.status, "draft") + + def test_ensure_kyc_record_no_duplicate_when_active_exists(self): + """Test that ensure_kyc_record does not create a record when an active one + already exists.""" + # Create the first record with 'draft' status (active) + self.test_partner.ensure_kyc_record() + + # Get the initial record + initial_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(len(initial_records), 1) + + # Call the API function again + self.test_partner.ensure_kyc_record() + + # Verify that no duplicate was created (still has only 1 active record) + final_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(len(final_records), 1) + + def test_ensure_kyc_record_creates_when_expired_exists(self): + """Test that ensure_kyc_record creates a record when only expired records + exist.""" + # Create an expired record + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-EXPIRED-TEST", + "status": "close", + } + ) + + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(initial_count, 1) + + # Call the API function - should create a new record since existing one is + # expired + self.test_partner.ensure_kyc_record() + + # Verify that a new record was created (now has 2 records total) + final_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(final_count, 2) + + def test_ensure_kyc_record_multiple_scenarios(self): + """Test ensure_kyc_record with different status scenarios.""" + test_partner_multi = self.env["res.partner"].create( + { + "name": "Test Partner Multi", + "email": "test.multi@example.com", + } + ) + + identification_model = self.env["res.partner.id_number"] + + # Scenario 1: Add a 'close' record, then ensure_kyc_record should create new one + identification_model.create( + { + "partner_id": test_partner_multi.id, + "category_id": self.kyc_category.id, + "name": "KYC-CLOSE-TEST", + "status": "close", + } + ) + + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", test_partner_multi.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(initial_count, 1) + + test_partner_multi.ensure_kyc_record() # Should create new record + count_after_ensure = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", test_partner_multi.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(count_after_ensure, 2) + + # Scenario 2: Add an 'open' record, then ensure_kyc_record should NOT create + # new one + test_partner_multi2 = self.env["res.partner"].create( + { + "name": "Test Partner Multi 2", + "email": "test.multi2@example.com", + } + ) + + identification_model.create( + { + "partner_id": test_partner_multi2.id, + "category_id": self.kyc_category.id, + "name": "KYC-OPEN-TEST", + "status": "open", + } + ) + + initial_count2 = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", test_partner_multi2.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(initial_count2, 1) + + test_partner_multi2.ensure_kyc_record() # Should NOT create new record + count_after_ensure2 = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", test_partner_multi2.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(count_after_ensure2, 1) + + def test_button_visibility_conditions(self): + """Test the visibility conditions for the Request KYC button.""" + # Initially, no KYC records exist, so button should be visible + # (This is tested indirectly by testing the functions that implement the logic) + + # Create a 'draft' status record + self.test_partner.action_request_kyc() + + # Now the button should be hidden (tested by trying to call the function + # and expect error) + with self.assertRaises(odoo.exceptions.UserError): + self.test_partner.action_request_kyc() + + # Create a running status record with a different partner for testing + partner2 = self.env["res.partner"].create( + { + "name": "Test Partner 2 for KYC", + "email": "test2.kyc@example.com", + } + ) + + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": partner2.id, + "category_id": self.kyc_category.id, + "name": "KYC-RUNNING-TEST", + "status": "open", + } + ) + + # With a running status, the button should be hidden + with self.assertRaises(odoo.exceptions.UserError): + partner2.action_request_kyc() + + def test_button_visibility_computed_field(self): + """Test the computed field show_kyc_button for different scenarios.""" + # Initially, no KYC records - button should be visible (show_kyc_button = True) + self.assertTrue(self.test_partner.show_kyc_button) + + # Create a draft status record - button should be hidden + self.test_partner.action_request_kyc() + # Reload the partner to get the updated computed field + self.test_partner.invalidate_recordset() + partner_reloaded = self.test_partner.browse(self.test_partner.id) + self.assertFalse(partner_reloaded.show_kyc_button) + + # Create a new partner with pending status - button should be hidden + partner_pending = self.env["res.partner"].create( + { + "name": "Test Partner Pending", + "email": "test.pending@example.com", + } + ) + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": partner_pending.id, + "category_id": self.kyc_category.id, + "name": "KYC-PENDING-TEST", + "status": "pending", + } + ) + partner_pending.invalidate_recordset() + partner_pending_reloaded = partner_pending.browse(partner_pending.id) + self.assertFalse(partner_pending_reloaded.show_kyc_button) + + # Create a new partner with close status - button should be visible + partner_close = self.env["res.partner"].create( + { + "name": "Test Partner Close", + "email": "test.close@example.com", + } + ) + identification_model.create( + { + "partner_id": partner_close.id, + "category_id": self.kyc_category.id, + "name": "KYC-CLOSE-TEST", + "status": "close", + } + ) + partner_close.invalidate_recordset() + partner_close_reloaded = partner_close.browse(partner_close.id) + self.assertTrue(partner_close_reloaded.show_kyc_button) + + def test_action_request_kyc_ensure_single_record(self): + """Test that action_request_kyc works correctly with single record.""" + # Test that the method properly calls ensure_one() + partners = self.test_partner | self.env["res.partner"].create( + { + "name": "Another Test Partner", + "email": "another.test@example.com", + } + ) + + # Calling the action on multiple records should raise an error + with self.assertRaises(ValueError): + partners.action_request_kyc() + + def test_ensure_kyc_record_idempotency(self): + """Test that ensure_kyc_record is idempotent when record exists.""" + # Call ensure_kyc_record multiple times - should not create duplicates + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + # First call - creates the record + self.test_partner.ensure_kyc_record() + + # Second call - should not create a duplicate + self.test_partner.ensure_kyc_record() + + final_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + # Should have created only one record + self.assertEqual(final_count, initial_count + 1) + + def test_multiple_status_scenarios_for_button_visibility(self): + """Test all possible status combinations for button visibility.""" + # Create a new partner to test various scenarios + test_partner_3 = self.env["res.partner"].create( + { + "name": "Test Partner 3", + "email": "test3@example.com", + } + ) + + # Initially, with no records, button should be visible + self.assertTrue(test_partner_3.show_kyc_button) + + # Test each status combination + + # Test with 'open' (Running) status only - button should be hidden + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": test_partner_3.id, + "category_id": self.kyc_category.id, + "name": "KYC-OPEN-TEST", + "status": "open", + } + ) + test_partner_3.invalidate_recordset() + reloaded_partner = test_partner_3.browse(test_partner_3.id) + self.assertFalse(reloaded_partner.show_kyc_button) + + # Clean up for next test + identification_model.search( + [ + ("partner_id", "=", test_partner_3.id), + ("category_id", "=", self.kyc_category.id), + ] + ).unlink() + + # Test with 'pending' (To Renew) status only - button should be hidden + identification_model.create( + { + "partner_id": test_partner_3.id, + "category_id": self.kyc_category.id, + "name": "KYC-PENDING-TEST", + "status": "pending", + } + ) + test_partner_3.invalidate_recordset() + reloaded_partner = test_partner_3.browse(test_partner_3.id) + self.assertFalse(reloaded_partner.show_kyc_button) + + # Clean up for next test + identification_model.search( + [ + ("partner_id", "=", test_partner_3.id), + ("category_id", "=", self.kyc_category.id), + ] + ).unlink() + + # Test with 'close' (Expired) status only - button should be visible + identification_model.create( + { + "partner_id": test_partner_3.id, + "category_id": self.kyc_category.id, + "name": "KYC-CLOSE-TEST", + "status": "close", + } + ) + test_partner_3.invalidate_recordset() + reloaded_partner = test_partner_3.browse(test_partner_3.id) + self.assertTrue(reloaded_partner.show_kyc_button) + + def test_kyc_valid_until_computed_field_with_valid_dates(self): + """Test the kyc_valid_until computed field when records have valid dates.""" + # Create KYC record with a valid_until date + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-WITH-DATE", + "status": "open", + "valid_until": "2025-12-31", # Set a future date + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should have a valid_until date + self.assertIsNotNone(reloaded_partner.kyc_valid_until) + self.assertEqual( + reloaded_partner.kyc_valid_until, fields.Date.from_string("2025-12-31") + ) + + def test_kyc_valid_until_computed_field_multiple_records(self): + """Test the kyc_valid_until computed field with multiple records + to get min date.""" + identification_model = self.env["res.partner.id_number"] + + # Create multiple KYC records with different valid_until dates + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-DATE1", + "status": "open", + "valid_until": "2025-12-31", # Later date + } + ) + + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-DATE2", + "status": "open", + "valid_until": "2025-06-15", # Earlier date - should be the min + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should have the minimum (earliest) valid_until date + self.assertIsNotNone(reloaded_partner.kyc_valid_until) + self.assertEqual( + reloaded_partner.kyc_valid_until, fields.Date.from_string("2025-06-15") + ) + + def test_kyc_valid_until_computed_field_no_open_records(self): + """Test the kyc_valid_until computed field when no open records exist.""" + # Create a KYC record but with 'draft' status (not 'open') + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-DRAFT", + "status": "draft", # Not 'open' status + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should be False since there are no 'open' status records + self.assertFalse(reloaded_partner.kyc_valid_until) + + def test_kyc_valid_until_computed_field_open_records_without_dates(self): + """Test the kyc_valid_until computed field when open records + have no valid_until dates.""" + identification_model = self.env["res.partner.id_number"] + + # Create KYC record with 'open' status but no valid_until date + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-NO-DATE", + "status": "open", # Open status but no valid_until + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should be False since there are no valid_until dates in open records + self.assertFalse(reloaded_partner.kyc_valid_until) + + def test_kyc_valid_until_computed_field_mixed_records(self): + """Test the kyc_valid_until computed field with mixed records + (some with dates, some without).""" + identification_model = self.env["res.partner.id_number"] + + # Create one record with valid_until and one without + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-WITH-DATE", + "status": "open", + "valid_until": "2025-12-31", + } + ) + + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-NO-DATE", + "status": "open", + # No valid_until field + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should have the valid_until from the record that has it + self.assertIsNotNone(reloaded_partner.kyc_valid_until) + self.assertEqual( + reloaded_partner.kyc_valid_until, fields.Date.from_string("2025-12-31") + ) + + def test_show_kyc_button_with_company_partner(self): + """Test show_kyc_button computed field with company partner + when child contacts disabled.""" + # First, disable child contacts on the KYC category + self.kyc_category.enable_on_child_contacts = False + + # Create a company partner (should still be able to see button + # regardless of enable_on_child_contacts) + company_partner = self.env["res.partner"].create( + { + "name": "Company Partner", + "email": "company@example.com", + "is_company": True, # Is a company + } + ) + + # The button should be visible for companies even when + # enable_on_child_contacts is False + company_partner.invalidate_recordset() + reloaded_company = company_partner.browse(company_partner.id) + self.assertTrue(reloaded_company.show_kyc_button) + + def test_button_visibility_computed_field_with_disabled_child_contacts(self): + """Test the computed field show_kyc_button when child contacts are disabled.""" + # First, disable child contacts on the KYC category + self.kyc_category.enable_on_child_contacts = False + + # Create a non-company partner (individual contact) + individual_contact = self.env["res.partner"].create( + { + "name": "Individual Contact", + "email": "individual@example.com", + "is_company": False, # Not a company + } + ) + + # The button should be hidden for individual contacts when + # enable_on_child_contacts is False + individual_contact.invalidate_recordset() + reloaded_contact = individual_contact.browse(individual_contact.id) + self.assertFalse(reloaded_contact.show_kyc_button) + + def test_button_visibility_computed_field_with_enabled_child_contacts(self): + """Test the computed field show_kyc_button when child contacts are enabled.""" + # Ensure child contacts are enabled on the KYC category (default) + self.kyc_category.enable_on_child_contacts = True + + # Create a non-company partner (individual contact) + individual_contact = self.env["res.partner"].create( + { + "name": "Individual Contact", + "email": "individual@example.com", + "is_company": False, # Not a company + } + ) + + # The button should be visible for individual contacts when + # enable_on_child_contacts is True + individual_contact.invalidate_recordset() + reloaded_contact = individual_contact.browse(individual_contact.id) + self.assertTrue(reloaded_contact.show_kyc_button) + + def test_kyc_valid_until_computed_field_empty_sequence_edge_case(self): + """Test that kyc_valid_until doesn't fail when open records exist + but none have valid_until.""" + # Create multiple open records without valid_until dates + # to test the min() edge case + identification_model = self.env["res.partner.id_number"] + + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-NO-DATE-1", + "status": "open", + # No valid_until + } + ) + + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-TEST-NO-DATE-2", + "status": "open", + # No valid_until + } + ) + + # This should not raise an error and should return False + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should be False since no records have valid_until dates + self.assertFalse(reloaded_partner.kyc_valid_until) + + def test_action_request_kyc_with_custom_sequence(self): + """Test action_request_kyc creates record with proper sequence.""" + # Remove any existing KYC records first + existing_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + existing_records.unlink() + + # Call action_request_kyc + self.test_partner.action_request_kyc() + + # Check that a record was created + kyc_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(len(kyc_records), 1) + self.assertEqual(kyc_records[0].status, "draft") + self.assertTrue(kyc_records[0].name.startswith("KYC-")) + + def test_ensure_kyc_record_when_none_exist(self): + """Test ensure_kyc_record creates record when none exists.""" + # Remove any existing KYC records first + existing_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + existing_records.unlink() + + # Call ensure_kyc_record + self.test_partner.ensure_kyc_record() + + # Check that a record was created + kyc_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(len(kyc_records), 1) + self.assertEqual(kyc_records[0].status, "draft") + + def test_ensure_kyc_record_when_exists_with_active_status(self): + """Test ensure_kyc_record does nothing when active record exists.""" + # Create an existing 'open' status record + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-EXISTING-TEST", + "status": "open", + } + ) + + # Count existing records + initial_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + # Call ensure_kyc_record - should not create a new record + self.test_partner.ensure_kyc_record() + + # Count should remain the same + final_count = self.env["res.partner.id_number"].search_count( + [ + ("partner_id", "=", self.test_partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + + self.assertEqual(initial_count, final_count) + + def test_action_view_kyc_records(self): + """Test action_view_kyc_records returns proper action.""" + # Create a KYC record first + identification_model = self.env["res.partner.id_number"] + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-VIEW-TEST", + "status": "open", + } + ) + + # Call action_view_kyc_records + action = self.test_partner.action_view_kyc_records() + + # Check the action structure + self.assertEqual(action["type"], "ir.actions.act_window") + self.assertEqual(action["res_model"], "res.partner.id_number") + self.assertIn("domain", action) + + # Check that domain contains partner_id filter + domain_has_partner = any( + isinstance(d, (list, tuple)) + and len(d) >= 3 + and d[0] == "partner_id" + and d[1] == "=" + and d[2] == self.test_partner.id + for d in action["domain"] + ) + self.assertTrue(domain_has_partner) + + def test_kyc_valid_until_with_expired_and_active_records(self): + """Test kyc_valid_until with mix of expired and active records.""" + identification_model = self.env["res.partner.id_number"] + + # Create an expired record (close status) with a date + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-EXPIRED-TEST", + "status": "close", # Not 'open' status, should be ignored + "valid_until": "2020-01-01", # Past date + } + ) + + # Create an open record with a future date + identification_model.create( + { + "partner_id": self.test_partner.id, + "category_id": self.kyc_category.id, + "name": "KYC-ACTIVE-TEST", + "status": "open", # This one should be considered + "valid_until": "2025-12-31", # Future date + } + ) + + # Reload partner to get updated computed field + self.test_partner.invalidate_recordset() + reloaded_partner = self.test_partner.browse(self.test_partner.id) + + # Should only consider 'open' status records + self.assertIsNotNone(reloaded_partner.kyc_valid_until) + expected_date = fields.Date.from_string("2025-12-31") + self.assertEqual(reloaded_partner.kyc_valid_until, expected_date) + + def test_button_visibility_with_multiple_partners(self): + """Test show_kyc_button computed field with multiple partners at once.""" + # Create multiple partners + partner1 = self.env["res.partner"].create( + { + "name": "Partner 1", + "email": "partner1@example.com", + } + ) + + partner2 = self.env["res.partner"].create( + { + "name": "Partner 2", + "email": "partner2@example.com", + } + ) + + # Get multiple partners at once to test computed field batch processing + partners = partner1 | partner2 + + # All should have button visible initially (no KYC records) + partners.invalidate_recordset() + for partner in partners: + self.assertTrue(partner.show_kyc_button) + + def test_ensure_kyc_record_batch_processing(self): + """Test ensure_kyc_record works with multiple partners.""" + # Create multiple partners + partner1 = self.env["res.partner"].create( + { + "name": "Batch Partner 1", + "email": "batch1@example.com", + } + ) + + partner2 = self.env["res.partner"].create( + { + "name": "Batch Partner 2", + "email": "batch2@example.com", + } + ) + + # Remove any existing KYC records for these partners + existing_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "in", [partner1.id, partner2.id]), + ("category_id", "=", self.kyc_category.id), + ] + ) + existing_records.unlink() + + # Apply ensure_kyc_record to multiple partners at once + partners = partner1 | partner2 + partners.ensure_kyc_record() + + # Each partner should now have a KYC record + for partner in partners: + partner_records = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", partner.id), + ("category_id", "=", self.kyc_category.id), + ] + ) + self.assertEqual(len(partner_records), 1) + self.assertEqual(partner_records[0].status, "draft") diff --git a/partner_identification_kyc/views/identification_number_views.xml b/partner_identification_kyc/views/identification_number_views.xml new file mode 100644 index 00000000000..8e44bd6d09b --- /dev/null +++ b/partner_identification_kyc/views/identification_number_views.xml @@ -0,0 +1,18 @@ + + + + + res.partner.id_number.kyc.filter + res.partner.id_number + + + + + + + + diff --git a/partner_identification_kyc/views/res_partner_id_category_view.xml b/partner_identification_kyc/views/res_partner_id_category_view.xml new file mode 100644 index 00000000000..b5eabf10bad --- /dev/null +++ b/partner_identification_kyc/views/res_partner_id_category_view.xml @@ -0,0 +1,16 @@ + + + + res.partner.id_category.form.kyc + res.partner.id_category + + + + + + + + diff --git a/partner_identification_kyc/views/res_partner_views.xml b/partner_identification_kyc/views/res_partner_views.xml new file mode 100644 index 00000000000..8a26e1844c0 --- /dev/null +++ b/partner_identification_kyc/views/res_partner_views.xml @@ -0,0 +1,39 @@ + + + + + res.partner.form.kyc + res.partner + + + + + + +
+
+
+
+
+
diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..e48f3526a30 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +odoo-addon-partner-identification-automation @ git+https://github.com/OCA/partner-contact.git@refs/pull/2224/head#subdirectory=partner_identification_automation +odoo-addon-partner-identification-automation-activity @ git+https://github.com/OCA/partner-contact.git@refs/pull/2225/head#subdirectory=partner_identification_automation_activity