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

[17.0][ADD] repair_substate: New module #59

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
server-ux
91 changes: 91 additions & 0 deletions repair_substate/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
================
Repair Sub State
================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bd1b4c8d66f914e77d41ab47d2b18cdf01c17356287d83955afb9399b1934b5b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Frepair-lightgray.png?logo=github
:target: https://github.com/OCA/repair/tree/17.0/repair_substate
:alt: OCA/repair
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/repair-17-0/repair-17-0-repair_substate
: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/repair&target_branch=17.0
:alt: Try me on Runboat

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

This module allows to add a substate to repair order. For each repair
order state you can define a substate. With this module substates can be
defined allowing to extend the repair workflow.

**Table of contents**

.. contents::
:local:

Usage
=====

1. | Go to \*\* Settings > Technical > Sub State Configuration \*\* and
Add "Base Substate".
| If necessary you can add "Target State values" (ex define a
substate for "cancel" state). Substate sequence is very important.

2. Create a repair order and check if the substate are displayed on the
header of form view. Check if you can't set substate defined for
repair if repair is draft.

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

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

* 360ERP

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

- Marco Verbeij <[email protected]>
- Antonio Buric <[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/repair <https://github.com/OCA/repair/tree/17.0/repair_substate>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions repair_substate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions repair_substate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Repair Sub State",
"version": "17.0.1.0.0",
"category": "Tools",
"author": "360ERP, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/repair",
"license": "AGPL-3",
"depends": ["base_substate", "repair"],
"data": [
"views/repair_views.xml",
"data/repair_substate_data.xml",
],
"installable": True,
}
19 changes: 19 additions & 0 deletions repair_substate/data/repair_substate_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="base_substate_type_repair" model="base.substate.type">
<field name="name">Repair order Substate</field>
<field name="model">repair.order</field>
<field name="target_state_field">state</field>
</record>
<!-- repair related substate to repair state (draft, repair) -->
<record id="target_state_value_draft" model="target.state.value">
<field name="name">New</field>
<field name="base_substate_type_id" ref="base_substate_type_repair" />
<field name="target_state_value">draft</field>
</record>
<record id="target_state_value_repair" model="target.state.value">
<field name="name">Confirmed</field>
<field name="base_substate_type_id" ref="base_substate_type_repair" />
<field name="target_state_value">confirmed</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions repair_substate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import repair_order
54 changes: 54 additions & 0 deletions repair_substate/models/repair_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2024 360ERP (<https://www.360erp.com>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class BaseSubstateType(models.Model):
_inherit = "base.substate.type"

model = fields.Selection(
selection_add=[("repair.order", "Repair order")],
ondelete={"repair.order": "cascade"},
)


class RepairOrder(models.Model):
_inherit = ["repair.order", "base.substate.mixin"]
_name = "repair.order"

@api.constrains("substate_id", "state")
def check_substate_id_value(self):
repair_states = dict(self._fields["state"].selection)
for order in self:
target_state = order.substate_id.target_state_value_id.target_state_value
if order.substate_id and order.state != target_state and target_state:
raise ValidationError(

Check warning on line 27 in repair_substate/models/repair_order.py

View check run for this annotation

Codecov / codecov/patch

repair_substate/models/repair_order.py#L27

Added line #L27 was not covered by tests
_(
"The substate %(name)s is not defined for the state"
" %(state)s but for %(target_state)s "
)
% {
"name": order.substate_id.name,
"state": _(repair_states[order.state]),
"target_state": _(repair_states[target_state]),
}
)

def _track_template(self, changes):
res = super()._track_template(changes)
track = self[0]

Check warning on line 41 in repair_substate/models/repair_order.py

View check run for this annotation

Codecov / codecov/patch

repair_substate/models/repair_order.py#L40-L41

Added lines #L40 - L41 were not covered by tests
if "substate_id" in changes and track.substate_id.mail_template_id:
res["substate_id"] = (

Check warning on line 43 in repair_substate/models/repair_order.py

View check run for this annotation

Codecov / codecov/patch

repair_substate/models/repair_order.py#L43

Added line #L43 was not covered by tests
track.substate_id.mail_template_id,
{
"composition_mode": "comment",
"auto_delete_message": True,
"subtype_id": self.env["ir.model.data"]._xmlid_to_res_id(
"mail.mt_note"
),
"email_layout_xmlid": "mail.mail_notification_light",
},
)
return res

Check warning on line 54 in repair_substate/models/repair_order.py

View check run for this annotation

Codecov / codecov/patch

repair_substate/models/repair_order.py#L54

Added line #L54 was not covered by tests
3 changes: 3 additions & 0 deletions repair_substate/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions repair_substate/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Marco Verbeij \<<[email protected]>\>
- Antonio Buric \<<[email protected]>\>
3 changes: 3 additions & 0 deletions repair_substate/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module allows to add a substate to repair order. For each repair
order state you can define a substate. With this module substates can be
defined allowing to extend the repair workflow.
7 changes: 7 additions & 0 deletions repair_substate/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1. Go to \*\* Settings \> Technical \> Sub State Configuration \*\* and Add "Base Substate".
If necessary you can add "Target State values" (ex define a substate
for "cancel" state). Substate sequence is very important.

2. Create a repair order and check if the substate are displayed on the
header of form view. Check if you can't set substate defined for
repair if repair is draft.
Binary file added repair_substate/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading