diff --git a/quality_assurance/__init__.py b/quality_assurance/__init__.py new file mode 100644 index 000000000..89d26e2f5 --- /dev/null +++ b/quality_assurance/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models diff --git a/quality_assurance/__manifest__.py b/quality_assurance/__manifest__.py new file mode 100644 index 000000000..5db8cbcc3 --- /dev/null +++ b/quality_assurance/__manifest__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +################################################################################### +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: fasluca() +# +# This program is free software: you can modify +# it under the terms of the GNU Affero General Public License (AGPL) as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +{ + 'name': 'Quality Assurance', + 'version': '10.0.1.0', + 'summary': 'Manage Your Quality Assurance Processes', + 'description': """ + This module provides features to manage basic quality assurance procedures. + """, + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': "https://cybrosys.com/", + 'category': '', + 'depends': ['product', 'stock', 'purchase'], + 'data': [ + 'data/data.xml', + 'security/quality_security.xml', + 'security/ir.model.access.csv', + 'views/quality_view.xml', + 'views/stock_view.xml', + ], + 'demo': [], + 'images': ['static/description/banner.jpg'], + 'license': 'LGPL-3', + 'installable': True, + 'application': True +} diff --git a/quality_assurance/data/data.xml b/quality_assurance/data/data.xml new file mode 100644 index 000000000..506d91259 --- /dev/null +++ b/quality_assurance/data/data.xml @@ -0,0 +1,14 @@ + + + + + Quality alert sequence + quality.alert + QA + + + + 5 + + + \ No newline at end of file diff --git a/quality_assurance/models/__init__.py b/quality_assurance/models/__init__.py new file mode 100644 index 000000000..9a5e0594b --- /dev/null +++ b/quality_assurance/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +import quality +import stock +import purchase diff --git a/quality_assurance/models/purchase.py b/quality_assurance/models/purchase.py new file mode 100644 index 000000000..7c9b4c6bf --- /dev/null +++ b/quality_assurance/models/purchase.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models, _ + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + @api.multi + def _create_picking(self): + StockPicking = self.env['stock.picking'] + for order in self: + if any([ptype in ['product', 'consu'] for ptype in order.order_line.mapped('product_id.type')]): + pickings = order.picking_ids.filtered(lambda x: x.state not in ('done','cancel')) + if not pickings: + res = order._prepare_picking() + picking = StockPicking.create(res) + else: + picking = pickings[0] + moves = order.order_line._create_stock_moves(picking) + moves = moves.filtered(lambda x: x.state not in ('done', 'cancel')).action_confirm() + moves.force_assign() + picking.generate_quality_alert() + picking.message_post_with_view('mail.message_origin_link', + values={'self': picking, 'origin': order}, + subtype_id=self.env.ref('mail.mt_note').id) + return True \ No newline at end of file diff --git a/quality_assurance/models/quality.py b/quality_assurance/models/quality.py new file mode 100644 index 000000000..5c4b8005a --- /dev/null +++ b/quality_assurance/models/quality.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +from datetime import datetime +from odoo import api, fields, models + + +class QualityMeasure(models.Model): + _name = 'quality.measure' + _inherit = ['mail.thread'] + _order = "id desc" + + name = fields.Char('Name', required=True) + product_id = fields.Many2one('product.product', string='Product', index=True, ondelete='cascade', track_visibility='onchange') + product_template_id = fields.Many2one('product.template', string='Product Template', related='product_id.product_tmpl_id') + type = fields.Selection( + [('quantity', 'Quantitative'), + ('quality', 'Qualitative')], + string='Test Type', default='quantity', required=True, track_visibility='onchange') + quantity_min = fields.Float('Min-Value', track_visibility='onchange') + quantity_max = fields.Float('Max-Value', track_visibility='onchange') + trigger_time = fields.Many2many('stock.picking.type', string='Trigger On') + active = fields.Boolean('Active', default=True, track_visibility='onchange') + company_id = fields.Many2one('res.company', 'Company', + default=lambda self: self.env.user.company_id.id, index=1) + + @api.onchange('type') + def onchange_type(self): + if self.type == 'quality': + self.quantity_min = 0.0 + self.quantity_max = 0.0 + + +class QualityAlert(models.Model): + _name = 'quality.alert' + _inherit = ['mail.thread'] + _order = "date asc, id desc" + + name = fields.Char('Name', required=True) + date = fields.Datetime(string='Date', default=datetime.now(), track_visibility='onchange') + product_id = fields.Many2one('product.product', string='Product', index=True, ondelete='cascade') + picking_id = fields.Many2one('stock.picking', string='Source Operation') + origin = fields.Char(string='Source Document', + help="Reference of the document that produced this alert.", + readonly=True) + company_id = fields.Many2one('res.company', 'Company', + default=lambda self: self.env.user.company_id.id, index=1) + user_id = fields.Many2one('res.users', string='Created by', default=lambda self: self.env.user.id) + tests = fields.One2many('quality.test', 'alert_id', string="Tests") + final_status = fields.Selection(compute="_compute_status", + selection=[('wait', 'Waiting'), + ('pass', 'Passed'), + ('fail', 'Failed')], + store=True, string='Status', + default='fail', track_visibility='onchange') + + @api.multi + def generate_tests(self): + quality_measure = self.env['quality.measure'] + measures = quality_measure.search([('product_id', '=', self.product_id.id), + ('trigger_time', 'in', self.picking_id.picking_type_id.id)]) + for measure in measures: + self.env['quality.test'].create({ + 'quality_measure': measure.id, + 'alert_id': self.id, + }) + + @api.depends('tests', 'tests.test_status') + def _compute_status(self): + for alert in self: + failed_tests = [test for test in alert.tests if test.test_status == 'fail'] + if not alert.tests: + alert.final_status = 'wait' + elif failed_tests: + alert.final_status = 'fail' + else: + alert.final_status = 'pass' + + +class QualityTest(models.Model): + _name = 'quality.test' + _inherit = ['mail.thread'] + _order = "id desc" + + quality_measure = fields.Many2one('quality.measure', string='Measure', index=True, ondelete='cascade',track_visibility='onchange') + alert_id = fields.Many2one('quality.alert', string="Quality Alert",track_visibility='onchange') + name = fields.Char('Name', related="quality_measure.name", required=True) + product_id = fields.Many2one('product.product', string='Product', related='alert_id.product_id') + test_type = fields.Selection(related='quality_measure.type', string='Test Type', required=True, readonly=True) + quantity_min = fields.Float(related='quality_measure.quantity_min', string='Min-Value', store=True, readonly=True) + quantity_max = fields.Float(related='quality_measure.quantity_max', string='Max-Value', store=True, readonly=True) + test_user_id = fields.Many2one('res.users', string='Assigned to', track_visibility='onchange') + test_result = fields.Float(string='Result', track_visibility='onchange') + test_result2 = fields.Selection([ + ('satisfied', 'Satisfied'), + ('unsatisfied', 'Unsatisfied')], string='Result', track_visibility='onchange') + test_status = fields.Selection(compute="_compute_status", + selection=[('pass', 'Passed'), + ('fail', 'Failed')], + store=True, string='Status', track_visibility='onchange') + + @api.depends('test_result', 'test_result2') + def _compute_status(self): + for test in self: + if test.test_type == 'quantity': + if test.quantity_min <= test.test_result <= test.quantity_max: + test.test_status = 'pass' + else: + test.test_status = 'fail' + else: + if test.test_result2 == 'satisfied': + test.test_status = 'pass' + else: + test.test_status = 'fail' diff --git a/quality_assurance/models/stock.py b/quality_assurance/models/stock.py new file mode 100644 index 000000000..8de07f861 --- /dev/null +++ b/quality_assurance/models/stock.py @@ -0,0 +1,138 @@ +# -*- coding: utf-8 -*- +from odoo import api, fields, models,_ +from odoo.tools.float_utils import float_compare +from odoo.exceptions import UserError + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + @api.depends('move_lines') + def _compute_alert(self): + ''' + This function computes the number of quality alerts generated from given picking. + ''' + for picking in self: + alerts = self.env['quality.alert'].search([('picking_id', '=', picking.id)]) + picking.alert_ids = alerts + picking.alert_count = len(alerts) + + @api.multi + def quality_alert_action(self): + ''' + This function returns an action that display existing quality alerts generated from a given picking. + ''' + action = self.env.ref('quality_assurance.quality_alert_action') + result = action.read()[0] + + # override the context to get rid of the default filtering on picking type + result.pop('id', None) + result['context'] = {} + alert_ids = sum([picking.alert_ids.ids for picking in self], []) + # choose the view_mode accordingly + if len(alert_ids) > 1: + result['domain'] = "[('id','in',[" + ','.join(map(str, alert_ids)) + "])]" + elif len(alert_ids) == 1: + res = self.env.ref('quality_assurance.quality_alert_form', False) + result['views'] = [(res and res.id or False, 'form')] + result['res_id'] = alert_ids and alert_ids[0] or False + return result + + alert_count = fields.Integer(compute='_compute_alert', string='Quality Alerts', default=0) + alert_ids = fields.Many2many('quality.alert', compute='_compute_alert', string='Quality Alerts', copy=False) + + @api.multi + def generate_quality_alert(self): + ''' + This function generates quality alerts for the products mentioned in move_lines of given picking and also have quality measures configured. + ''' + quality_alert = self.env['quality.alert'] + quality_measure = self.env['quality.measure'] + for move in self.move_lines: + measures = quality_measure.search([('product_id', '=', move.product_id.id), ('trigger_time', 'in', self.picking_type_id.id)]) + if measures: + quality_alert.create({ + 'name': self.env['ir.sequence'].next_by_code('quality.alert') or _('New'), + 'product_id': move.product_id.id, + 'picking_id': self.id, + 'origin': self.name, + 'company_id': self.company_id.id, + }) + + @api.multi + def action_confirm(self): + if self.alert_count == 0: + self.generate_quality_alert() + res = super(StockPicking, self).action_confirm() + return res + + @api.multi + def force_assign(self): + if self.alert_count == 0: + self.generate_quality_alert() + res = super(StockPicking, self).force_assign() + return res + + @api.multi + def do_transfer(self): + """ If no pack operation, we do simple action_done of the picking. + Otherwise, do the pack operations. """ + # TDE CLEAN ME: reclean me, please + self._create_lots_for_picking() + + no_pack_op_pickings = self.filtered(lambda picking: not picking.pack_operation_ids) + no_pack_op_pickings.action_done() + other_pickings = self - no_pack_op_pickings + for picking in other_pickings: + need_rereserve, all_op_processed = picking.picking_recompute_remaining_quantities() + todo_moves = self.env['stock.move'] + toassign_moves = self.env['stock.move'] + + # create extra moves in the picking (unexpected product moves coming from pack operations) + if not all_op_processed: + todo_moves |= picking._create_extra_moves() + + if need_rereserve or not all_op_processed: + moves_reassign = any(x.origin_returned_move_id or x.move_orig_ids for x in picking.move_lines if + x.state not in ['done', 'cancel']) + if moves_reassign and picking.location_id.usage not in ("supplier", "production", "inventory"): + # unnecessary to assign other quants than those involved with pack operations as they will be unreserved anyways. + picking.with_context(reserve_only_ops=True, no_state_change=True).rereserve_quants( + move_ids=picking.move_lines.ids) + picking.do_recompute_remaining_quantities() + + # split move lines if needed + for move in picking.move_lines: + rounding = move.product_id.uom_id.rounding + remaining_qty = move.remaining_qty + if move.state in ('done', 'cancel'): + # ignore stock moves cancelled or already done + continue + elif move.state == 'draft': + toassign_moves |= move + if float_compare(remaining_qty, 0, precision_rounding=rounding) == 0: + if move.state in ('draft', 'assigned', 'confirmed'): + todo_moves |= move + elif float_compare(remaining_qty, 0, precision_rounding=rounding) > 0 and float_compare(remaining_qty, move.product_qty, precision_rounding=rounding) < 0: + # TDE FIXME: shoudl probably return a move - check for no track key, by the way + new_move_id = move.split(remaining_qty) + new_move = self.env['stock.move'].with_context(mail_notrack=True).browse(new_move_id) + todo_moves |= move + # Assign move as it was assigned before + toassign_moves |= new_move + + # TDE FIXME: do_only_split does not seem used anymore + if todo_moves and not self.env.context.get('do_only_split'): + for move in todo_moves: + alerts = self.env['quality.alert'].search([('picking_id', '=', self.id), ('product_id', '=', move.product_id.id)]) + for alert in alerts: + if alert.final_status == 'wait': + raise UserError(_('There are items still in quality test')) + if alert.final_status == 'fail': + raise UserError(_('There are items failed in quality test')) + todo_moves.action_done() + elif self.env.context.get('do_only_split'): + picking = picking.with_context(split=todo_moves.ids) + + picking._create_backorder() + return True diff --git a/quality_assurance/security/ir.model.access.csv b/quality_assurance/security/ir.model.access.csv new file mode 100644 index 000000000..0b5028e2e --- /dev/null +++ b/quality_assurance/security/ir.model.access.csv @@ -0,0 +1,7 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +quality_measure_all,quality.measure,quality_assurance.model_quality_measure,base.group_user,1,0,0,0 +quality_measure_user,quality.measure,quality_assurance.model_quality_measure,quality_assurance.group_quality_user,1,1,1,1 +quality_alert_stock,quality.alert,quality_assurance.model_quality_alert,stock.group_stock_user,1,0,1,0 +quality_alert_user,quality.alert,quality_assurance.model_quality_alert,quality_assurance.group_quality_user,1,1,1,1 +quality_test_stock,quality.test,quality_assurance.model_quality_test,stock.group_stock_user,1,0,1,0 +quality_test_all,quality.test,quality_assurance.model_quality_test,quality_assurance.group_quality_user,1,1,1,1 diff --git a/quality_assurance/security/quality_security.xml b/quality_assurance/security/quality_security.xml new file mode 100644 index 000000000..3382a28e0 --- /dev/null +++ b/quality_assurance/security/quality_security.xml @@ -0,0 +1,25 @@ + + + + + + Quality + Helps you manage your quality assurance processes + 4 + + + + User + + + + + + Manager + + + + + + + \ No newline at end of file diff --git a/quality_assurance/static/description/banner.jpg b/quality_assurance/static/description/banner.jpg new file mode 100644 index 000000000..f415bb367 Binary files /dev/null and b/quality_assurance/static/description/banner.jpg differ diff --git a/quality_assurance/static/description/cybro_logo.png b/quality_assurance/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/quality_assurance/static/description/cybro_logo.png differ diff --git a/quality_assurance/static/description/icon.png b/quality_assurance/static/description/icon.png new file mode 100644 index 000000000..7a117b4fc Binary files /dev/null and b/quality_assurance/static/description/icon.png differ diff --git a/quality_assurance/static/description/index.html b/quality_assurance/static/description/index.html new file mode 100644 index 000000000..eed9962ac --- /dev/null +++ b/quality_assurance/static/description/index.html @@ -0,0 +1,206 @@ +
+
+

