Skip to content

Commit

Permalink
[IMP] quality_control_oca: inspection access buttons - moved to XML a…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
dalonsod committed Nov 25, 2023
1 parent 22a1130 commit 0a26ef8
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 62 deletions.
3 changes: 2 additions & 1 deletion quality_control_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Quality Control OCA
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6fb9b191b38582ebba5b4717a2666ce0afc2e2fde98cade2b2cba4010a1c7111
!! source digest: sha256:9416315bac2077c0ab38d72f229416d9fb0412fd00b8f74e72953166aaa7ad9b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -109,6 +109,7 @@ Contributors
* `Trey Kilobytes de Soluciones SL <https://www.trey.es>`__:

* Vicent Cubells
* David Alonso <david.alonso@solvos.es>

Other credits
~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions quality_control_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2014 Oihane Crucelaegui - AvanzOSC
# Copyright 2017-2020 ForgeFlow S.L.
# Copyright 2017 Simone Rubino - Agile Business Group
# Copyright 2023 Solvos Consultoría Informática, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
Expand All @@ -25,6 +26,7 @@
"views/qc_test_view.xml",
"views/qc_trigger_view.xml",
"views/product_template_view.xml",
"views/product_product_view.xml",
"views/product_category_view.xml",
],
"demo": ["demo/quality_control_demo.xml"],
Expand Down
25 changes: 1 addition & 24 deletions quality_control_oca/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Copyright 2014 Oihane Crucelaegui - AvanzOSC
# Copyright 2017 ForgeFlow S.L.
# Copyright 2017 Simone Rubino - Agile Business Group
# Copyright 2023 Solvos Consultoría Informática, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import ast

from odoo import fields, models

Expand Down Expand Up @@ -54,26 +54,3 @@ def _compute_count_inspections(self):
product.done_inspections = (
product.passed_inspections + product.failed_inspections
)

def button_qc_inspection_per_product(self):
return self._action_qc_inspection_per_product()

def _action_qc_inspection_per_product(self):
product_ids = self.ids
action = self.env["ir.actions.act_window"]._for_xml_id(
"quality_control_oca.action_qc_inspection"
)
domain = [("product_id", "in", product_ids)]
qc_type = self.env.context.get("qc_type", "all")
if qc_type == "done":
domain.append(("state", "not in", ["draft", "waiting"]))
elif qc_type == "passed":
domain.append(("state", "=", "success"))
elif qc_type == "failed":
domain.append(("state", "=", "failed"))
action["domain"] = domain
if len(product_ids) == 1:
context = ast.literal_eval(action.get("context"))
context["default_object_id"] = "product.product,%s" % product_ids[0]
action["context"] = context
return action
3 changes: 2 additions & 1 deletion quality_control_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Quality Control OCA</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6fb9b191b38582ebba5b4717a2666ce0afc2e2fde98cade2b2cba4010a1c7111
!! source digest: sha256:9416315bac2077c0ab38d72f229416d9fb0412fd00b8f74e72953166aaa7ad9b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/manufacture/tree/15.0/quality_control_oca"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-quality_control_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/manufacture&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module provides a generic infrastructure for quality tests. The idea is
Expand Down Expand Up @@ -459,6 +459,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Vicent Cubells</li>
</ul>
</li>
<li>David Alonso &lt;<a class="reference external" href="mailto:david.alonso&#64;solvos.es">david.alonso&#64;solvos.es</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
9 changes: 1 addition & 8 deletions quality_control_oca/tests/test_quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2014 Oihane Crucelaegui - AvanzOSC
# Copyright 2017 ForgeFlow S.L.
# Copyright 2017 Simone Rubino - Agile Business Group
# Copyright 2023 Solvos Consultoría Informática, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import exceptions
Expand Down Expand Up @@ -204,15 +205,7 @@ def test_qc_inspection_product(self):
)
self.assertEqual(self.inspection1.product_id, self.product)
self.assertEqual(self.product.created_inspections, 1)
action_prod = self.product._action_qc_inspection_per_product()
self.assertEqual(action_prod["domain"][0][2][0], self.product.id)
self.assertEqual(
action_prod["context"]["default_object_id"],
"product.product,%s" % self.product.id,
)
self.assertEqual(self.product.product_tmpl_id.created_inspections, 1)
action_tmpl = self.product.product_tmpl_id.button_qc_inspection_per_product()
self.assertTrue(self.product.id in action_tmpl["domain"][0][2])

def test_qc_test_question_constraints(self):
with self.assertRaises(exceptions.ValidationError):
Expand Down
66 changes: 66 additions & 0 deletions quality_control_oca/views/product_product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Solvos Consultoría Informática, S.L.
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="product_normal_form_view">
<field name="name">product.product.form (in quality_control_oca)</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field
name="groups_id"
eval="[(4, ref('quality_control_oca.group_quality_control_user'))]"
/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_inline oe_stat_button"
type="action"
name="%(action_qc_inspection_product_all)d"
icon="fa-list"
>
<field
name="created_inspections"
widget="statinfo"
string="inspections"
/>
</button>
<button
class="oe_inline oe_stat_button"
type="action"
name="%(action_qc_inspection_product_done)d"
icon="fa-pencil"
>
<field
name="done_inspections"
widget="statinfo"
string="inspections"
/>
</button>
<button
class="oe_inline oe_stat_button"
type="action"
name="%(action_qc_inspection_product_passed)d"
icon="fa-thumbs-o-up"
>
<field
name="passed_inspections"
widget="statinfo"
string="inspections"
/>
</button>
<button
class="oe_inline oe_stat_button"
type="action"
name="%(action_qc_inspection_product_failed)d"
icon="fa-thumbs-o-down"
>
<field
name="failed_inspections"
widget="statinfo"
string="inspections"
/>
</button>
</div>
</field>
</record>
</odoo>
64 changes: 37 additions & 27 deletions quality_control_oca/views/product_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Copyright 2014 Oihane Crucelaegui - AvanzOSC
Copyright 2017 ForgeFlow S.L.
Copyright 2017 Simone Rubino - Agile Business Group
Copyright 2023 Solvos Consultoría Informática, S.L.
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="product_template_form_view">
Expand All @@ -14,14 +15,41 @@
name="groups_id"
eval="[(4, ref('quality_control_oca.group_quality_control_user'))]"
/>
<field name="arch" type="xml">
<page name="inventory" position="inside">
<group name="qc" string="Quality control">
<field name="qc_triggers" nolabel="1">
<tree editable="bottom">
<field
name="trigger"
options="{'no_create': True, 'no_edit': True, 'no_open': True}"
/>
<field name="test" />
<field name="user" />
<field name="partners" widget="many2many_tags" />
</tree>
</field>
</group>
</page>
</field>
</record>
<record model="ir.ui.view" id="product_template_only_form_view">
<field
name="name"
>product.template.product.form (in quality_control_oca)</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field
name="groups_id"
eval="[(4, ref('quality_control_oca.group_quality_control_user'))]"
/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_inline oe_stat_button"
type="object"
name="button_qc_inspection_per_product"
type="action"
name="%(action_qc_inspection_product_template_all)d"
icon="fa-list"
context="{'qc_status': 'all'}"
>
<field
name="created_inspections"
Expand All @@ -31,10 +59,9 @@
</button>
<button
class="oe_inline oe_stat_button"
type="object"
name="button_qc_inspection_per_product"
type="action"
name="%(action_qc_inspection_product_template_done)d"
icon="fa-pencil"
context="{'qc_status': 'done'}"
>
<field
name="done_inspections"
Expand All @@ -44,10 +71,9 @@
</button>
<button
class="oe_inline oe_stat_button"
type="object"
name="button_qc_inspection_per_product"
type="action"
name="%(action_qc_inspection_product_template_passed)d"
icon="fa-thumbs-o-up"
context="{'qc_status': 'passed'}"
>
<field
name="passed_inspections"
Expand All @@ -57,10 +83,9 @@
</button>
<button
class="oe_inline oe_stat_button"
type="object"
name="button_qc_inspection_per_product"
type="action"
name="%(action_qc_inspection_product_template_failed)d"
icon="fa-thumbs-o-down"
context="{'qc_status': 'failed'}"
>
<field
name="failed_inspections"
Expand All @@ -69,21 +94,6 @@
/>
</button>
</div>
<page name="inventory" position="inside">
<group name="qc" string="Quality control">
<field name="qc_triggers" nolabel="1">
<tree editable="bottom">
<field
name="trigger"
options="{'no_create': True, 'no_edit': True, 'no_open': True}"
/>
<field name="test" />
<field name="user" />
<field name="partners" widget="many2many_tags" />
</tree>
</field>
</group>
</page>
</field>
</record>
</odoo>
Loading

0 comments on commit 0a26ef8

Please sign in to comment.