Skip to content

Commit

Permalink
Merge pull request #303 from itpp-labs/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream itpp-labs/sync-addons (17.0)
  • Loading branch information
bt-admin authored Feb 26, 2025
2 parents 90e7d56 + f13a1d8 commit 80abef6
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/DINAR-PORT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
path: REPO
fetch-depth: 0
ref: ${{ env.PORT_TO_BRANCH }}
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/DINAR-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run:
echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
run:
echo "PY=$(python --version --version | sha256sum | cut -d' ' -f1)" >>
$GITHUB_ENV
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('REPO/.pre-commit-config.yaml') }}
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
echo "${{ env.PR_MODULES_DEPS }}" > new-deps/modules.txt
echo "ARTIFACT=yes" >> $GITHUB_ENV
- name: Save DINAR with dependencies
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: new-deps
path: new-deps/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude: |
# Maybe reactivate this when all README files include prettier ignore tags?
^README\.md$|
# Library files can have extraneous formatting (even minimized)
/static/(src/)?lib/|
/lib/|
# Repos using Sphinx to generate docs don't need prettying
^docs/_templates/.*\.html$|
# You don't usually want a bot to modify your legal texts
Expand Down
11 changes: 11 additions & 0 deletions partner_telegram/README.rst
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 to the partner form: `<models/res_partner.py>`__.

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.
2 changes: 2 additions & 0 deletions partner_telegram/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License MIT (https://opensource.org/licenses/MIT).
from . import models
24 changes: 24 additions & 0 deletions partner_telegram/__manifest__.py
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": "17.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",
"partner_telegram/static/src/scss/telegram_widget.scss",
],
},
"installable": True,
}
4 changes: 4 additions & 0 deletions partner_telegram/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**
2 changes: 2 additions & 0 deletions partner_telegram/models/__init__.py
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
40 changes: 40 additions & 0 deletions partner_telegram/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 not value:
record.telegram_username = False
record.telegram_mobile = False
elif value.startswith("@"):
record.telegram_username = value[1:]
elif value.startswith("https://t.me/"):
record.telegram_username = value[len("https://t.me/") :]
elif value.startswith("+"):
record.telegram_mobile = value.replace("-", "").replace(" ", "")
Binary file added partner_telegram/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions partner_telegram/static/src/js/telegram_widget.js
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);
7 changes: 7 additions & 0 deletions partner_telegram/static/src/scss/telegram_widget.scss
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;
}
}
}
49 changes: 49 additions & 0 deletions partner_telegram/static/src/xml/telegram_widget.xml
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>
2 changes: 2 additions & 0 deletions partner_telegram/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License MIT (https://opensource.org/licenses/MIT).
from . import test_telegram
49 changes: 49 additions & 0 deletions partner_telegram/tests/test_telegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2024 Ivan Yelizariev <https://twitter.com/yelizariev>
# License MIT (https://opensource.org/licenses/MIT).
from odoo.tests.common import TransactionCase


class TestResPartnerTelegram(TransactionCase):
def setUp(self):
super(TestResPartnerTelegram, self).setUp()
self.ResPartner = self.env["res.partner"]
# Create a partner without telegram information
self.partner = self.ResPartner.create({"name": "Test"})

def test_telegram_set_username(self):
# Set the telegram field with a username
self.partner.telegram = "@testuser"

# Check the computed fields
self.assertEqual(self.partner.telegram_username, "testuser")
self.assertEqual(self.partner.telegram_url, "https://t.me/testuser")
self.assertEqual(self.partner.telegram, "testuser")

def test_telegram_set_mobile(self):
# Set the telegram field with a mobile number
self.partner.telegram = "+1234567890"

# Check the computed fields
self.assertEqual(self.partner.telegram_mobile, "+1234567890")
self.assertEqual(self.partner.telegram_url, "https://t.me/+1234567890")
self.assertEqual(self.partner.telegram, "+1234567890")

def test_telegram_set_url(self):
# Set the telegram field with a URL
self.partner.telegram = "https://t.me/testuser"

# Check the computed fields
self.assertEqual(self.partner.telegram_username, "testuser")
self.assertEqual(self.partner.telegram_url, "https://t.me/testuser")
self.assertEqual(self.partner.telegram, "testuser")

def test_telegram_clear(self):
# Set the telegram field and then clear it
self.partner.telegram = "@testuser"
self.partner.telegram = ""

# Check the computed fields
self.assertFalse(self.partner.telegram_username)
self.assertFalse(self.partner.telegram_mobile)
self.assertFalse(self.partner.telegram_url)
self.assertFalse(self.partner.telegram)
17 changes: 17 additions & 0 deletions partner_telegram/views/res_partner_views.xml
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>

0 comments on commit 80abef6

Please sign in to comment.