Quality Assurance

+

Cybrosys Technologies

+
+
+ +
+
+ +

+ Manage Your Quality Assurance Processes +

+
+
+

Features:

+
+ Quality Measures
+ Quality Alert
+ Quality Tests
+
+
+
+ +
+
+
+

Overview

+

+ Quality assurance/control is not a new term in this industrial world. Almost everything has some specific quality standards. and it varies with the different attributes like, who is using and where is using.. etc. This module allows Odoo users to ensure quality specification of the items they are using in their business. This module provides quality alerts and quality test along with control in inventory moves based on the test result. +

+
+
+
+ +
+
+
+

+ Using this module, Quality manager can setup the Quality Measures of each product under Quality> Configuration> Quality Measures menu + He can setup two types of measures, +

+ Qualitative
+ Quantitative
+
+
+
+ +
+
+
+
+ +
+
+
+

+ If you have configured Quality Measure for a product, whenever the product undergoes Trigger On operation, Odoo will create a Quality Alert +

+
+
+
+ +
+
+
+

+ The user can access the Quality Alerts generated from the operation itself. +

+
+
+
+ +
+
+
+

+ Quality Alertscan be accessed also from Quality> Quality Assurance> Quality Alerts +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Generate Tests button will create Quality Tests for the product based on Quality Measures. +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Quality manager can assign Quality Tests to different users. +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Quality users will have a list of Quality Tests that are assigned to them. + Now the user can update the test result to the Quality Test record. +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Important changes made on Quality Tests will be tracked by the system. +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Result updated on the Quality Tests will reflect on related Quality Alerts. +

