Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
2085 Vistas

I want to implement a quality module that consists of two types of quality control (pre and post-production), each with its own set of tests, is it possible to create a package to generate reports from these tests? or do you have other recommendations to manage the quality module?


Avatar
Descartar
Mejor respuesta

Hi, 
Please go through the below code. You will get an idea .
from odoo import fields, models, api
class QualityControlTest(models.Model):
    _name = 'quality.control.test'
    _description = 'Quality Control Test'

    name = fields.Char(string='Name', required=True)
    test_type = fields.Selection([('pre', 'Pre-Production'), ('post', 'Post-Production')],
                                 string='Test Type', required=True)
    test_status = fields.Selection([('passed', 'Passed'), ('failed', 'Failed')],
                                   string='Test Status', default='passed')
    error_message = fields.Text(string='Error Message')
    timestamp = fields.Datetime(string='Timestamp', default=fields.Datetime.now)

class QualityControlReport(models.Model):
    _name = 'quality.control.report'
    _description = 'Quality Control Report'

    name = fields.Char(string='Name', required=True)
    test_ids = fields.One2many('quality.control.test', 'report_id', string='Tests')

class QualityControlWizard(models.TransientModel):
    _name = 'quality.control.wizard'
    _description = 'Quality Control Wizard'

    name = fields.Char(string='Name')
    test_type = fields.Selection([('pre', 'Pre-Production'), ('post', 'Post-Production')],
                                 string='Test Type', required=True)

    def run_tests(self):
        test_model = self.env['quality.control.test']
        tests = test_model.search([('test_type', '=', self.test_type)])
        for test in tests:
            if test.name == 'Sample Test':
                test.test_status = 'failed'
                test.error_message = 'Test failed due to invalid input'
            else:
                test.test_status = 'passed'
        report_model = self.env['quality.control.report']
        report_vals = {
            'name': self.name,
            'test_ids': [(6, 0, tests.ids)] 
        }
        report_model.create(report_vals)
        return {
            'type': 'ir.actions.act_window',
            'name': 'Quality Control Report',
            'res_model': 'quality.control.report',
            'view_mode': 'form',
            'res_id': report.id,
            'target': 'new',
        }

When the wizard is launched, the run_tests() method is invoked. According to the chosen test type, it runs the tests, updates the test results, compiles the results into a quality control report, and then opens the report in a new window. The run_tests() method's logic can be modified to carry out your unique tests and update the test results appropriately. You must install this module in your Odoo instance and configure the proper views and menu items in the module's XML files in order to use it.

Hope it helps

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
oct 25
123
0
ago 24
1454
0
dic 23
1457
2
feb 25
54
0
sept 23
1721