Add quality templates from products into productions. (#1)
Add cron to create quality test in productions. 043843
This commit is contained in:
parent
5a3af545cb
commit
a43ce9d57d
|
@ -2,10 +2,12 @@
|
|||
# copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from . import production
|
||||
|
||||
from . import ir
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
ir.Cron,
|
||||
production.Template,
|
||||
production.Production,
|
||||
production.ProductionTemplate,
|
||||
module='production_quality_control', type_='model')
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#The COPYRIGHT file at the top level of this repository contains the full
|
||||
#copyright notices and license terms.
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class Cron(metaclass=PoolMeta):
|
||||
__name__ = 'ir.cron'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.method.selection.extend([
|
||||
('production|create_quality_tests_worker', "Create quality control")
|
||||
])
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.cron" id="cron_process_queue">
|
||||
<field name="method">production|create_quality_tests_worker</field>
|
||||
<field name="interval_number">5</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
54
locale/ca.po
54
locale/ca.po
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
|
@ -6,14 +6,66 @@ msgctxt "field:product.template,quality_template:"
|
|||
msgid "Quality Template"
|
||||
msgstr "Plantilla de qualitat"
|
||||
|
||||
msgctxt "field:product.template,quality_templates:"
|
||||
msgid "Quality Templates"
|
||||
msgstr "Plantilles de qualitat"
|
||||
|
||||
msgctxt "field:product.template-quality.template,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:product.template-quality.template,interval:"
|
||||
msgid "Interval"
|
||||
msgstr "Interval"
|
||||
|
||||
msgctxt "field:product.template-quality.template,quality_template:"
|
||||
msgid "Quality Template"
|
||||
msgstr "Plantilla de qualitat"
|
||||
|
||||
msgctxt "field:product.template-quality.template,template:"
|
||||
msgid "Template"
|
||||
msgstr "Plantilla"
|
||||
|
||||
msgctxt "field:production,quality_template:"
|
||||
msgid "Quality Template"
|
||||
msgstr "Plantilla de qualitat"
|
||||
|
||||
msgctxt "field:production,quality_templates:"
|
||||
msgid "Quality Templates"
|
||||
msgstr "Plantilles de qualitat"
|
||||
|
||||
msgctxt "field:production,quality_tests:"
|
||||
msgid "Quality Tests"
|
||||
msgstr "Tests de qualitat"
|
||||
|
||||
msgctxt "field:production,time_since_quality_control:"
|
||||
msgid "Time since quality control"
|
||||
msgstr "Temps des de control de qualitat"
|
||||
|
||||
msgctxt "help:product.template-quality.template,interval:"
|
||||
msgid "Interval in minutes"
|
||||
msgstr "Interval en minuts"
|
||||
|
||||
msgctxt "model:ir.action,name:act_quality_tests"
|
||||
msgid "Quality Tests"
|
||||
msgstr "Tests de qualitat"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_test_not_successful"
|
||||
msgid "The production \"%(production)s\" has tests that are not correct."
|
||||
msgstr "La producció \"%(production)s\" té tests que no són correctes."
|
||||
|
||||
msgctxt "model:ir.rule.group,name:rule_product_quality_template"
|
||||
msgid "Product Template Quality Template Rule"
|
||||
msgstr "Regla de plantilles de producte i plantilles de qualitat "
|
||||
|
||||
msgctxt "model:product.template-quality.template,name:"
|
||||
msgid "Production Template"
|
||||
msgstr "Produccions - Plantilles"
|
||||
|
||||
msgctxt "selection:ir.cron,method:"
|
||||
msgid "Create quality control"
|
||||
msgstr "Crear control de qualitat"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Quality"
|
||||
msgstr "Qualitat"
|
||||
|
|
54
locale/es.po
54
locale/es.po
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
|
@ -6,14 +6,66 @@ msgctxt "field:product.template,quality_template:"
|
|||
msgid "Quality Template"
|
||||
msgstr "Plantilla de calidad"
|
||||
|
||||
msgctxt "field:product.template,quality_templates:"
|
||||
msgid "Quality Templates"
|
||||
msgstr "Plantillas de calidad"
|
||||
|
||||
msgctxt "field:product.template-quality.template,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:product.template-quality.template,interval:"
|
||||
msgid "Interval"
|
||||
msgstr "Intervalo"
|
||||
|
||||
msgctxt "field:product.template-quality.template,quality_template:"
|
||||
msgid "Quality Template"
|
||||
msgstr "Plantilla de calidad"
|
||||
|
||||
msgctxt "field:product.template-quality.template,template:"
|
||||
msgid "Template"
|
||||
msgstr "Plantilla"
|
||||
|
||||
msgctxt "field:production,quality_template:"
|
||||
msgid "Quality Template"
|
||||
msgstr "Plantilla de calidad"
|
||||
|
||||
msgctxt "field:production,quality_templates:"
|
||||
msgid "Quality Templates"
|
||||
msgstr "Plantillas de calidad"
|
||||
|
||||
msgctxt "field:production,quality_tests:"
|
||||
msgid "Quality Tests"
|
||||
msgstr "Tests de calidad"
|
||||
|
||||
msgctxt "field:production,time_since_quality_control:"
|
||||
msgid "Time since quality control"
|
||||
msgstr "Tiempo des de control de calidad"
|
||||
|
||||
msgctxt "help:product.template-quality.template,interval:"
|
||||
msgid "Interval in minutes"
|
||||
msgstr "Intervalo en minutos"
|
||||
|
||||
msgctxt "model:ir.action,name:act_quality_tests"
|
||||
msgid "Quality Tests"
|
||||
msgstr "Tests de calidad"
|
||||
|
||||
msgctxt "model:ir.message,text:msg_test_not_successful"
|
||||
msgid "The production \"%(production)s\" has tests that are not correct."
|
||||
msgstr "La producción \"%(production)s\" tiene tests que no son correctos."
|
||||
|
||||
msgctxt "model:ir.rule.group,name:rule_product_quality_template"
|
||||
msgid "Product Template Quality Template Rule"
|
||||
msgstr "Regla de plantillas de producto y plantillas de calidad"
|
||||
|
||||
msgctxt "model:product.template-quality.template,name:"
|
||||
msgid "Production Template"
|
||||
msgstr "Producciones - Plantillas"
|
||||
|
||||
msgctxt "selection:ir.cron,method:"
|
||||
msgid "Create quality control"
|
||||
msgstr "Crear control de calidad"
|
||||
|
||||
msgctxt "view:production:"
|
||||
msgid "Quality"
|
||||
msgstr "Calidad"
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<tryton>
|
||||
<data grouped="1">
|
||||
<record model="ir.message" id="msg_test_not_successful">
|
||||
<field name="text">The production "%(production)s" has tests that are not correct.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
107
production.py
107
production.py
|
@ -1,38 +1,115 @@
|
|||
#The COPYRIGHT file at the top level of this repository contains the full
|
||||
#copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from datetime import datetime
|
||||
|
||||
__all__ = ['Template', 'Production']
|
||||
from trytond.model import fields, ModelSQL, ModelView
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
|
||||
|
||||
class Template(metaclass=PoolMeta):
|
||||
__name__ = 'product.template'
|
||||
quality_template = fields.Many2One('quality.template', 'Quality Template')
|
||||
quality_templates = fields.One2Many('product.template-quality.template',
|
||||
'template', "Quality Templates")
|
||||
|
||||
|
||||
class Production(metaclass=PoolMeta):
|
||||
__name__ = 'production'
|
||||
|
||||
quality_template = fields.Many2One('quality.template', 'Quality Template')
|
||||
quality_templates = fields.Function(fields.One2Many(
|
||||
'product.template-quality.template', None, "Quality Templates"),
|
||||
'get_quality_templates')
|
||||
|
||||
quality_tests = fields.One2Many('quality.test', 'document', 'Quality Tests',
|
||||
context={
|
||||
'default_quality_template': Eval('quality_template'),
|
||||
'default_quality_templates': Eval('quality_templates'),
|
||||
},
|
||||
depends=['quality_template'])
|
||||
depends=['quality_templates'])
|
||||
time_since_quality_control = fields.DateTime('Time since quality control',
|
||||
readonly=True)
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_product(self):
|
||||
super(Production, self).on_change_product()
|
||||
if self.product and self.product.template.quality_template:
|
||||
self.quality_template = self.product.template.quality_template
|
||||
def get_quality_templates(self, name):
|
||||
context = Transaction().context
|
||||
|
||||
quality_templates = []
|
||||
if self.product:
|
||||
for quality_template in self.product.template.quality_templates:
|
||||
if quality_template.company.id == context.get('company'):
|
||||
quality_templates.append(quality_template.id)
|
||||
return quality_templates
|
||||
|
||||
@classmethod
|
||||
def compute_request(cls, product, warehouse, quantity, date, company):
|
||||
"Inherited from stock_supply_production"
|
||||
production = super(Production, cls).compute_request(product,
|
||||
warehouse, quantity, date, company)
|
||||
if product.template.quality_template:
|
||||
production.quality_template = product.template.quality_template
|
||||
if product.template.quality_templates:
|
||||
production.quality_templates = product.template.quality_templates
|
||||
return production
|
||||
|
||||
@classmethod
|
||||
def run(cls, productions):
|
||||
to_save = []
|
||||
for production in productions:
|
||||
production.time_since_quality_control = datetime.now()
|
||||
to_save.append(production)
|
||||
cls.save(to_save)
|
||||
super(Production, cls).run(productions)
|
||||
|
||||
@classmethod
|
||||
def create_quality_tests(cls, productions):
|
||||
pool = Pool()
|
||||
QualityTest = pool.get('quality.test')
|
||||
|
||||
to_save = []
|
||||
for production in productions:
|
||||
for quality_template in production.quality_templates:
|
||||
total_time_since_quality_control = (datetime.now() -
|
||||
production.time_since_quality_control).seconds/60
|
||||
if (total_time_since_quality_control >=
|
||||
quality_template.interval):
|
||||
for quality_contol in range(int(
|
||||
total_time_since_quality_control/
|
||||
quality_template.interval)):
|
||||
test = QualityTest()
|
||||
test.document = production
|
||||
test.templates = [quality_template.quality_template]
|
||||
test.company = quality_template.company
|
||||
to_save.append(test)
|
||||
|
||||
production.time_since_quality_control = datetime.now()
|
||||
|
||||
cls.save(production)
|
||||
if to_save:
|
||||
QualityTest.save(to_save)
|
||||
QualityTest.apply_templates(to_save)
|
||||
|
||||
@classmethod
|
||||
def create_quality_tests_worker(cls):
|
||||
productions = cls.search([
|
||||
('state','=','running')
|
||||
])
|
||||
|
||||
for production in productions:
|
||||
with Transaction().set_context(queue_name='production'):
|
||||
cls.__queue__.create_quality_tests([production])
|
||||
|
||||
|
||||
class ProductionTemplate(ModelSQL, ModelView):
|
||||
"Production Template"
|
||||
__name__ = 'product.template-quality.template'
|
||||
|
||||
template = fields.Many2One('product.template', "Template",required=True,
|
||||
ondelete="CASCADE")
|
||||
company = fields.Many2One('company.company', "Company", required=True)
|
||||
interval = fields.Integer("Interval", required=True,
|
||||
help="Interval in minutes")
|
||||
quality_template = fields.Many2One('quality.template', "Quality Template",
|
||||
required=True)
|
||||
|
||||
@classmethod
|
||||
def default_company(cls):
|
||||
return Transaction().context.get('company')
|
|
@ -12,5 +12,37 @@
|
|||
<field name="inherit" ref="product.template_view_form"/>
|
||||
<field name="name">template_form</field>
|
||||
</record>
|
||||
|
||||
<!-- product.template-quality.template -->
|
||||
<record model="ir.ui.view" id="product_quantity_template_view_form">
|
||||
<field name="model">product.template-quality.template</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority" eval="10"/>
|
||||
<field name="name">production_template_list</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule.group" id="rule_product_quality_template">
|
||||
<field name="name">Product Template Quality Template Rule</field>
|
||||
<field name="model" search="[('model', '=', 'product.template-quality.template')]"/>
|
||||
<field name="global_p" eval="True"/>
|
||||
</record>
|
||||
<record model="ir.rule" id="rule_product_template_quality_template">
|
||||
<field name="domain"
|
||||
eval="[('company', '=', Eval('user', {}).get('company', None))]"
|
||||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_product_quality_template"/>
|
||||
</record>
|
||||
|
||||
<!-- Actions -->
|
||||
<record model="ir.action.act_window" id="act_quality_tests">
|
||||
<field name="name">Quality Tests</field>
|
||||
<field name="res_model">quality.test</field>
|
||||
<field name="domain" eval="[('document.id', '=', Eval('active_id'), 'production')]" pyson="1"/>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="keyword_quality_tests">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">production,-1</field>
|
||||
<field name="action" ref="act_quality_tests"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -6,4 +6,6 @@ depends:
|
|||
extras_depend:
|
||||
stock_supply_production
|
||||
xml:
|
||||
ir.xml
|
||||
production.xml
|
||||
message.xml
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<data>
|
||||
<xpath expr="/form/notebook" position="inside">
|
||||
<page id="quality" string="Quality">
|
||||
<label name="quality_template"/>
|
||||
<field name="quality_template"/>
|
||||
<label name="time_since_quality_control"/>
|
||||
<field name="time_since_quality_control"/>
|
||||
<field name="quality_tests" colspan="4"/>
|
||||
</page>
|
||||
</xpath>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="template"/>
|
||||
<field name="quality_template"/>
|
||||
<field name="interval"/>
|
||||
</tree>
|
|
@ -4,8 +4,7 @@
|
|||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='general']/field[@name='products']"
|
||||
position="before">
|
||||
<label name="quality_template"/>
|
||||
<field name="quality_template"/>
|
||||
<field name="quality_templates" colspan="6"/>
|
||||
<newline/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue