Skip to content

Commit

Permalink
[MIG] crm_phonecall_timesheet: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Jun 7, 2019
1 parent d63e772 commit ce87f82
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 81 deletions.
85 changes: 63 additions & 22 deletions crm_phonecall_timesheet/README.rst
Original file line number Diff line number Diff line change
@@ -1,56 +1,97 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
=============
CRM Timesheet
=============

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Ftimesheet-lightgray.png?logo=github
:target: https://github.com/OCA/timesheet/tree/12.0/crm_phonecall_timesheet
:alt: OCA/timesheet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/timesheet-12-0/timesheet-12-0-crm_phonecall_timesheet
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/117/12.0
:alt: Try me on Runbot

=======================
CRM Phonecall Timesheet
=======================
|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to generate timesheets from phone calls.

**Table of contents**

.. contents::
:local:

Configuration
=============

Go to ``Settings > Users`` and enable 'Show Scheduled Calls Menu'

Usage
=====

* In phone calls tree, you can add an analytic account, and if the call has
any duration, a timesheet activity will be created.
* You can choose how to input time: (1) set time you dedicated to call after
finishing it OR (2) create & save call with time set in 00:00 and Stop the
timer when call ends, this will set exactly the time you spent.
1. Go to ``CRM > Phone Calls`` and create or edit a record
2. Only records with project and duration > 0 will be generate an timesheet

** If you remove the project or change duration to 0 the timesheet will
be deleted.

Known issues / Roadmap
======================

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/117/10.0
* A bridge module would be needed in case of using hr_timesheet_activity_begin_end
to get the right start and stop hours.

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/timesheet/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/timesheet/issues/new?body=module:%20crm_phonecall_timesheet%0Aversion:%2012.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
~~~~~~~

* Tecnativa

Contributors
------------
~~~~~~~~~~~~

* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Javier Iniesta <javieria@antiun.com>
* David Vidal <david.vidal@tecnativa.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>

Maintainers
~~~~~~~~~~~

Maintainer
----------
This module is maintained by the OCA.

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/timesheet <https://github.com/OCA/timesheet/tree/12.0/crm_phonecall_timesheet>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 0 additions & 2 deletions crm_phonecall_timesheet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import models
7 changes: 3 additions & 4 deletions crm_phonecall_timesheet/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "CRM Timesheet",
'category': 'Customer Relationship Management',
'version': '10.0.1.0.0',
'version': '12.0.1.0.0',
'depends': [
'crm_timesheet',
'hr_timesheet',
'crm_phonecall',
],
'data': [
Expand All @@ -17,7 +16,7 @@
],
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'http://www.tecnativa.com',
'website': 'https://github.com/OCA/timesheet',
'license': 'AGPL-3',
'auto_install': True,
'installable': True,
Expand Down
2 changes: 0 additions & 2 deletions crm_phonecall_timesheet/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -*- coding: utf-8 -*-

from . import account_analytic_line
from . import crm_phonecall
1 change: 0 additions & 1 deletion crm_phonecall_timesheet/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
Expand Down
61 changes: 36 additions & 25 deletions crm_phonecall_timesheet/models/crm_phonecall.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
# Copyright 2017 David Vidal <david.vidal@tecnativa.com>
# Copyright 2019 Alexandre Díaz <alexandre.diaz@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from odoo import _, api, fields, models
from odoo.fields import DATE_LENGTH
from datetime import datetime
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)


class CrmPhonecall(models.Model):
_inherit = 'crm.phonecall'

analytic_account_id = fields.Many2one(
comodel_name='account.analytic.account')
project_id = fields.Many2one(
comodel_name='project.project')
timesheet_ids = fields.One2many(comodel_name='account.analytic.line',
inverse_name='phonecall_id')

@api.model
def _timesheet_prepare(self, vals):
"""
param: vals
Expand All @@ -26,50 +29,58 @@ def _timesheet_prepare(self, vals):
"""
if len(self) > 0:
self.ensure_one()
date = vals.get('date', self.date)
date = vals.get(
'date',
fields.Date.to_string(self.date))
if not date:
raise UserError(_('Date field must be filled.'))
project_id = vals.get('project_id', self.project_id)
user_id = vals.get('user_id', self.user_id.id)
account_id = vals.get('analytic_account_id',
self.analytic_account_id.id)
unit_amount = vals.get('duration', self.duration)
res = {
'date': date[:DATE_LENGTH],
'user_id': user_id,
'name': vals.get('name', self.name),
'account_id': account_id,
'project_id': project_id,
'unit_amount': unit_amount / 60.0,
'code': 'phone',
}
return res

@api.model
def create(self, vals):
if vals.get('analytic_account_id') and vals.get('duration', 0) > 0:
if vals.get('project_id') and vals.get('duration', 0) > 0:
timesheet_data = self._timesheet_prepare(vals)
vals['timesheet_ids'] = vals.get('timesheet_ids', [])
vals['timesheet_ids'].append((0, 0, timesheet_data))
res = super(CrmPhonecall, self).create(vals)
res = super().create(vals)
return res

@api.multi
def write(self, vals):
timesheet = self.env['account.analytic.line'].search([
('code', '=', 'phone'), ('phonecall_id', '=', self.id)])
analytic_account_id = vals.get('analytic_account_id',
self.analytic_account_id)
duration = vals.get('duration', 0)
if timesheet:
if ('analytic_account_id' in vals and not vals[
'analytic_account_id']):
vals['timesheet_ids'] = [(2, timesheet.id, 0)]
else:
vals['timesheet_ids'] = [(1, timesheet.id,
self._timesheet_prepare(vals))]
elif analytic_account_id and duration > 0:
vals['timesheet_ids'] = [(0, 0, self._timesheet_prepare(vals))]
res = super(CrmPhonecall, self).write(vals)
return res
AccountAnalitycLineObj = self.env['account.analytic.line']
for record in self:
timesheet = AccountAnalitycLineObj.search([
('phonecall_id', '=', record.id),
('code', '=', 'phone'),
])
project_id = vals.get('project_id', record.project_id.id)
duration = vals.get('duration', record.duration) or 0
can_create_ts = project_id and duration > 0
if can_create_ts:
vals.update({
'project_id': project_id,
'duration': duration,
})
if timesheet:
if not can_create_ts:
vals['timesheet_ids'] = [(2, timesheet.id, 0)]
else:
vals['timesheet_ids'] = [(1, timesheet.id,
self._timesheet_prepare(vals))]
elif can_create_ts:
vals['timesheet_ids'] = [(0, 0, self._timesheet_prepare(vals))]
return super().write(vals)

@api.multi
def button_end_call(self):
Expand Down
1 change: 1 addition & 0 deletions crm_phonecall_timesheet/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Go to ``Settings > Users`` and enable 'Show Scheduled Calls Menu'
5 changes: 5 additions & 0 deletions crm_phonecall_timesheet/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Rafael Blasco <rafael.blasco@tecnativa.com>
* Javier Iniesta <javieria@antiun.com>
* David Vidal <david.vidal@tecnativa.com>
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
1 change: 1 addition & 0 deletions crm_phonecall_timesheet/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to generate timesheets from phone calls.
2 changes: 2 additions & 0 deletions crm_phonecall_timesheet/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* A bridge module would be needed in case of using hr_timesheet_activity_begin_end
to get the right start and stop hours.
5 changes: 5 additions & 0 deletions crm_phonecall_timesheet/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. Go to ``CRM > Phone Calls`` and create or edit a record
2. Only records with project and duration > 0 will be generate an timesheet

** If you remove the project or change duration to 0 the timesheet will
be deleted.
Loading

0 comments on commit ce87f82

Please sign in to comment.