Several fixes:

* add stage states
* default values for relational fields must return a recordset.
* do not allow to create qc issues from kanban quick create.
This commit is contained in:
Jordi Ballester
2017-07-26 18:46:05 +02:00
committed by Jordi Ballester Alomar
parent 508fe0a28b
commit e16506f189
5 changed files with 35 additions and 31 deletions

View File

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import qc_stage
from . import qc_issue
from . import qc_problem from . import qc_problem
from . import qc_problem_group from . import qc_problem_group
from . import qc_stage
from . import qc_issue_stage from . import qc_issue_stage
from . import qc_issue

View File

@@ -23,9 +23,9 @@ class QualityControlIssue(models.Model):
def _get_default_stage_id(self): def _get_default_stage_id(self):
""" Gives default stage_id """ """ Gives default stage_id """
team_id = self.env['qc.team']._get_default_qc_team_id( team = self.env['qc.team']._get_default_qc_team_id(
user_id=self.env.uid) user_id=self.env.uid)
return self.issue_stage_find([], team_id, [('fold', '=', False)]) return self.issue_stage_find([], team, [('fold', '=', False)])
@api.multi @api.multi
def _read_group_stage_ids(self, domain, read_group_order=None, def _read_group_stage_ids(self, domain, read_group_order=None,
@@ -64,8 +64,7 @@ class QualityControlIssue(models.Model):
track_visibility='onchange') track_visibility='onchange')
product_id = fields.Many2one( product_id = fields.Many2one(
comodel_name="product.product", string="Product", comodel_name="product.product", string="Product",
readonly=True, states={"new": [("readonly", False)]}, readonly=True, states={"new": [("readonly", False)]}, required=True)
required=True)
product_tracking = fields.Selection(related="product_id.tracking") product_tracking = fields.Selection(related="product_id.tracking")
product_qty = fields.Float( product_qty = fields.Float(
string="Product Quantity", required=True, default=1.0, string="Product Quantity", required=True, default=1.0,
@@ -73,8 +72,8 @@ class QualityControlIssue(models.Model):
digits_compute=dp.get_precision("Product Unit of Measure")) digits_compute=dp.get_precision("Product Unit of Measure"))
product_uom = fields.Many2one( product_uom = fields.Many2one(
comodel_name="product.uom", string="Product Unit of Measure", comodel_name="product.uom", string="Product Unit of Measure",
required=True, default=_get_uom, default=_get_uom, required=True, readonly=True,
readonly=True, states={"new": [("readonly", False)]},) states={"new": [("readonly", False)]})
lot_id = fields.Many2one( lot_id = fields.Many2one(
comodel_name="stock.production.lot", string="Lot/Serial Number", comodel_name="stock.production.lot", string="Lot/Serial Number",
readonly=True, states={"new": [("readonly", False)]},) readonly=True, states={"new": [("readonly", False)]},)
@@ -117,7 +116,7 @@ class QualityControlIssue(models.Model):
'stage_id': _read_group_stage_ids 'stage_id': _read_group_stage_ids
} }
def issue_stage_find(self, cases, team_id, domain=None, order='sequence'): def issue_stage_find(self, cases, team, domain=None, order='sequence'):
""" Override of the base.stage method """ Override of the base.stage method
Parameter of the stage search taken from the problem: Parameter of the stage search taken from the problem:
- team_id: if set, stages must belong to this team or - team_id: if set, stages must belong to this team or
@@ -125,26 +124,25 @@ class QualityControlIssue(models.Model):
stages stages
""" """
team_ids = set() team_ids = set()
if team_id: if team:
team_ids.add(team_id) team_ids.add(team.id)
for problem in cases: for issue in cases:
if problem.team_id: if issue.team_id:
team_ids.add(problem.team_id.id) team_ids.add(issue.team_id.id)
search_domain = [] search_domain = []
if team_ids: if team_ids:
search_domain += [('|')] * (len(team_ids) - 1) search_domain += [('|')] * (len(team_ids) - 1)
for team_id in team_ids: for team_id in team_ids:
search_domain.append(('qc_team_id', '=', team_id.id)) search_domain.append(('qc_team_id', '=', team_id))
search_domain += list(domain) search_domain += list(domain)
# perform search, return the first found # perform search, return the first found
stage_ids = self.env['qc.issue.stage'].search( stage = self.env['qc.issue.stage'].search(
search_domain, order=order, limit=1) search_domain, order=order, limit=1)
if stage_ids: return stage
return stage_ids[0]
return False
@api.multi @api.multi
def action_confirm(self): def action_confirm(self):
self._check_required_fields()
self.write({'state': 'progress'}) self.write({'state': 'progress'})
@api.multi @api.multi
@@ -171,3 +169,8 @@ class QualityControlIssue(models.Model):
if product: if product:
self.product_id = product self.product_id = product
self.product_uom = product.product_tmpl_id.uom_id 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

