-
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 13ca571
Showing
11 changed files
with
144 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,3 @@ | ||
# WIP | ||
|
||
TODO: we can't open telegram contact by url if we have Telegram ID only |
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,23 @@ | ||
# 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": "[email protected]", | ||
"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", | ||
], | ||
}, | ||
"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,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,21 @@ | ||
# Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev> | ||
import re | ||
|
||
from odoo import _, api, exceptions, fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
telegram = fields.Char(string="Telegram") | ||
|
||
@api.constrains("telegram") | ||
def _check_telegram_format(self): | ||
telegram_format = re.compile(r"^(\d+|@\w+)$") | ||
for record in self: | ||
if record.telegram and not telegram_format.match(record.telegram): | ||
raise exceptions.ValidationError( | ||
_( | ||
"Telegram contact must be a number (ID) or a string prefixed with '@' (username)." | ||
) | ||
) |
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,22 @@ | ||
/** @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 { | ||
_formatValue(value) { | ||
if (value.startsWith("@")) { | ||
return `https://t.me/${value.substring(1)}`; | ||
} | ||
return `tg://user?id=${value}`; | ||
} | ||
} | ||
|
||
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,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.value ? 'https://t.me/'+props.value.substring(1) : undefined" | ||
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="'https://t.me/'+props.value.substring(1)" | ||
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,15 @@ | ||
<?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" /> | ||
</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, | ||
) |