Skip to content

Commit

Permalink
[MIG] base_phone: Migrated to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikul-OSI committed Feb 12, 2024
1 parent 6a1e1bc commit 1669387
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 210 deletions.
1 change: 1 addition & 0 deletions base_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Contributors

- Alexis de Lattre <[email protected]>
- Sébastien Beau <[email protected]>
- Nikul Chaudhary [email protected]

Maintainers
-----------
Expand Down
6 changes: 5 additions & 1 deletion base_phone/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
"views/res_users_view.xml",
"wizard/reformat_all_phonenumbers_view.xml",
"wizard/number_not_found_view.xml",
"views/web_phone.xml",
],
"assets": {
"web.assets_backend": [
"base_phone/static/src/**/*",
],
},
"qweb": ["static/src/xml/phone.xml"],
"installable": True,
}
2 changes: 1 addition & 1 deletion base_phone/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import phone_validation_mixin
from . import models
from . import res_company
from . import res_partner
from . import phone_common
21 changes: 21 additions & 0 deletions base_phone/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018-2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import models


class BaseModel(models.AbstractModel):
_inherit = "base"

def _phone_format_number(
self, number, country, force_format="E164", raise_exception=False
):
if "country_id" in self and self.country_id:
country = self.country_id
if "partner_id" in self and self.partner_id and self.partner_id.country_id:
country = self.partner_id.country_id
return super()._phone_format_number(
number, country, force_format, raise_exception
)
5 changes: 2 additions & 3 deletions base_phone/models/phone_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def get_name_from_phone_number(self, presented_number):
res = self.get_record_from_phone_number(presented_number)
if res:
return res[2]
else:
return False
return False

