Skip to content

Commit

Permalink
[MIG] base_phone_cdr
Browse files Browse the repository at this point in the history
  • Loading branch information
murtuzasaleh committed Feb 14, 2024
1 parent 25851c5 commit e877744
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 28 deletions.
68 changes: 63 additions & 5 deletions base_phone_cdr/README.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,77 @@
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:alt: License LGPL-3

==============
Base Phone CDR
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ec510c031dcf39f8614be3fdcaae8d6837177255ccd70c3dc3f275c44145a2ff
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github
:target: https://github.com/OCA/connector-telephony/tree/17.0/base_phone_cdr
:alt: OCA/connector-telephony
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/connector-telephony-17-0/connector-telephony-17-0-base_phone_cdr
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds Phone CDR.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-telephony/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/connector-telephony/issues/new?body=module:%20base_phone_cdr%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Open Source Integrators

Contributors
------------

* Chanakya Soni <[email protected]>
* Daniel Reis <[email protected]>
- * Chanakya Soni <[email protected]>
- * Daniel Reis <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/connector-telephony <https://github.com/OCA/connector-telephony/tree/17.0/base_phone_cdr>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion base_phone_cdr/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
"view/res_users_view.xml",
"view/res_partner_view.xml",
],
"qweb": ["static/src/xml/widget.xml"],
"license": "AGPL-3",
}
23 changes: 15 additions & 8 deletions base_phone_cdr/models/phone_cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@ class PhoneCDR(models.Model):
@api.depends("call_start_time", "call_connect_time", "inbound_flag")
def _compute_ring_time(self):
for rec in self:
ring_time = 0.0
if rec.inbound_flag and rec.call_connect_time and rec.call_start_time:
duration = rec.call_connect_time - rec.call_start_time
duration_in_s = duration.total_seconds()
rec.ring_time = divmod(duration_in_s, 3600)[0]
ring_time = divmod(duration.total_seconds(), 3600)[0]
rec.ring_time = ring_time

@api.depends("called_id", "inbound_flag")
def _compute_odoo_user(self):
for rec in self:
user_id = False
if rec.inbound_flag:
rec.user_id = self.env["res.users"].search(
[
("related_phone", "=", rec.called_id),
("related_phone", "!=", False),
],
limit=1,
user_id = (
self.env["res.users"]
.search(
[
("related_phone", "=", rec.called_id),
("related_phone", "!=", False),
],
limit=1,
)
.id
)
rec.user_id = user_id

guid = fields.Char("Call GUID")
inbound_flag = fields.Selection(
Expand Down
7 changes: 3 additions & 4 deletions base_phone_cdr/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ast import literal_eval

from odoo import api, fields, models
from odoo import fields, models


class ResPartner(models.Model):
Expand All @@ -12,12 +12,11 @@ class ResPartner(models.Model):

def _compute_total_cdr_count(self):
for partner in self:
cdr_records = self.env["phone.cdr"].search(
cdr_records_count = self.env["phone.cdr"].search_count(
[("partner_id", "=", partner.id)]
)
partner.total_cdr_count = cdr_records and len(cdr_records) or 0
partner.total_cdr_count = cdr_records_count

@api.multi
def action_view_partner_cdr_records(self):
self.ensure_one()
action = self.env.ref("base_phone_cdr.phone_cdr_view_action").read()[0]
Expand Down
1 change: 0 additions & 1 deletion base_phone_cdr/view/phone_cdr_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<field name="name">Phone Records</field>
<field name="view_id" ref="view_phone_cdr_tree" />
<field name="res_model">phone.cdr</field>
<field name="view_type">form</field>
<field name="domain">[]</field>
<field name="view_mode">tree,form,pivot</field>
</record>
Expand Down
12 changes: 3 additions & 9 deletions base_phone_cdr/view/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<button name="toggle_active" position="before">
<div name="button_box" position="inside">
<button
type="object"
class="oe_stat_button"
icon="fa-list"
name="action_view_partner_cdr_records"
attrs="{'invisible': [('customer', '=', False)]}"
context="{'default_partner_id': active_id}"
>
<div class="o_form_field o_stat_info">
<span class="o_stat_value">
<field name="total_cdr_count" />
</span>
<span class="o_stat_text">CDR</span>
</div>
<field string="CDR" name="total_cdr_count" widget="statinfo" />
</button>
</button>
</div>
</field>
</record>
</odoo>

0 comments on commit e877744

Please sign in to comment.