mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] quality_control_issue: add scrap feature.
This commit is contained in:
committed by
Jordi Ballester Alomar
parent
e16506f189
commit
4075ce1ffe
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import stock_scrap
|
||||
from . import qc_stage
|
||||
from . import qc_problem
|
||||
from . import qc_problem_group
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import api, fields, models
|
||||
from openerp import api, fields, models, _
|
||||
from openerp.exceptions import UserError
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
@@ -11,6 +12,12 @@ class QualityControlIssue(models.Model):
|
||||
_description = "Quality Control Issue"
|
||||
_inherit = "mail.thread"
|
||||
|
||||
@api.multi
|
||||
def _compute_stock_scrap_qty(self):
|
||||
for rec in self:
|
||||
rec.stock_scrap_qty = sum(
|
||||
self.stock_scrap_ids.mapped('scrap_qty'))
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
vals['name'] = self.env['ir.sequence'].next_by_code(
|
||||
@@ -61,7 +68,7 @@ class QualityControlIssue(models.Model):
|
||||
("progress", "In Progress"),
|
||||
("done", "Done"),
|
||||
("cancel", "Cancel")], default="new",
|
||||
track_visibility='onchange')
|
||||
track_visibility='onchange', readonly=True)
|
||||
product_id = fields.Many2one(
|
||||
comodel_name="product.product", string="Product",
|
||||
readonly=True, states={"new": [("readonly", False)]}, required=True)
|
||||
@@ -111,6 +118,10 @@ class QualityControlIssue(models.Model):
|
||||
company_id = fields.Many2one(
|
||||
comodel_name='res.company', string='Company', required=True,
|
||||
default=lambda self: self.env.user.company_id)
|
||||
stock_scrap_ids = fields.One2many(
|
||||
comodel_name='stock.scrap', string='Scraps',
|
||||
inverse_name='qc_issue_id')
|
||||
stock_scrap_qty = fields.Integer(compute=_compute_stock_scrap_qty)
|
||||
|
||||
_group_by_full = {
|
||||
'stage_id': _read_group_stage_ids
|
||||
@@ -131,18 +142,47 @@ class QualityControlIssue(models.Model):
|
||||
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._check_required_fields()
|
||||
self.write({'state': 'progress'})
|
||||
|
||||
@api.multi
|
||||
@@ -170,7 +210,38 @@ class QualityControlIssue(models.Model):
|
||||
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()
|
||||
return {
|
||||
'name': _('Scrap'),
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'stock.scrap',
|
||||
'view_id': self.env.ref('stock_scrap.stock_scrap_form_view2').id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {
|
||||
'default_qc_issue_id': self.id,
|
||||
'default_location_id': self.location_id.id,
|
||||
'default_product_id': self.product_id.id,
|
||||
'default_scrap_qty': self.product_qty,
|
||||
'default_product_uom_id': self.product_uom.id,
|
||||
'default_lot_id': self.lot_id.id,
|
||||
},
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@api.multi
|
||||
def action_view_stock_scrap(self):
|
||||
action = self.env.ref('stock_scrap.action_stock_scrap')
|
||||
result = action.read()[0]
|
||||
lines = self.stock_scrap_ids
|
||||
# choose the view_mode accordingly
|
||||
if len(lines) != 1:
|
||||
result['domain'] = "[('id', 'in', " + \
|
||||
str(lines.ids) + ")]"
|
||||
elif len(lines) == 1:
|
||||
res = self.env.ref('stock_scrap.stock_scrap_form_view', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = lines.id
|
||||
return result
|
||||
|
||||
@@ -40,5 +40,5 @@ class QualityControlIssueStage(models.Model):
|
||||
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)
|
||||
|
||||
@@ -101,9 +101,12 @@ class QcProblem(models.Model):
|
||||
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(
|
||||
|
||||
12
quality_control_issue/models/stock_scrap.py
Normal file
12
quality_control_issue/models/stock_scrap.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import fields, models
|
||||
|
||||
|
||||
class QualityControlIssueStage(models.Model):
|
||||
_inherit = "stock.scrap"
|
||||
|
||||
qc_issue_id = fields.Many2one(
|
||||
comodel_name="qc.issue", string="Quality Control Issue")
|
||||
Reference in New Issue
Block a user