@api.model
def get_record_from_phone_number(self, presented_number):
Expand Down Expand Up @@ -93,7 +92,7 @@ def get_record_from_phone_number(self, presented_number):
res_obj = obj.browse(obj_id)
# Use name_get()[0][1] instead of display_name
# to take the context into account with the callerid key
name = res_obj.name_get()[0][1]
name = res_obj.display_name
res = (obj._name, res_obj.id, name)
_logger.debug(
"Answer get_record_from_phone_number: (%s, %d, %s)",
Expand Down
17 changes: 0 additions & 17 deletions base_phone/models/phone_validation_mixin.py

This file was deleted.

15 changes: 4 additions & 11 deletions base_phone/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@


class ResPartner(models.Model):
_name = "res.partner"
# inherit on phone.validation.mixin (same as in crm_phone_validation,
# but base_phone only depends on phone_validation,
# not on crm_phone_validation)
_inherit = ["res.partner", "phone.validation.mixin"]
_inherit = "res.partner"
_phone_name_sequence = 10
_phone_name_fields = ["phone", "mobile"]

def name_get(self):
def _compute_display_name(self):
super()._compute_display_name()
if self._context.get("callerid"):
res = []
for partner in self:
if partner.parent_id and partner.parent_id.is_company:
name = f"{partner.parent_id.name}, {partner.name}"
else:
name = partner.name
res.append((partner.id, name))
return res
else:
return super().name_get()
partner.display_name = name.strip()
3 changes: 3 additions & 0 deletions base_phone/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions base_phone/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Alexis de Lattre \<<[email protected]>\>
- Sébastien Beau \<<[email protected]>\>
- Nikul Chaudhary \<<[email protected]>\>
14 changes: 14 additions & 0 deletions base_phone/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This module provides common methods and wizards which can be useful to
develop a connector between Odoo and a telephony system. It depends on
the official module *phone_validation* which handle the reformatting of
phone numbers using the
[phonenumbers](https://github.com/daviddrysdale/python-phonenumbers)
Python library, which is a port of the library used in Android
smartphones. For example, if your user is linked to a French company and
you update the form view of a partner with a badly written French phone
number such as '01-55-42-12-42', Odoo will automatically update the
phone number to [E.164](https://en.wikipedia.org/wiki/E.164) format
'+33155421242'. This module extends this reformatting to create() and
write() methods.

This module is used by the Odoo-Asterisk connector of the OCA.
1 change: 1 addition & 0 deletions base_phone/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Alexis de Lattre &lt;<a class="reference external" href="mailto:alexis.delattre&#64;akretion.com">alexis.delattre&#64;akretion.com</a>&gt;</li>
<li>Sébastien Beau &lt;<a class="reference external" href="mailto:sebastien.beau&#64;akretion.com">sebastien.beau&#64;akretion.com</a>&gt;</li>
<li>Nikul Chaudhary <a class="reference external" href="mailto:nchaudhary&#64;opensourceintegrators.com">nchaudhary&#64;opensourceintegrators.com</a></li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
220 changes: 116 additions & 104 deletions base_phone/static/src/js/phone_widget.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,122 @@
/** @odoo-module **/

/* Base phone module for Odoo
Copyright (C) 2013-2018 Akretion France
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */

odoo.define("base_phone.updatedphone_widget", function (require) {
"use strict";

var core = require("web.core");
var FieldPhone = require("web.basic_fields").FieldPhone;
var _t = core._t;

FieldPhone.include({
/* Always enable phone link tel:, not only on small screens */
_canCall: function () {
return true;
},
showDialButton: function () {
// Must be inherited by ipbx specific modules
// and set to true
return false;
},

_renderReadonly: function () {
// Create a link to trigger action on server
// this link will be after the <a href="tel:">
this._super();

if (!this.showDialButton()) {
return;
}
var self = this;

// Create our link
var dial = $(
'<a href="javascript:void(0)" class="dial"><div class="label label-primary">☎ Dial</div></a>'
);

// Add a parent element
// it's not possible to append to $el directly
// because $el don't have any parent yet
var parent = $("<div>");
parent.append([this.$el[0], " ", dial]);

// Replace this.$el by our new container
this.$el = parent;

var phone_num = this.value;
/* eslint-disable no-unused-vars */
dial.click(function (evt) {
self.click2dial(phone_num);
});
/* eslint-enable no-unused-vars */
},
click2dial: function (phone_num) {
var self = this;
this.do_notify(
_.str.sprintf(_t("Click2dial to %s"), phone_num),
_t("Unhook your ringing phone"),
false
);
var params = {
phone_number: phone_num,
click2dial_model: this.model,
click2dial_id: this.res_id,
};
return this._rpc({
model: "phone.common",
context: params,
method: "click2dial",
args: [phone_num],
}).then(
/* eslint-disable no-unused-vars */
function (r) {
console.log("successfull", r);
if (r === false) {
self.do_warn("Click2dial failed");
} else if (typeof r === "object") {
self.do_notify(
_t("Click2dial successfull"),
_.str.sprintf(_t("Number dialed: %s"), r.dialed_number),
false
);
if (r.action_model) {
var action = {
name: r.action_name,
type: "ir.actions.act_window",
res_model: r.action_model,
view_mode: "form",
views: [[false, "form"]],
target: "new",
context: params,
};
return self.do_action(action);
}
}
},
function (r) {
console.log("on error");
self.do_warn("Click2dial failed");
}
/* eslint-enable no-unused-vars */
);
},
});
import {registry} from "@web/core/registry";
import {_t} from "@web/core/l10n/translation";
import {
PhoneField,
phoneField,
formPhoneField,
} from "@web/views/fields/phone/phone_field";
import {patch} from "@web/core/utils/patch";
import {Component, useRef, useState, onMounted} from "@odoo/owl";

return {
FieldPhone: FieldPhone,
};
});
//odoo.define("base_phone.updatedphone_widget", function (require) {
// "use strict";
//
// var core = require("web.core");
// var FieldPhone = require("web.basic_fields").FieldPhone;
// var _t = core._t;
//
// FieldPhone.include({
// /* Always enable phone link tel:, not only on small screens */
// _canCall: function () {
// return true;
// },
// showDialButton: function () {
// // Must be inherited by ipbx specific modules
// // and set to true
// return false;
// },
//
// _renderReadonly: function () {
// // Create a link to trigger action on server
// // this link will be after the <a href="tel:">
// this._super();
//
// if (!this.showDialButton()) {
// return;
// }
// var self = this;
//
// // Create our link
// var dial = $(
// '<a href="javascript:void(0)" class="dial"><div class="label label-primary">☎ Dial</div></a>'
// );
//
// // Add a parent element
// // it's not possible to append to $el directly
// // because $el don't have any parent yet
// var parent = $("<div>");
// parent.append([this.$el[0], " ", dial]);
//
// // Replace this.$el by our new container
// this.$el = parent;
//
// var phone_num = this.value;
// /* eslint-disable no-unused-vars */
// dial.click(function (evt) {
// self.click2dial(phone_num);
// });
// /* eslint-enable no-unused-vars */
// },
// click2dial: function (phone_num) {
// var self = this;
// this.do_notify(
// _.str.sprintf(_t("Click2dial to %s"), phone_num),
// _t("Unhook your ringing phone"),
// false
// );
// var params = {
// phone_number: phone_num,
// click2dial_model: this.model,
// click2dial_id: this.res_id,
// };
// return this._rpc({
// model: "phone.common",
// context: params,
// method: "click2dial",
// args: [phone_num],
// }).then(
// /* eslint-disable no-unused-vars */
// function (r) {
// console.log("successfull", r);
// if (r === false) {
// self.do_warn("Click2dial failed");
// } else if (typeof r === "object") {
// self.do_notify(
// _t("Click2dial successfull"),
// _.str.sprintf(_t("Number dialed: %s"), r.dialed_number),
// false
// );
// if (r.action_model) {
// var action = {
// name: r.action_name,
// type: "ir.actions.act_window",
// res_model: r.action_model,
// view_mode: "form",
// views: [[false, "form"]],
// target: "new",
// context: params,
// };
// return self.do_action(action);
// }
// }
// },
// function (r) {
// console.log("on error");
// self.do_warn("Click2dial failed");
// }
// /* eslint-enable no-unused-vars */
// );
// },
// });
//
// return {
// FieldPhone: FieldPhone,
// };
//});
4 changes: 2 additions & 2 deletions base_phone/static/src/xml/phone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<templates>
<t t-name="base_phone.dial">
<templates xml:space="preserve">
<t t-name="base_phone.dial" owl="1">
<span class="float-right">
<a
href="#"
Expand Down
4 changes: 1 addition & 3 deletions base_phone/tests/test_base_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def test_lookup(self):
self.assertIsInstance(res, tuple)
self.assertEqual(res[0], "res.partner")
self.assertEqual(res[1], self.akretion.id)
self.assertEqual(
res[2], self.akretion.with_context(callerid=True).name_get()[0][1]
)
self.assertEqual(res[2], self.akretion.with_context(callerid=True).display_name)
res = self.phco.get_record_from_phone_number("0499889988")
self.assertFalse(res)

Expand Down
Loading

0 comments on commit 1669387

Please sign in to comment.