Skip to content

Commit

Permalink
Merge PR #70 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Dec 5, 2024
2 parents 3572a7e + 4fa927e commit f929f9d
Show file tree
Hide file tree
Showing 20 changed files with 988 additions and 0 deletions.
99 changes: 99 additions & 0 deletions repair_order_template/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=====================
Repair Order Template
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5a5ce7d5e2cfce32a16afc2beff8d76fe1445f91693e087e533fdd2309afeadc
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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_order_template
: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_order_template
: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|

Create and use templates to save time when creating repair orders. With
them, you can pre-fill the repair order fields and spare parts.

**Table of contents**

.. contents::
:local:

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

Go to **Repairs > Configuration > Repair Orders Templates** to create
and manage your templates.

Usage
=====

On a *draft* Repair Order, choose a template to automatically fill some
fields and spare parts, according to the template.

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

* Camptocamp

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

- `Camptocamp <https://camptocamp.com/>`__:

- Iván Todorovich <[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-ivantodorovich| image:: https://github.com/ivantodorovich.png?size=40px
:target: https://github.com/ivantodorovich
:alt: ivantodorovich

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

|maintainer-ivantodorovich|

This module is part of the `OCA/repair <https://github.com/OCA/repair/tree/17.0/repair_order_template>`_ 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_order_template/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions repair_order_template/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Repair Order Template",
"summary": "Use templates to save time when creating repair orders",
"version": "17.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/repair",
"license": "AGPL-3",
"category": "Repair",
"depends": ["repair"],
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"views/repair_order_template.xml",
"views/repair_order.xml",
],
"demo": [
"demo/repair_order_template.xml",
],
}
32 changes: 32 additions & 0 deletions repair_order_template/demo/repair_order_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="repair_order_template_demo" model="repair.order.template">
<field name="name">General Repair</field>
</record>

<record id="repair_order_template_demo__line_1" model="repair.order.template.line">
<field
name="template_id"
ref="repair_order_template.repair_order_template_demo"
/>
<field name="type">add</field>
<field name="product_id" ref="product.product_product_3" />
<field name="product_uom" ref="uom.product_uom_unit" />
</record>

<record id="repair_order_template_demo__line_2" model="repair.order.template.line">
<field
name="template_id"
ref="repair_order_template.repair_order_template_demo"
/>
<field name="type">add</field>
<field name="product_id" ref="product.product_product_4" />
<field name="product_uom" ref="uom.product_uom_unit" />
</record>

</odoo>
3 changes: 3 additions & 0 deletions repair_order_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import repair_order_template_line
from . import repair_order_template
from . import repair_order
38 changes: 38 additions & 0 deletions repair_order_template/models/repair_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

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


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

repair_order_template_id = fields.Many2one(
string="Order Template",
help="Use templates to save time when creating repair orders.",
comodel_name="repair.order.template",
check_company=True,
)

@api.constrains("repair_order_template_id")
def _check_repair_order_template_id(self):
if self.repair_order_template_id and self.state != "draft":
raise ValidationError(_("Order Template can only be set on draft orders"))

@api.onchange("repair_order_template_id")
def _onchange_repair_order_template_id(self):
if not self.repair_order_template_id:
return
# Simple fields get copied over if they're set on the template
for fname in ("product_id", "under_warranty", "tag_ids", "internal_notes"):
if self.repair_order_template_id[fname]:
self[fname] = self.repair_order_template_id[fname]
# Lines get replaced by new ones, generated from the template lines
if self.repair_order_template_id.line_ids:
self.move_ids = [fields.Command.clear()] + [
fields.Command.create(
dict(line._prepare_move_values(), company_id=self.company_id.id)
)
for line in self.repair_order_template_id.line_ids
]
33 changes: 33 additions & 0 deletions repair_order_template/models/repair_order_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class RepairOrderTemplate(models.Model):
_name = "repair.order.template"
_description = "Repair Order Template"
_check_company_auto = True

name = fields.Char(required=True, translate=True)
active = fields.Boolean(default=True)
company_id = fields.Many2one("res.company", default=lambda self: self.env.company)
tag_ids = fields.Many2many("repair.tags", string="Tags")
internal_notes = fields.Html()
under_warranty = fields.Boolean()
product_id = fields.Many2one(
"product.product",
string="Product to Repair",
domain="""
[
('type', 'in', ['product', 'consu']),
('company_id', 'in', [False, company_id])
]
""",
check_company=True,
)
line_ids = fields.One2many(
comodel_name="repair.order.template.line",
inverse_name="template_id",
check_company=True,
)
72 changes: 72 additions & 0 deletions repair_order_template/models/repair_order_template_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class RepairOrderTemplateLine(models.Model):
_name = "repair.order.template.line"
_description = "Repair Order Template Line"
_check_company_auto = True

template_id = fields.Many2one(
"repair.order.template",
required=True,
readonly=True,
ondelete="cascade",
)
company_id = fields.Many2one(
related="template_id.company_id",
store=True,
)
type = fields.Selection(
selection=lambda self: (
self.env["stock.move"]
._fields["repair_line_type"]
._description_selection(self.env)
),
required=True,
)
product_id = fields.Many2one(
"product.product",
string="Product",
domain="""
[
('type', 'in', ['product', 'consu']),
('company_id', 'in', [False, company_id])
]
""",
check_company=True,
required=True,
)
product_uom_category_id = fields.Many2one(
related="product_id.uom_id.category_id",
)
product_uom = fields.Many2one(
"uom.uom",
string="Unit of Measure",
domain="[('category_id', '=', product_uom_category_id)]",
compute="_compute_product_uom",
readonly=False,
required=True,
store=True,
)
product_uom_qty = fields.Float(
"Quantity",
digits="Product Unit of Measure",
required=True,
default=1.0,
)

@api.depends("product_id")
def _compute_product_uom(self):
for rec in self:
rec.product_uom = rec.product_id.uom_id

def _prepare_move_values(self):
return {
"repair_line_type": self.type,
"product_id": self.product_id.id,
"product_uom": self.product_uom.id,
"product_uom_qty": self.product_uom_qty,
}
3 changes: 3 additions & 0 deletions repair_order_template/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_order_template/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Go to **Repairs > Configuration > Repair Orders Templates** to create and manage your
templates.
3 changes: 3 additions & 0 deletions repair_order_template/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Camptocamp](https://camptocamp.com/):

- Iván Todorovich \<<[email protected]>\>
2 changes: 2 additions & 0 deletions repair_order_template/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Create and use templates to save time when creating repair orders.
With them, you can pre-fill the repair order fields and spare parts.
2 changes: 2 additions & 0 deletions repair_order_template/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On a *draft* Repair Order, choose a template to automatically fill some fields
and spare parts, according to the template.
5 changes: 5 additions & 0 deletions repair_order_template/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_repair_order_template_user,repair.order.template::user,model_repair_order_template,stock.group_stock_user,1,0,0,0
access_repair_order_template_manager,repair.order.template::manager,model_repair_order_template,stock.group_stock_manager,1,1,1,1
access_repair_order_template_line_user,repair.order.template.line::user,model_repair_order_template_line,stock.group_stock_user,1,0,0,0
access_repair_order_template_line_manager,repair.order.template.line::manager,model_repair_order_template_line,stock.group_stock_manager,1,1,1,1
20 changes: 20 additions & 0 deletions repair_order_template/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Camptocamp SA (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="ir_rule_repair_order_template_multi_company" model="ir.rule">
<field name="name">Repair Order Template: Multi-company</field>
<field name="model_id" ref="model_repair_order_template" />
<field name="domain_force">[('company_id', 'in', company_ids + [False])]</field>
</record>

<record id="ir_rule_repair_order_template_line_multi_company" model="ir.rule">
<field name="name">Repair Order Template Line: Multi-company</field>
<field name="model_id" ref="model_repair_order_template_line" />
<field name="domain_force">[('company_id', 'in', company_ids + [False])]</field>
</record>

</odoo>
Loading

0 comments on commit f929f9d

Please sign in to comment.