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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilitat
- Inventari
- PoS
- Project
- MRP
This question has been flagged
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrar-seRelated Posts | Respostes | Vistes | Activitat | |
---|---|---|---|---|
|
0
d’ag. 24
|
1172 | ||
|
0
de des. 23
|
1221 | ||
|
2
de febr. 25
|
53 | ||
|
0
de set. 23
|
1435 | ||
|
1
de jul. 24
|
982 |