Files
manufacture/quality_control_stock_oca/models/stock_picking.py
Pedro M. Baeza 1891090bed [IMP] Total refactorization of quality control modules with new API, README files, and new concepts. WIP of quality_control_tolerance
Merge branch '8.0' of github.com:odoomrp/odoomrp-wip into 8.0

[FIX] quality_control_stock:
* File missing
* Triggers for product category
2021-10-04 12:19:41 +02:00

50 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from openerp import models, fields, api
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.one
@api.depends('qc_inspections', 'qc_inspections.state')
def _count_inspections(self):
self.created_inspections = len(self.qc_inspections)
self.passed_inspections = len([x for x in self.qc_inspections if
x.state == 'success'])
self.failed_inspections = len([x for x in self.qc_inspections if
x.state == 'failed'])
self.done_inspections = (self.passed_inspections +
self.failed_inspections)
qc_inspections = fields.One2many(
comodel_name='qc.inspection', inverse_name='picking', copy=False,
string='Inspections', help="Inspections related to this picking.")
created_inspections = fields.Integer(
compute="_count_inspections", string="Created inspections")
done_inspections = fields.Integer(
compute="_count_inspections", string="Done inspections")
passed_inspections = fields.Integer(
compute="_count_inspections", string="Inspections OK")
failed_inspections = fields.Integer(
compute="_count_inspections", string="Inspections failed")
@api.multi
def do_transfer(self):
res = super(StockPicking, self).do_transfer()
inspection_model = self.env['qc.inspection']
for operation in self.pack_operation_ids:
qc_trigger = self.env['qc.trigger'].search(
[('picking_type', '=', self.picking_type_id.id)])
tests = set()
for model in ['qc.trigger.product_category_line',
'qc.trigger.product_template_line',
'qc.trigger.product_line']:
tests = tests.union(self.env[model].get_test_for_product(
qc_trigger, operation.product_id))
for test in tests:
inspection_model._make_inspection(operation, test)
return res