+
+
+
+ +
+
+
+
+ +
+
+
+

+ Inventory user cannot proceed with an item that is failed in Quality Test. + User will get a warning message when they try +

+
+
+
+ +
+
+
+
+ +
+

Need Any Help?

+ +
+ diff --git a/quality_assurance/static/description/picking_frm.png b/quality_assurance/static/description/picking_frm.png new file mode 100644 index 000000000..4ae88dd76 Binary files /dev/null and b/quality_assurance/static/description/picking_frm.png differ diff --git a/quality_assurance/static/description/picking_qq_wrng.png b/quality_assurance/static/description/picking_qq_wrng.png new file mode 100644 index 000000000..820625e3c Binary files /dev/null and b/quality_assurance/static/description/picking_qq_wrng.png differ diff --git a/quality_assurance/static/description/qa_qa_nt.png b/quality_assurance/static/description/qa_qa_nt.png new file mode 100644 index 000000000..80b43c232 Binary files /dev/null and b/quality_assurance/static/description/qa_qa_nt.png differ diff --git a/quality_assurance/static/description/qa_qa_tst_assgn.png b/quality_assurance/static/description/qa_qa_tst_assgn.png new file mode 100644 index 000000000..c144db058 Binary files /dev/null and b/quality_assurance/static/description/qa_qa_tst_assgn.png differ diff --git a/quality_assurance/static/description/qa_qa_wt.png b/quality_assurance/static/description/qa_qa_wt.png new file mode 100644 index 000000000..d0c6e78b9 Binary files /dev/null and b/quality_assurance/static/description/qa_qa_wt.png differ diff --git a/quality_assurance/static/description/qa_qa_wtr.png b/quality_assurance/static/description/qa_qa_wtr.png new file mode 100644 index 000000000..f189711b3 Binary files /dev/null and b/quality_assurance/static/description/qa_qa_wtr.png differ diff --git a/quality_assurance/static/description/qa_qm_frm.png b/quality_assurance/static/description/qa_qm_frm.png new file mode 100644 index 000000000..a1a03645f Binary files /dev/null and b/quality_assurance/static/description/qa_qm_frm.png differ diff --git a/quality_assurance/static/description/qa_qt_frm.png b/quality_assurance/static/description/qa_qt_frm.png new file mode 100644 index 000000000..627cebb15 Binary files /dev/null and b/quality_assurance/static/description/qa_qt_frm.png differ diff --git a/quality_assurance/static/description/qa_qt_track.png b/quality_assurance/static/description/qa_qt_track.png new file mode 100644 index 000000000..228c14654 Binary files /dev/null and b/quality_assurance/static/description/qa_qt_track.png differ diff --git a/quality_assurance/views/product_view.xml b/quality_assurance/views/product_view.xml new file mode 100644 index 000000000..054b89e53 --- /dev/null +++ b/quality_assurance/views/product_view.xml @@ -0,0 +1,106 @@ + + + + + product.template.quality.form + product.template + + + + + + + + + + + + + + + + + + + + + + product.product.quality.form + product.product + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/quality_assurance/views/quality_view.xml b/quality_assurance/views/quality_view.xml new file mode 100644 index 000000000..268e0b96f --- /dev/null +++ b/quality_assurance/views/quality_view.xml @@ -0,0 +1,273 @@ + + + + + + + + quality.measure.tree + quality.measure + + + + + + + + + + + + + quality.measure.form + quality.measure + +
+ + +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + + quality.measure.search + quality.measure + + + + + + + + + + + + + + Quality Measure + quality.measure + form + tree,form + + +

+ Click here to add a new Quality Measure +

+
+
+ + + + + + + + + + + + quality.alert.tree + quality.alert + + + + + + + + + + + + quality.alert.form + quality.alert + +
+
+
+ +
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + + quality.alert.search + quality.alert + + + + + + + + + + + + + + + + Quality Alerts + quality.alert + form + tree,form + + +

+ Click here to add a new Quality Alert +

+ Quality alerts will be created automatically when your inventory team try to process inventory operations. +

+
+
+ + + + + + + quality.test.tree + quality.test + + + + + + + + + + + + quality.test.form + quality.test + +
+ +
+

+
+ + + + + + + + + + + + + + + + +
+
+ + +
+
+
+
+ + + quality.test.search + quality.test + + + + + + + + + + + + + + + + Quality Tests + quality.test + form + tree,form + {'search_default_my_tests': 1} + + + + +
\ No newline at end of file diff --git a/quality_assurance/views/stock_view.xml b/quality_assurance/views/stock_view.xml new file mode 100644 index 000000000..4283d9c9e --- /dev/null +++ b/quality_assurance/views/stock_view.xml @@ -0,0 +1,21 @@ + + + + quality.stock.picking.form + stock.picking + + + + + + + + \ No newline at end of file