View File

@@ -39,3 +39,6 @@ class QualityControlIssueStage(models.Model):
string='Folded in Pipeline', default=False, string='Folded in Pipeline', default=False,
help='This stage is folded in the kanban view when there are no ' help='This stage is folded in the kanban view when there are no '
'records in that stage to display.') 'records in that stage to display.')
state = fields.Selection(
string="QC Status",
selection=lambda self: self.env['qc.issue']._fields['state'].selection)

View File

@@ -19,9 +19,9 @@ class QcProblem(models.Model):
def _get_default_stage_id(self): def _get_default_stage_id(self):
""" Gives default stage_id """ """ Gives default stage_id """
team_id = self.env['qc.team']._get_default_qc_team_id( team = self.env['qc.team']._get_default_qc_team_id(
user_id=self.env.uid) user_id=self.env.uid)
return self.stage_find([], team_id, [('fold', '=', False)]) return self.stage_find([], team, [('fold', '=', False)])
@api.multi @api.multi
def _read_group_stage_ids(self, domain, read_group_order=None, def _read_group_stage_ids(self, domain, read_group_order=None,
@@ -86,7 +86,7 @@ class QcProblem(models.Model):
'stage_id': _read_group_stage_ids 'stage_id': _read_group_stage_ids
} }
def stage_find(self, cases, team_id, domain=None, order='sequence'): def stage_find(self, cases, team, domain=None, order='sequence'):
""" Override of the base.stage method """ Override of the base.stage method
Parameter of the stage search taken from the problem: Parameter of the stage search taken from the problem:
- team_id: if set, stages must belong to this team or - team_id: if set, stages must belong to this team or
@@ -94,8 +94,8 @@ class QcProblem(models.Model):
stages stages
""" """
team_ids = set() team_ids = set()
if team_id: if team:
team_ids.add(team_id) team_ids.add(team.id)
for problem in cases: for problem in cases:
if problem.team_id: if problem.team_id:
team_ids.add(problem.team_id.id) team_ids.add(problem.team_id.id)
@@ -103,11 +103,9 @@ class QcProblem(models.Model):
if team_ids: if team_ids:
search_domain += [('|')] * (len(team_ids) - 1) search_domain += [('|')] * (len(team_ids) - 1)
for team_id in team_ids: for team_id in team_ids:
search_domain.append(('qc_team_id', '=', team_id.id)) search_domain.append(('qc_team_id', '=', team_id))
search_domain += list(domain) search_domain += list(domain)
# perform search, return the first found # perform search, return the first found
stage_ids = self.env['qc.stage'].search( stage = self.env['qc.stage'].search(
search_domain, order=order, limit=1) search_domain, order=order, limit=1)
if stage_ids: return stage
return stage_ids[0]
return False

View File

@@ -87,7 +87,8 @@
<field name="name">qc.issue.kanban</field> <field name="name">qc.issue.kanban</field>
<field name="model">qc.issue</field> <field name="model">qc.issue</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<kanban class="o_kanban_small_column" default_group_by="stage_id"> <kanban class="o_kanban_small_column" default_group_by="stage_id"
quick_create="false" create="true">
<field name="stage_id"/> <field name="stage_id"/>
<field name="color"/> <field name="color"/>
<templates> <templates>