diff --git a/partner_telegram/README.rst b/partner_telegram/README.rst new file mode 100644 index 00000000..7404d7fe --- /dev/null +++ b/partner_telegram/README.rst @@ -0,0 +1,11 @@ +# Telegram Contact Field + +.. image:: static/description/icon.png + +This module adds telegram fields to the partner form: ``__. + +It works similarly to the `email` widget and opens the Telegram app when clicking the Telegram icon. + +The Telegram value can be either a username or a mobile phone number prefixed with `+`. + +An additional field, `telegram_ID`, is used for technical purposes and doesn't affect the partner form. diff --git a/partner_telegram/__init__.py b/partner_telegram/__init__.py new file mode 100644 index 00000000..3ed6cbbe --- /dev/null +++ b/partner_telegram/__init__.py @@ -0,0 +1,2 @@ +# License MIT (https://opensource.org/licenses/MIT). +from . import models diff --git a/partner_telegram/__manifest__.py b/partner_telegram/__manifest__.py new file mode 100644 index 00000000..77654a19 --- /dev/null +++ b/partner_telegram/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2024 Ivan Yelizariev +# License MIT (https://opensource.org/licenses/MIT). + +{ + "name": "Telegram Contact Field", + "summary": """Join the Amazing 😍 Community ⤵️""", + "category": "VooDoo ✨ Magic", + "version": "16.0.1.0.0", + "author": "Ivan Kropotkin", + "support": "info@odoomagic.com", + "website": "https://sync_studio.t.me/", + "license": "Other OSI approved licence", # MIT + "data": [ + "views/res_partner_views.xml", + ], + "assets": { + "web.assets_backend": [ + "partner_telegram/static/src/js/telegram_widget.js", + "partner_telegram/static/src/xml/telegram_widget.xml", + "partner_telegram/static/src/scss/telegram_widget.scss", + ], + }, + "installable": True, +} diff --git a/partner_telegram/doc/changelog.rst b/partner_telegram/doc/changelog.rst new file mode 100644 index 00000000..5583eb32 --- /dev/null +++ b/partner_telegram/doc/changelog.rst @@ -0,0 +1,4 @@ +`1.0.0` +------- + +- **Init version** diff --git a/partner_telegram/models/__init__.py b/partner_telegram/models/__init__.py new file mode 100644 index 00000000..03956d53 --- /dev/null +++ b/partner_telegram/models/__init__.py @@ -0,0 +1,2 @@ +# License MIT (https://opensource.org/licenses/MIT). +from . import res_partner diff --git a/partner_telegram/models/res_partner.py b/partner_telegram/models/res_partner.py new file mode 100644 index 00000000..461b7758 --- /dev/null +++ b/partner_telegram/models/res_partner.py @@ -0,0 +1,38 @@ +# Copyright 2024 Ivan Yelizariev + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + telegram_ID = fields.Char() + telegram = fields.Char( + string="Telegram", compute="_compute_telegram", inverse="_inverse_telegram" + ) + telegram_username = fields.Char() + telegram_mobile = fields.Char() + telegram_url = fields.Char(compute="_compute_telegram") + + @api.depends("telegram_username", "telegram_mobile") + def _compute_telegram(self): + for record in self: + if record.telegram_username: + record.telegram_url = f"https://t.me/{record.telegram_username}" + record.telegram = record.telegram_username + elif record.telegram_mobile: + record.telegram_url = f"https://t.me/{record.telegram_mobile}" + record.telegram = record.telegram_mobile + else: + record.telegram_url = "" + + def _inverse_telegram(self): + for record in self: + value = record.telegram + if value.startswith("@"): + value = value[1:] + elif value.startswith("+"): + value = value.replace("-", "").replace(" ", "") + elif value.startswith("https://t.me/"): + value = value[len("https://t.me/") :] + record.telegram_mobile = value diff --git a/partner_telegram/static/description/icon.png b/partner_telegram/static/description/icon.png new file mode 100644 index 00000000..7f0fb65c Binary files /dev/null and b/partner_telegram/static/description/icon.png differ diff --git a/partner_telegram/static/src/js/telegram_widget.js b/partner_telegram/static/src/js/telegram_widget.js new file mode 100644 index 00000000..96b711fc --- /dev/null +++ b/partner_telegram/static/src/js/telegram_widget.js @@ -0,0 +1,15 @@ +/** @odoo-module **/ +/** Copyright 2024 Ivan Yelizariev **/ + +import { EmailField } from "@web/views/fields/email/email_field"; +import { registry } from "@web/core/registry"; + +class TelegramField extends EmailField {} + +TelegramField.template = "partner_contact.TelegramField"; + +class FormTelegramField extends TelegramField {} +FormTelegramField.template = "partner_contact.FormTelegramField"; + +registry.category("fields").add("telegram", TelegramField); +registry.category("fields").add("form.telegram", FormTelegramField); diff --git a/partner_telegram/static/src/scss/telegram_widget.scss b/partner_telegram/static/src/scss/telegram_widget.scss new file mode 100644 index 00000000..d317bffc --- /dev/null +++ b/partner_telegram/static/src/scss/telegram_widget.scss @@ -0,0 +1,7 @@ +body:not(.o_touch_device) .o_field_telegram { + &:not(:hover):not(:focus-within) { + & input:not(:hover) ~ a { + display: none !important; + } + } +} diff --git a/partner_telegram/static/src/xml/telegram_widget.xml b/partner_telegram/static/src/xml/telegram_widget.xml new file mode 100644 index 00000000..1890ccbf --- /dev/null +++ b/partner_telegram/static/src/xml/telegram_widget.xml @@ -0,0 +1,49 @@ + + + + + +
+ +
+
+ +
+ +
+
+
+ + + + + + + +
diff --git a/partner_telegram/views/res_partner_views.xml b/partner_telegram/views/res_partner_views.xml new file mode 100644 index 00000000..0375b61d --- /dev/null +++ b/partner_telegram/views/res_partner_views.xml @@ -0,0 +1,17 @@ + + + + + res.partner.form.telegram + res.partner + + + + + + + + + + diff --git a/setup/partner_telegram/odoo/addons/partner_telegram b/setup/partner_telegram/odoo/addons/partner_telegram new file mode 120000 index 00000000..ea7e5345 --- /dev/null +++ b/setup/partner_telegram/odoo/addons/partner_telegram @@ -0,0 +1 @@ +../../../../partner_telegram \ No newline at end of file diff --git a/setup/partner_telegram/setup.py b/setup/partner_telegram/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/partner_telegram/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)