From d762e7c78040e31d211f99fa4285fd5dc1bff6e8 Mon Sep 17 00:00:00 2001 From: lreficent Date: Mon, 31 Jul 2017 12:09:59 +0200 Subject: [PATCH] fix stage state relation and update readme. --- quality_control_issue/README.rst | 55 ++++++++++++++++--- quality_control_issue/models/qc_issue.py | 38 +++++++++++-- .../models/qc_issue_stage.py | 2 +- quality_control_issue/models/qc_problem.py | 5 +- 4 files changed, 85 insertions(+), 15 deletions(-) diff --git a/quality_control_issue/README.rst b/quality_control_issue/README.rst index f17a29a5a85..8581832f781 100644 --- a/quality_control_issue/README.rst +++ b/quality_control_issue/README.rst @@ -6,17 +6,59 @@ Quality Control Issue ===================== -WIP - This module extends the functionality of quality Control to allow you to report and manage quality control issues. +Configuration +============= + +To configure this module in order to take advantage of the kanban views you +need to create the stages for *issues* and *problems*. To **create** stages in +any kanban view click on *Add New Column*. Then you can **reorder** the stages +just dragging them. + +In created stages you can **configure** them clicking on the gear button that +appears at the right of the stage name and clicking on *Edit*. Note the +following behaviors: + +* You can set a *Quality Control Team*. + + - Stages with no team set will be shared by all teams. + - Stages with a team associated will be only available for that specific + team. + +* In Issue Stages you can also relate a *QC State* to the stage. + + - When you move to a different stage an issue with *QC state* defined the + state of the issue will also change according to it. + - The other way around, if you change the state, the system will look for + an appropriate stage and if existing the issue will be move to that stage. + - If you change the *QC team* of an issue, the system will get the default + stage for that team and apply it to the issue. + Usage ===== -To use this module, you need to: +To use Quality Control Issues, you need to: + +#. Go to *Quality Control > Issues > QC Issues* or to *Quality Control > + Dashboard* and click on *Issues* in any of your teams. +#. Click on create to report an issue. +#. Select the product and quantity for the issue. Optionally you can specify + a location and relate the issue to some *Problem*. + +To manage your Quality Control Problems, you have to: + +#. Go to *Quality Control > Problem Tracking > Problems* or to *Quality + Control > Dashboard* and click on *Problems* in any of your teams. + +Issue Dispositions: +------------------- + +You can perform the following actions in quality control issues 'in progress': -#. Go to *Quality Control > Issues > QC Issues*. +* Scrap: Click on *Scrap Products* button. +* Create RMA: Install `rma_quality_control_issue` and see instructions there. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot @@ -28,9 +70,7 @@ Known issues / Roadmap Todo: ----- -* Add Dispositions: RMA, scrap, rework... -* reference to PO, MO, QC... -* Link to Problem tracking... +* Add more dispositions: repair, refurbish... Bug Tracker =========== @@ -52,6 +92,7 @@ Contributors ------------ * Lois Rilo +* Jordi Ballester Alomar Maintainer ---------- diff --git a/quality_control_issue/models/qc_issue.py b/quality_control_issue/models/qc_issue.py index 902325be322..19dfeb3e3f1 100644 --- a/quality_control_issue/models/qc_issue.py +++ b/quality_control_issue/models/qc_issue.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from openerp import api, fields, models, _ +from openerp.exceptions import UserError import openerp.addons.decimal_precision as dp @@ -141,15 +142,45 @@ def issue_stage_find(self, cases, team, domain=None, order='sequence'): team_ids.add(issue.team_id.id) search_domain = [] if team_ids: - search_domain += [('|')] * (len(team_ids) - 1) + search_domain += [('|')] * (len(team_ids)) + search_domain.append(('qc_team_id', '=', False)) for team_id in team_ids: search_domain.append(('qc_team_id', '=', team_id)) + else: + search_domain.append(('qc_team_id', '=', False)) search_domain += list(domain) # perform search, return the first found stage = self.env['qc.issue.stage'].search( search_domain, order=order, limit=1) return stage + @api.multi + def write(self, vals): + stage_obj = self.env['qc.issue.stage'] + state = vals.get('state') + if state: + if len(self.mapped('qc_team_id')) > 1: + raise UserError(_( + "Every issue must have the same QC team to perform this " + "action.")) + team = self[0].qc_team_id + stage = self.issue_stage_find([], team, [('state', '=', state)]) + if stage: + vals.update({'stage_id': stage.id}) + return super(QualityControlIssue, self).write(vals) + team_id = vals.get('qc_team_id') + if team_id is not None: + team = self.env['qc.team'].browse(team_id) + stage = self.issue_stage_find([], team, [('fold', '=', False)]) + if stage: + vals.update({'stage_id': stage.id}) + stage_id = vals.get('stage_id') + if stage_id: + state = stage_obj.browse(stage_id).state + if state: + vals.update({'state': state}) + return super(QualityControlIssue, self).write(vals) + @api.multi def action_confirm(self): self.write({'state': 'progress'}) @@ -179,11 +210,6 @@ def _onchange_lot_id(self): self.product_id = product self.product_uom = product.product_tmpl_id.uom_id - @api.onchange("stage_id") - def _onchange_stage_id(self): - if self.stage_id.state: - self.state = self.stage_id.state - @api.multi def scrap_products(self): self.ensure_one() diff --git a/quality_control_issue/models/qc_issue_stage.py b/quality_control_issue/models/qc_issue_stage.py index 4a652ff1813..387e1ff17f6 100644 --- a/quality_control_issue/models/qc_issue_stage.py +++ b/quality_control_issue/models/qc_issue_stage.py @@ -40,5 +40,5 @@ def default_get(self, fields): help='This stage is folded in the kanban view when there are no ' 'records in that stage to display.') state = fields.Selection( - string="QC Status", + string="QC State", selection=lambda self: self.env['qc.issue']._fields['state'].selection) diff --git a/quality_control_issue/models/qc_problem.py b/quality_control_issue/models/qc_problem.py index 72b9881f418..465f6b37709 100644 --- a/quality_control_issue/models/qc_problem.py +++ b/quality_control_issue/models/qc_problem.py @@ -101,9 +101,12 @@ def stage_find(self, cases, team, domain=None, order='sequence'): team_ids.add(problem.team_id.id) search_domain = [] if team_ids: - search_domain += [('|')] * (len(team_ids) - 1) + search_domain += [('|')] * (len(team_ids)) + search_domain.append(('qc_team_id', '=', False)) for team_id in team_ids: search_domain.append(('qc_team_id', '=', team_id)) + else: + search_domain.append(('qc_team_id', '=', False)) search_domain += list(domain) # perform search, return the first found stage = self.env['qc.stage'].search(