Skip to content

Commit

Permalink
[ADD] maintenance_request_sale
Browse files Browse the repository at this point in the history
  • Loading branch information
etobella committed Sep 27, 2023
1 parent bfb39a3 commit d602ba5
Show file tree
Hide file tree
Showing 16 changed files with 694 additions and 0 deletions.
57 changes: 57 additions & 0 deletions maintenance_request_sale/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
========================
Maintenance Request Sale
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-oxigensalud%2Fodoo--addons-lightgray.png?logo=github
:target: https://github.com/oxigensalud/odoo-addons/tree/14.0/maintenance_request_sale
:alt: oxigensalud/odoo-addons

|badge1| |badge2| |badge3|

This is a bridge module between Maintenance and Sale

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/oxigensalud/odoo-addons/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/oxigensalud/odoo-addons/issues/new?body=module:%20maintenance_request_sale%0Aversion:%2014.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
~~~~~~~

* Dixmit

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

* Enric Tobella

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

This module is part of the `oxigensalud/odoo-addons <https://github.com/oxigensalud/odoo-addons/tree/14.0/maintenance_request_sale>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions maintenance_request_sale/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions maintenance_request_sale/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Maintenance Request Sale",
"summary": """
This is a bridge module between Maintenance and Sale""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"category": "Maintenance",
"author": "Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/oxigensalud/odoo-addons",
"depends": [
"maintenance",
"sale",
],
"data": [
"views/maintenance_request.xml",
"views/sale_order.xml",
],
}
2 changes: 2 additions & 0 deletions maintenance_request_sale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import maintenance_request
from . import sale_order
13 changes: 13 additions & 0 deletions maintenance_request_sale/models/maintenance_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 Dixmit
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class MaintenanceRequest(models.Model):

_inherit = "maintenance.request"

sale_order_id = fields.Many2one(
"sale.order", "Sale Order", groups="sales_team.group_sale_salesman"
)
47 changes: 47 additions & 0 deletions maintenance_request_sale/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Dixmit
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SaleOrder(models.Model):

_inherit = "sale.order"

maintenance_request_ids = fields.One2many(
"maintenance.request", "sale_order_id", string="Maintenance Requests"
)

maintenance_request_count = fields.Integer(
compute="_compute_maintenance_request_count", string="# Maintenances"
)

@api.depends("maintenance_request_ids")
def _compute_maintenance_request_count(self):
for sale in self:
sale.maintenance_request_count = len(sale.maintenance_request_ids)

def action_view_maintenance_request(self):
"""This function returns an action that display existing maintenance requests
of given repair order ids. When only one found, show the maintenance request
immediately.
"""
action = self.env.ref("maintenance.hr_equipment_request_action")
result = action.read()[0]
# override the context to get rid of the default filtering on repair order
result["context"] = {"default_sale_order_id": self.id}
maintenance_request_ids = self.mapped("maintenance_request_ids")
# choose the view_mode accordingly
if not maintenance_request_ids or len(maintenance_request_ids) > 1:
result["domain"] = [("sale_order_id", "=", self.id)]
elif len(maintenance_request_ids) == 1:
res = self.env.ref("maintenance.hr_equipment_request_view_form", False)
form_view = [(res and res.id or False, "form")]
if "views" in result:
result["views"] = form_view + [
(state, view) for state, view in result["views"] if view != "form"
]
else:
result["views"] = form_view
result["res_id"] = maintenance_request_ids.id
return result
1 change: 1 addition & 0 deletions maintenance_request_sale/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Enric Tobella
1 change: 1 addition & 0 deletions maintenance_request_sale/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a bridge module between Maintenance and Sale
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d602ba5

Please sign in to comment.