changeset dd5f9ab0b15e in modules/production:default
details:
https://hg.tryton.org/modules/production?cmd=changeset&node=dd5f9ab0b15e
description:
Use declarative index definition for ModelSQL
issue5757
review361251002
diffstat:
bom.py | 4 ++--
product.py | 13 +++++++------
production.py | 23 +++++++++++++++++++----
stock.py | 8 ++++----
4 files changed, 32 insertions(+), 16 deletions(-)
diffs (125 lines):
diff -r 7a5d40ebd258 -r dd5f9ab0b15e bom.py
--- a/bom.py Sun Oct 09 13:18:14 2022 +0200
+++ b/bom.py Tue Oct 11 00:44:49 2022 +0200
@@ -45,8 +45,8 @@
"Bill of Material Input"
__name__ = 'production.bom.input'
- bom = fields.Many2One('production.bom', 'BOM', required=True,
- select=1, ondelete='CASCADE')
+ bom = fields.Many2One(
+ 'production.bom', "BOM", required=True, ondelete='CASCADE')
product = fields.Many2One('product.product', 'Product', required=True)
uom_category = fields.Function(fields.Many2One(
'product.uom.category', 'Uom Category'), 'on_change_with_uom_category')
diff -r 7a5d40ebd258 -r dd5f9ab0b15e product.py
--- a/product.py Sun Oct 09 13:18:14 2022 +0200
+++ b/product.py Tue Oct 11 00:44:49 2022 +0200
@@ -80,13 +80,14 @@
'Product - BOM'
__name__ = 'product.product-production.bom'
- product = fields.Many2One('product.product', 'Product',
- ondelete='CASCADE', select=1, required=True,
+ product = fields.Many2One(
+ 'product.product', "Product", ondelete='CASCADE', required=True,
domain=[
('producible', '=', True),
])
- bom = fields.Many2One('production.bom', 'BOM', ondelete='CASCADE',
- select=1, required=True, domain=[
+ bom = fields.Many2One(
+ 'production.bom', "BOM", ondelete='CASCADE', required=True,
+ domain=[
('output_products', '=', If(Bool(Eval('product')),
Eval('product', 0),
Get(Eval('_parent_product', {}), 'id', 0))),
@@ -104,8 +105,8 @@
'Production Lead Time'
__name__ = 'production.lead_time'
- product = fields.Many2One('product.product', 'Product',
- ondelete='CASCADE', select=True, required=True,
+ product = fields.Many2One(
+ 'product.product', "Product", ondelete='CASCADE', required=True,
domain=[
('producible', '=', True),
])
diff -r 7a5d40ebd258 -r dd5f9ab0b15e production.py
--- a/production.py Sun Oct 09 13:18:14 2022 +0200
+++ b/production.py Tue Oct 11 00:44:49 2022 +0200
@@ -10,7 +10,8 @@
from sql.functions import CharLength
from trytond.i18n import gettext
-from trytond.model import ModelSQL, ModelView, Workflow, dualmethod, fields
+from trytond.model import (
+ Index, ModelSQL, ModelView, Workflow, dualmethod, fields)
from trytond.modules.company.model import employee_field, set_employee
from trytond.modules.product import price_digits, round_price
from trytond.modules.stock.shipment import ShipmentAssignMixin
@@ -27,10 +28,12 @@
class Production(ShipmentAssignMixin, Workflow, ModelSQL, ModelView):
"Production"
__name__ = 'production'
+ _rec_name = 'number'
_assign_moves_field = 'inputs'
- number = fields.Char('Number', select=True, readonly=True)
- reference = fields.Char('Reference', select=1,
+ number = fields.Char("Number", readonly=True)
+ reference = fields.Char(
+ "Reference",
states={
'readonly': ~Eval('state').in_(['request', 'draft']),
})
@@ -151,14 +154,26 @@
('cancelled', 'Cancelled'),
], 'State', readonly=True, sort=False)
origin = fields.Reference(
- "Origin", selection='get_origin', select=True,
+ "Origin", selection='get_origin',
states={
'readonly': ~Eval('state').in_(['request', 'draft']),
})
@classmethod
def __setup__(cls):
+ cls.number.search_unaccented = False
+ cls.reference.search_unaccented = False
super(Production, cls).__setup__()
+ t = cls.__table__()
+ cls._sql_indexes.update({
+ Index(t, (t.reference, Index.Similarity())),
+ Index(
+ t,
+ (t.state, Index.Equality()),
+ where=t.state.in_([
+ 'request', 'draft', 'waiting', 'assigned',
+ 'running'])),
+ })
cls._order = [
('effective_date', 'ASC NULLS LAST'),
('id', 'ASC'),
diff -r 7a5d40ebd258 -r dd5f9ab0b15e stock.py
--- a/stock.py Sun Oct 09 13:18:14 2022 +0200
+++ b/stock.py Tue Oct 11 00:44:49 2022 +0200
@@ -43,14 +43,14 @@
class Move(metaclass=PoolMeta):
__name__ = 'stock.move'
- production_input = fields.Many2One('production', 'Production Input',
- readonly=True, select=True, ondelete='CASCADE',
+ production_input = fields.Many2One(
+ 'production', "Production Input", readonly=True, ondelete='CASCADE',
domain=[('company', '=', Eval('company'))],
states={
'invisible': ~Eval('production_input'),
})
- production_output = fields.Many2One('production', 'Production Output',
- readonly=True, select=True, ondelete='CASCADE',
+ production_output = fields.Many2One(
+ 'production', "Production Output", readonly=True, ondelete='CASCADE',
domain=[('company', '=', Eval('company'))],
states={
'invisible': ~Eval('production_output'),