diff --git a/base_phone_cdr/README.rst b/base_phone_cdr/README.rst index e6083fe9a..a5d43292f 100644 --- a/base_phone_cdr/README.rst +++ b/base_phone_cdr/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= +Authors +------- + +* Open Source Integrators + Contributors ------------ -* Chanakya Soni -* Daniel Reis +- * Chanakya Soni +- * Daniel Reis + +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 `_ project on GitHub. +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_phone_cdr/__init__.py b/base_phone_cdr/__init__.py index 0650744f6..3275ac2ad 100644 --- a/base_phone_cdr/__init__.py +++ b/base_phone_cdr/__init__.py @@ -1 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models diff --git a/base_phone_cdr/__manifest__.py b/base_phone_cdr/__manifest__.py index 472c28106..53fa6f365 100644 --- a/base_phone_cdr/__manifest__.py +++ b/base_phone_cdr/__manifest__.py @@ -1,5 +1,5 @@ -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Base Phone CDR", "category": "web", @@ -13,6 +13,5 @@ "view/res_users_view.xml", "view/res_partner_view.xml", ], - "qweb": ["static/src/xml/widget.xml"], "license": "AGPL-3", } diff --git a/base_phone_cdr/models/__init__.py b/base_phone_cdr/models/__init__.py index 69e08cdb8..ef5a92aea 100644 --- a/base_phone_cdr/models/__init__.py +++ b/base_phone_cdr/models/__init__.py @@ -1,3 +1,4 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import phone_cdr from . import res_users from . import res_partner diff --git a/base_phone_cdr/models/phone_cdr.py b/base_phone_cdr/models/phone_cdr.py index 649fcf243..6d3e8d6bd 100644 --- a/base_phone_cdr/models/phone_cdr.py +++ b/base_phone_cdr/models/phone_cdr.py @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models @@ -8,22 +10,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( @@ -53,14 +62,15 @@ def _compute_odoo_user(self): ) partner_id = fields.Many2one("res.partner", string="Partner") - @api.model - def create(self, vals): - res = super().create(vals) - if res.inbound_flag: - res.partner_id = self.env["res.partner"].search( - [("phone", "=", res.called_id), ("phone", "!=", False)], limit=1 - ) - return res + @api.model_create_multi + def create(self, vals_list): + phonc_cdr_rec = super().create(vals_list) + for rec in phonc_cdr_rec: + if rec.inbound_flag: + rec.partner_id = self.env["res.partner"].search( + [("phone", "=", rec.called_id), ("phone", "!=", False)], limit=1 + ) + return phonc_cdr_rec def write(self, vals): res = super().write(vals) diff --git a/base_phone_cdr/models/res_partner.py b/base_phone_cdr/models/res_partner.py index c1cc2e09c..c4ee01ca3 100644 --- a/base_phone_cdr/models/res_partner.py +++ b/base_phone_cdr/models/res_partner.py @@ -1,6 +1,8 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from ast import literal_eval -from odoo import api, fields, models +from odoo import fields, models class ResPartner(models.Model): @@ -12,12 +14,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] diff --git a/base_phone_cdr/models/res_users.py b/base_phone_cdr/models/res_users.py index 9d17e706c..d418b83ae 100644 --- a/base_phone_cdr/models/res_users.py +++ b/base_phone_cdr/models/res_users.py @@ -1,3 +1,5 @@ +# Copyright (C) 2024 Open Source Integrators +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import fields, models diff --git a/base_phone_cdr/view/phone_cdr_view.xml b/base_phone_cdr/view/phone_cdr_view.xml index c4bf2f431..7cdea3ca6 100644 --- a/base_phone_cdr/view/phone_cdr_view.xml +++ b/base_phone_cdr/view/phone_cdr_view.xml @@ -7,7 +7,7 @@
- + @@ -52,11 +52,10 @@ - + Phone Records phone.cdr - form [] tree,form,pivot diff --git a/base_phone_cdr/view/res_partner_view.xml b/base_phone_cdr/view/res_partner_view.xml index e2016026b..e15bf0ca9 100644 --- a/base_phone_cdr/view/res_partner_view.xml +++ b/base_phone_cdr/view/res_partner_view.xml @@ -1,27 +1,20 @@ - + partner.view.cdr res.partner - - +