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][MIG] repair_sequence_type: Migration to 17.0 #44

Closed
wants to merge 14 commits into from
Closed
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
90 changes: 90 additions & 0 deletions repair_type_sequence/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
====================
Repair Type Sequence
====================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |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_type_sequence
: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_type_sequence
: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 introduces a sequence to the repair type that will be
influence the numbering in the repair orders.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

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_type_sequence%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
-------

* ForgeFlow S.L.

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

- Aaron Henriquez [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.

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

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

|maintainer-AaronHForgeFlow|

This module is part of the `OCA/repair <https://github.com/OCA/repair/tree/17.0/repair_type_sequence>`_ 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_type_sequence/__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_type_sequence/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 ForgeFlow S.L. (https://forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Repair Type Sequence",
"summary": """
Adds sequence to repair orders defined in the repairs's
type""",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow S.L.," "Odoo Community Association (OCA)",
"maintainers": ["AaronHForgeFlow"],
"website": "https://github.com/OCA/repair",
"depends": ["repair_type"],
"development_status": "Alpha",
"data": ["views/repair_type_views.xml"],
}
65 changes: 65 additions & 0 deletions repair_type_sequence/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * repair_type_sequence
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-04-03 12:35+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_id
msgid "Entry Sequence"
msgstr "Sequenza di immissione"

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_number_next
msgid "Next Number"
msgstr "Numero successivo"

#. module: repair_type_sequence
#: model:ir.model,name:repair_type_sequence.model_repair_order
msgid "Repair Order"
msgstr "Ordine di riparazione"

#. module: repair_type_sequence
#: model:ir.model,name:repair_type_sequence.model_repair_type
msgid "Repair Type"
msgstr "Tipo riparazione"

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_prefix
msgid "Sequence Prefix"
msgstr "Prefisso sequenza"

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_number_next
msgid "The next sequence number will be used for the next rorder."
msgstr ""
"Il numero di sequenza successivo verrà utilizzato per il prossimo ordine di "
"riparazione."

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_prefix
msgid "The rorder's sequence will be created using this prefix."
msgstr ""
"La sequenza dell'ordine di riparazione verrà creata utilizzando questo "
"prefisso."

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_id
msgid ""
"This field contains the information related to the numbering of the rorders "
"belonging to this rtype."
msgstr ""
"Questo campo contiene l'informazione relativa alla numerazione degli ordini "
"di riparazione appartenenti a questo tipo."
56 changes: 56 additions & 0 deletions repair_type_sequence/i18n/repair_type_sequence.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * repair_type_sequence
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_id
msgid "Entry Sequence"
msgstr ""

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_number_next
msgid "Next Number"
msgstr ""

#. module: repair_type_sequence
#: model:ir.model,name:repair_type_sequence.model_repair_order
msgid "Repair Order"
msgstr ""

#. module: repair_type_sequence
#: model:ir.model,name:repair_type_sequence.model_repair_type
msgid "Repair Type"
msgstr ""

#. module: repair_type_sequence
#: model:ir.model.fields,field_description:repair_type_sequence.field_repair_type__sequence_prefix
msgid "Sequence Prefix"
msgstr ""

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_number_next
msgid "The next sequence number will be used for the next rorder."
msgstr ""

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_prefix
msgid "The rorder's sequence will be created using this prefix."
msgstr ""

#. module: repair_type_sequence
#: model:ir.model.fields,help:repair_type_sequence.field_repair_type__sequence_id
msgid ""
"This field contains the information related to the numbering of the rorders "
"belonging to this rtype."
msgstr ""
2 changes: 2 additions & 0 deletions repair_type_sequence/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import repair_type
from . import repair_order
29 changes: 29 additions & 0 deletions repair_type_sequence/models/repair_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 ForgeFlow S.L. (https://forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class RepairOrder(models.Model):
_inherit = "repair.order"

@api.model
def create(self, vals):
rorder = super().create(vals)
if rorder.repair_type_id:
sequence_id = (
self.env["repair.type"].browse(vals["repair_type_id"]).sequence_id
)
if sequence_id:
rorder.name = sequence_id._next()
return rorder

def write(self, vals):
res = False
for rec in self:
new_rtype_id = vals.get("repair_type_id", False)
new_rtype = self.env["repair.type"].browse(new_rtype_id)
if new_rtype and new_rtype.sequence_id:
vals["name"] = new_rtype.sequence_id._next()
res = super(RepairOrder, rec).write(vals)
return res
104 changes: 104 additions & 0 deletions repair_type_sequence/models/repair_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright 2023 ForgeFlow S.L. (https://forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class RepairType(models.Model):
_inherit = "repair.type"

sequence_prefix = fields.Char(
help="The rorder's sequence will be created using this prefix.",
)
sequence_id = fields.Many2one(
"ir.sequence",
string="Entry Sequence",
help="This field contains the information related to the "
"numbering of the rorders belonging to this rtype.",
copy=False,
)
sequence_number_next = fields.Integer(
string="Next Number",
help="The next sequence number will be used for the next rorder.",
compute="_compute_seq_number_next",
inverse="_inverse_seq_number_next",
)

@api.model
def _create_sequence(self, vals):
"""Create new no_gap entry sequence"""
seq = {
"name": vals.get("name", False) or self.name,
"implementation": "no_gap",
"prefix": (vals.get("sequence_prefix", False) or self.sequence_prefix),
"padding": 4,
"number_increment": 1,
"use_date_range": False,
}
seq = self.env["ir.sequence"].create(seq)
seq_date_range = seq._get_current_sequence()
seq_date_range.number_next = vals.get("sequence_number_next", 1)
return seq

# do not depend on 'sequence_id.date_range_ids', because
# sequence_id._get_current_sequence() may invalidate it!
@api.depends("sequence_id.use_date_range", "sequence_id.number_next_actual")
def _compute_seq_number_next(self):
"""Compute 'sequence_number_next' according to the current sequence
in use, an ir.sequence or an ir.sequence.date_range.
"""
for rtype in self:
if rtype.sequence_id:
sequence = rtype.sequence_id._get_current_sequence()
rtype.sequence_number_next = sequence.number_next_actual

Check warning on line 53 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L52-L53

Added lines #L52 - L53 were not covered by tests
else:
rtype.sequence_number_next = 1

Check warning on line 55 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L55

Added line #L55 was not covered by tests

def _inverse_seq_number_next(self):
"""
Inverse 'sequence_number_next' to edit the current sequence next number
"""
for rtype in self:
if rtype.sequence_id and rtype.sequence_number_next:
sequence = rtype.sequence_id._get_current_sequence()
sequence.sudo().number_next = rtype.sequence_number_next

Check warning on line 64 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L63-L64

Added lines #L63 - L64 were not covered by tests

@api.model
def create(self, vals):
if not vals.get("sequence_id", False):
if vals.get("sequence_prefix", False):
vals["sequence_id"] = self.sudo()._create_sequence(vals).id
else:
vals["sequence_prefix"] = (

Check warning on line 72 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L72

Added line #L72 was not covered by tests
self.env["ir.sequence"].browse(vals["sequence_id"]).prefix
)
result = super().create(vals)
self._compute_rorder_code()
return result

def write(self, vals):
if not vals.get("sequence_id", False):
if vals.get("sequence_prefix", False):
vals["sequence_id"] = self.sudo()._create_sequence(vals).id

Check warning on line 82 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L82

Added line #L82 was not covered by tests
else:
vals["sequence_prefix"] = (

Check warning on line 84 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L84

Added line #L84 was not covered by tests
self.env["ir.sequence"].browse(vals["sequence_id"]).prefix
)
result = super().write(vals)
self._compute_rorder_code()
return result

Check warning on line 89 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L87-L89

Added lines #L87 - L89 were not covered by tests

@api.onchange("sequence_id")
def _onchange_sequence_id(self):
if self.sequence_id:
self.sequence_prefix = self.sequence_id.prefix

Check warning on line 94 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L94

Added line #L94 was not covered by tests

def _compute_rorder_code(self):
for rtype in self:
if rtype.sequence_id:
rtype_rorders = rtype.env["repair.order"].search(

Check warning on line 99 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L99

Added line #L99 was not covered by tests
[("repair_type_id", "=", rtype.id)]
)
for rorder in rtype_rorders:
if not rorder.name and rorder.repair_type_id.sequence_id:
rorder.name = rorder.repair_type_id.sequence_id._next()

Check warning on line 104 in repair_type_sequence/models/repair_type.py

View check run for this annotation

Codecov / codecov/patch

repair_type_sequence/models/repair_type.py#L104

Added line #L104 was not covered by tests
3 changes: 3 additions & 0 deletions repair_type_sequence/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions repair_type_sequence/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Aaron Henriquez <[email protected]>\>
2 changes: 2 additions & 0 deletions repair_type_sequence/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module introduces a sequence to the repair type that will be
influence the numbering in the repair orders.
Binary file added repair_type_sequence/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