[ADD] mrp_workcenter_category

This commit is contained in:
Ivàn Todorovich
2023-01-31 10:23:17 -03:00
parent c6c6c93ef6
commit e95d4d6240
16 changed files with 285 additions and 0 deletions

View File

@@ -0,0 +1 @@
# TO BE GENERATED

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,21 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "MRP Workcenter Category",
"summary": "Adds a category to workcenters",
"version": "15.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["ivantodorovich"],
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"category": "Manufacturing",
"depends": ["mrp"],
"data": [
"security/ir.model.access.csv",
"views/mrp_workcenter_category.xml",
"views/mrp_workcenter.xml",
],
"demo": ["demo/mrp_workcenter_category.xml"],
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
@author Iván Todorovich <ivan.todorovich@camptocamp.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="categ_extrusion" model="mrp.workcenter.category">
<field name="name">Extrusion</field>
</record>
<record id="categ_extrusion_pp" model="mrp.workcenter.category">
<field name="name">Polypropylene</field>
<field name="parent_id" ref="categ_extrusion" />
</record>
<record id="categ_extrusion_pvc" model="mrp.workcenter.category">
<field name="name">PVC</field>
<field name="parent_id" ref="categ_extrusion" />
</record>
<record id="categ_injection" model="mrp.workcenter.category">
<field name="name">Injection Molding</field>
</record>
<record id="categ_injection_pp" model="mrp.workcenter.category">
<field name="name">Polypropylene</field>
<field name="parent_id" ref="categ_injection" />
</record>
</odoo>

View File

@@ -0,0 +1,2 @@
from . import mrp_workcenter
from . import mrp_workcenter_category

View File

@@ -0,0 +1,14 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class MrpWorkcenter(models.Model):
_inherit = "mrp.workcenter"
category_id = fields.Many2one(
string="Category",
comodel_name="mrp.workcenter.category",
)

View File

@@ -0,0 +1,53 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class MrpWorkcenterCategory(models.Model):
_name = "mrp.workcenter.category"
_description = "Work Center Category"
_parent_name = "parent_id"
_parent_store = True
_rec_name = "complete_name"
_order = "complete_name"
ref = fields.Char(string="Internal Reference", index=True)
name = fields.Char(required=True)
parent_path = fields.Char(index=True)
parent_id = fields.Many2one(
string="Parent Category",
comodel_name="mrp.workcenter.category",
ondelete="cascade",
index=True,
)
child_ids = fields.One2many(
string="Children Categories",
comodel_name="mrp.workcenter.category",
inverse_name="parent_id",
)
complete_name = fields.Char(
compute="_compute_complete_name",
store=True,
recursive=True,
)
description = fields.Html()
_sql_constraints = [
("ref_uniq", "UNIQUE(ref)", "The reference must be unique!"),
]
@api.depends("name", "parent_id.complete_name")
def _compute_complete_name(self):
for rec in self:
if rec.parent_id:
rec.complete_name = f"{rec.parent_id.complete_name} / {rec.name}"
else:
rec.complete_name = rec.name
@api.model
def name_create(self, name):
# OVERRIDE: `name_create` should ignore `_rec_name = "complete_name"`
record = self.create({"name": name})
return record.name_get()[0]

View File

@@ -0,0 +1,3 @@
* `Camptocamp <https://www.camptocamp.com>`_
* Iván Todorovich <ivan.todorovich@camptocamp.com>

View File

@@ -0,0 +1 @@
Allows to set a Category on Work Centers.

View File

@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_mrp_workcenter_category_user,mrp.workcenter.category user,model_mrp_workcenter_category,mrp.group_mrp_user,1,0,0,0
access_mrp_workcenter_category_manager,mrp.workcenter.category manager,model_mrp_workcenter_category,mrp.group_mrp_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_mrp_workcenter_category_user mrp.workcenter.category user model_mrp_workcenter_category mrp.group_mrp_user 1 0 0 0
3 access_mrp_workcenter_category_manager mrp.workcenter.category manager model_mrp_workcenter_category mrp.group_mrp_manager 1 1 1 1

View File

@@ -0,0 +1 @@
from . import test_mrp_workcenter_category

View File

@@ -0,0 +1,27 @@
# Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests import TransactionCase
class TestMrpWorkcenterCategory(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.categ_extrusion = cls.env.ref("mrp_workcenter_category.categ_extrusion")
cls.categ_pp = cls.env.ref("mrp_workcenter_category.categ_extrusion_pp")
cls.categ_pvc = cls.env.ref("mrp_workcenter_category.categ_extrusion_pvc")
def test_complete_name(self):
self.assertEqual(self.categ_pp.complete_name, "Extrusion / Polypropylene")
def test_check_recursion(self):
with self.assertRaisesRegex(UserError, "Recursion Detected"):
self.categ_extrusion.parent_id = self.categ_pvc
def test_name_create(self):
record_id, __ = self.env["mrp.workcenter.category"].name_create("Test")
record = self.env["mrp.workcenter.category"].browse(record_id)
self.assertEqual(record.name, "Test")

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
@author Iván Todorovich <ivan.todorovich@camptocamp.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="mrp_workcenter_view" model="ir.ui.view">
<field name="model">mrp.workcenter</field>
<field name="inherit_id" ref="mrp.mrp_workcenter_view" />
<field name="arch" type="xml">
<field name="tag_ids" position="before">
<field name="category_id" />
</field>
</field>
</record>
<record id="mrp_workcenter_tree_view" model="ir.ui.view">
<field name="model">mrp.workcenter</field>
<field name="inherit_id" ref="mrp.mrp_workcenter_tree_view" />
<field name="arch" type="xml">
<field name="tag_ids" position="before">
<field name="category_id" optional="show" />
</field>
</field>
</record>
<record id="view_mrp_workcenter_search" model="ir.ui.view">
<field name="model">mrp.workcenter</field>
<field name="inherit_id" ref="mrp.view_mrp_workcenter_search" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="category_id" />
</field>
<filter name="company" position="before">
<filter
string="Category"
name="category"
domain="[]"
context="{'group_by': 'category_id'}"
/>
</filter>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
@author Iván Todorovich <ivan.todorovich@camptocamp.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_mrp_workcenter_category_search" model="ir.ui.view">
<field name="model">mrp.workcenter.category</field>
<field name="arch" type="xml">
<search>
<field name="name" />
<field name="ref" />
<field name="parent_id" />
</search>
</field>
</record>
<record id="view_mrp_workcenter_category_form" model="ir.ui.view">
<field name="model">mrp.workcenter.category</field>
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_title">
<label for="name" />
<h1>
<field name="name" placeholder="e.g. Extrusion lines" />
</h1>
</div>
<group name="main">
<group name="left">
<field name="parent_id" />
<field name="ref" />
</group>
<group name="right">
</group>
</group>
<notebook>
<page name="description" string="Description">
<field name="description" nolabel="1" />
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="view_mrp_workcenter_category_tree" model="ir.ui.view">
<field name="model">mrp.workcenter.category</field>
<field name="arch" type="xml">
<tree>
<field name="ref" optional="hide" />
<field name="display_name" />
</tree>
</field>
</record>
<record id="action_mrp_workcenter_category" model="ir.actions.act_window">
<field name="name">Work Center Categories</field>
<field name="res_model">mrp.workcenter.category</field>
</record>
<menuitem
id="menu_mrp_workcenter_category"
action="action_mrp_workcenter_category"
groups="mrp.group_mrp_routings"
parent="mrp.menu_mrp_configuration"
sequence="91"
/>
</odoo>

View File

@@ -0,0 +1 @@
../../../../mrp_workcenter_category

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)