-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da6f707
commit 6e39e22
Showing
13 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Telegram Contact Field | ||
|
||
.. image:: static/description/icon.png | ||
|
||
This module adds `telegram fields<models/res_partner.py>`_ 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License MIT (https://opensource.org/licenses/MIT). | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 Ivan Yelizariev <https://twitter.com/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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
`1.0.0` | ||
------- | ||
|
||
- **Init version** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License MIT (https://opensource.org/licenses/MIT). | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2024 Ivan Yelizariev <https://twitter.com/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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** @odoo-module **/ | ||
/** Copyright 2024 Ivan Yelizariev <https://twitter.com/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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
body:not(.o_touch_device) .o_field_telegram { | ||
&:not(:hover):not(:focus-within) { | ||
& input:not(:hover) ~ a { | ||
display: none !important; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev> | ||
License MIT (https://opensource.org/licenses/MIT). --> | ||
<templates xml:space="preserve"> | ||
<t t-name="partner_contact.TelegramField" owl="1"> | ||
<t t-if="props.readonly"> | ||
<div class="d-grid"> | ||
<a | ||
class="o_form_uri o_text_overflow" | ||
t-on-click.stop="" | ||
t-att-href="props.record.data.telegram_url" | ||
t-esc="props.value || ''" | ||
/> | ||
</div> | ||
</t> | ||
<t t-else=""> | ||
<div class="d-inline-flex w-100"> | ||
<input | ||
class="o_input" | ||
t-att-id="props.id" | ||
type="text" | ||
autocomplete="off" | ||
t-att-placeholder="props.placeholder" | ||
t-att-required="props.required" | ||
t-ref="input" | ||
/> | ||
</div> | ||
</t> | ||
</t> | ||
<t | ||
t-name="partner_contact.FormTelegramField" | ||
t-inherit="partner_contact.TelegramField" | ||
t-inherit-mode="primary" | ||
> | ||
<xpath expr="//input" position="after"> | ||
<a | ||
t-if="props.value" | ||
t-att-href="props.record.data.telegram_url" | ||
class="ms-3 d-inline-flex align-items-center" | ||
> | ||
<i | ||
class="fa fa-telegram" | ||
data-tooltip="Open in Telegram" | ||
aria-label="Open in Telegram" | ||
/> | ||
</a> | ||
</xpath> | ||
</t> | ||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev> | ||
License MIT (https://opensource.org/licenses/MIT). --> | ||
<odoo> | ||
<record id="view_res_partner_form_telegram" model="ir.ui.view"> | ||
<field name="name">res.partner.form.telegram</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='website']" position="before"> | ||
<field name="telegram" widget="telegram" /> | ||
<field name="telegram_url" invisible="1" /> | ||
<field name="telegram_username" invisible="1" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../partner_telegram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |