Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][12.0] fleet vehicle service calendar: Backporting 13.0 to 12.0 #11

Merged
merged 4 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions fleet_vehicle_service_calendar/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
========================================
Scheduling Meetings for Vehicle Services
========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| 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
.. |badge2| image:: https://img.shields.io/badge/github-OCA%2Ffleet-lightgray.png?logo=github
:target: https://github.com/OCA/fleet/tree/12.0/fleet_vehicle_service_calendar
:alt: OCA/fleet
.. |badge3| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/fleet-12-0/fleet-12-0-fleet_vehicle_service_calendar
:alt: Translate me on Weblate
.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/291/12.0
:alt: Try me on Runbot

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

This module adds the following features:

- A smart button in form view of services to schedule meetings.
- Search events for specific services in calendar view.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/fleet/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/fleet/issues/new?body=module:%20fleet_vehicle_service_calendar%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
~~~~~~~

* Druidoo

Contributors
~~~~~~~~~~~~

* `Druidoo <https://www.druidoo.io>`_:

* Iván Todorovich <[email protected]>
* Manuel Marquez <[email protected]>

* `PnLUG - Gruppo Odoo <https://odoo.pnlug.it>`_:

* Stefano Consolaro <[email protected]> (backport 13.0→12.0)

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.

.. |maintainer-mamcode| image:: https://github.com/mamcode.png?size=40px
:target: https://github.com/mamcode
:alt: mamcode
.. |maintainer-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
:target: https://github.com/ivantodorovich
:alt: ivantodorovich

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-mamcode| |maintainer-ivantodorovich|

This module is part of the `OCA/fleet <https://github.com/OCA/fleet/tree/12.0/fleet_vehicle_service_calendar>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions fleet_vehicle_service_calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2020-Present Druidoo - Manuel Marquez <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
20 changes: 20 additions & 0 deletions fleet_vehicle_service_calendar/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020-Present Druidoo - Manuel Marquez <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Scheduling Meetings for Vehicle Services",
"summary": "Add a smart button in services to schedule meetings.",
"category": "Human Resources/Fleet",
"author": "Druidoo, Odoo Community Association (OCA)",
"maintainers": ["mamcode", "ivantodorovich"],
"development_status": "Stable",
"website": "https://github.com/OCA/fleet",
"license": "AGPL-3",
"version": "12.0.1.0.0",
"depends": ["calendar", "fleet_vehicle_service_kanban"],
"data": [
"views/fleet_vehicle_log_services_views.xml",
"views/calendar_event_views.xml",
],
"installable": True,
}
5 changes: 5 additions & 0 deletions fleet_vehicle_service_calendar/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2020-Present Druidoo - Manuel Marquez <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import calendar_event
from . import fleet_vehicle_log_services
51 changes: 51 additions & 0 deletions fleet_vehicle_service_calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2020-Present Druidoo - Manuel Marquez <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class CalendarEvent(models.Model):
_inherit = "calendar.event"

vehicle_service_id = fields.Many2one(
"fleet.vehicle.log.services", "Vehicle Service"
)

@api.model
def default_get(self, fields):
if self.env.context.get("default_vehicle_service_id"):
self = self.with_context(
default_res_model_id=self.env.ref(
"fleet.model_fleet_vehicle_log_services"
).id,
default_res_id=self.env.context["default_vehicle_service_id"],
)
defaults = super(CalendarEvent, self).default_get(fields)

# sync res_model / res_id to service id
# (aka creating meeting from service chatter)
ctx = self.env.context
if "vehicle_service_id" not in defaults:
defaults["vehicle_service_id"] = defaults.get("res_id", False) or ctx.get(
"default_res_id", False
)

return defaults

def _compute_is_highlighted(self):
super(CalendarEvent, self)._compute_is_highlighted()
if self.env.context.get("active_model") == "fleet.vehicle.log.services":
vehicle_service_id = self.env.context.get("active_id")
for event in self:
if event.vehicle_service_id.id == vehicle_service_id:
event.is_highlighted = True

@api.model
def create(self, vals):
event = super(CalendarEvent, self).create(vals)

if event.vehicle_service_id and not event.activity_ids:
event.vehicle_service_id.log_meeting(
event.name, event.start, event.duration
)
return event
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2020-Present Druidoo - Manuel Marquez <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, fields, models


class FleetVehicleLogServices(models.Model):
_inherit = "fleet.vehicle.log.services"

meeting_count = fields.Integer("# Meetings", compute="_compute_meeting_count")

def _compute_meeting_count(self):
meeting_data = self.env["calendar.event"].read_group(
[("vehicle_service_id", "in", self.ids)],
["vehicle_service_id"],
["vehicle_service_id"],
)
mapped_data = {
m["vehicle_service_id"][0]: m["vehicle_service_id_count"]
for m in meeting_data
}
for record in self:
record.meeting_count = mapped_data.get(record.id, 0)

def action_schedule_meeting(self):
""" Open meeting's calendar view to schedule meeting on current service.
:return dict: dictionary value for created Meeting view
"""
self.ensure_one()
action = self.env.ref("calendar.action_calendar_event").read()[0]
partner_ids = self.env.user.partner_id.ids
if self.user_id:
partner_ids += self.user_id.partner_id.ids
action["context"] = {
"default_vehicle_service_id": self.id,
"default_partner_id": self.user_id.partner_id.id if self.user_id else False,
"default_partner_ids": partner_ids,
"default_name": "%s - %s"
% (self.vehicle_id.name, self.cost_subtype_id.name),
"search_default_vehicle_service_id": self.id,
}
return action

def log_meeting(self, meeting_subject, meeting_date, duration):
if not duration:
duration = _("unknown")
else:
duration = str(duration)
meet_date = fields.Datetime.from_string(meeting_date)
meeting_usertime = fields.Datetime.to_string(
fields.Datetime.context_timestamp(self, meet_date)
)
html_time = "<time datetime='{}+00:00'>{}</time>".format(
meeting_date, meeting_usertime,
)
message = _(
"Meeting scheduled at '%s'<br> Subject: %s <br> Duration: %s hours"
) % (html_time, meeting_subject, duration)
return self.message_post(body=message)
8 changes: 8 additions & 0 deletions fleet_vehicle_service_calendar/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* `Druidoo <https://www.druidoo.io>`_:

* Iván Todorovich <[email protected]>
* Manuel Marquez <[email protected]>

* `PnLUG - Gruppo Odoo <https://odoo.pnlug.it>`_:

* Stefano Consolaro <[email protected]> (backport 13.0→12.0)
4 changes: 4 additions & 0 deletions fleet_vehicle_service_calendar/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module adds the following features:

- A smart button in form view of services to schedule meetings.
- Search events for specific services in calendar view.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading