Add a reference field to the quality inspections

Closes #12436
This commit is contained in:
Alex Alias Montserrar
2026-03-27 18:10:21 +01:00
parent 55da16f6a7
commit b8a951b95e
4 changed files with 31 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add a reference to the inspections
* Add support for Python 3.14
* Remove support for Python 3.9
+27 -2
View File
@@ -9,8 +9,9 @@ from sql.functions import CharLength
from trytond.i18n import gettext, lazy_gettext
from trytond.model import (
ChatMixin, DeactivableMixin, DictSchemaMixin, MatchMixin, ModelSingleton,
ModelSQL, ModelStorage, ModelView, Unique, Workflow, dualmethod, fields)
ChatMixin, DeactivableMixin, DictSchemaMixin, Index, MatchMixin,
ModelSingleton, ModelSQL, ModelStorage, ModelView, Unique, Workflow,
dualmethod, fields)
from trytond.model.exceptions import AccessError, ButtonActionException
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin, employee_field, reset_employee,
@@ -350,6 +351,7 @@ class Inspection(Workflow, ModelSQL, ModelView, ChatMixin):
}
number = fields.Char("Number", required=True, readonly=True)
reference = fields.Char("Reference")
company = fields.Many2One(
'company.company', "Company", required=True, states=_states)
origin = fields.Reference(
@@ -406,7 +408,12 @@ class Inspection(Workflow, ModelSQL, ModelView, ChatMixin):
@classmethod
def __setup__(cls):
cls.number.search_unaccented = False
cls.reference.search_unaccented = False
super().__setup__()
t = cls.__table__()
cls._sql_indexes.update({
Index(t, (t.reference, Index.Similarity())),
})
cls._transitions |= {
('pending', 'passed'),
('pending', 'failed'),
@@ -511,6 +518,24 @@ class Inspection(Workflow, ModelSQL, ModelView, ChatMixin):
return attributes
def get_rec_name(self, name):
items = [self.number]
if self.reference:
items.append('[%s]' % self.reference)
return ' '.join(items)
@classmethod
def search_rec_name(cls, name, clause):
_, operator, value = clause
if operator.startswith('!') or operator.startswith('not'):
bool_op = 'AND'
else:
bool_op = 'OR'
return [bool_op,
('number', operator, value),
('reference', operator, value),
]
@classmethod
@ModelView.button
@Workflow.transition('pending')
@@ -9,6 +9,8 @@ this repository contains the full copyright notices and license terms. -->
<label name="origin"/>
<field name="origin"/>
<label name="reference"/>
<field name="reference"/>
<notebook>
<page name="points">
@@ -5,6 +5,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="company" expand="1" optional="1"/>
<field name="number" expand="1"/>
<field name="control" expand="1" optional="0"/>
<field name="reference" expand="1" optional="1"/>
<field name="origin" expand="1" optional="0"/>
<field name="state"/>
</tree>