增加质检模块

This commit is contained in:
胡尧
2025-01-08 11:16:05 +08:00
parent b996c0c787
commit db83846588
165 changed files with 30620 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import mrp_production
from . import mrp_workorder
from . import quality
from . import product
from . import stock_move_line

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
check_ids = fields.One2many('quality.check', domain=[('workorder_id', '=', False)])

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, _
from odoo.exceptions import UserError
class MrpProductionWorkcenterLine(models.Model):
_inherit = "mrp.workorder"
def button_quality_alert(self):
self.ensure_one()
action = self.env["ir.actions.actions"]._for_xml_id("quality_control.quality_alert_action_check")
action['target'] = 'new'
action['views'] = [(False, 'form')]
action['context'] = {
'default_company_id': self.company_id.id,
'default_product_id': self.product_id.id,
'default_product_tmpl_id': self.product_id.product_tmpl_id.id,
'default_workorder_id': self.id,
'default_production_id': self.production_id.id,
'default_workcenter_id': self.workcenter_id.id,
'discard_on_footer_button': True,
}
return action

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.osv.expression import AND
class ProductTemplate(models.Model):
_inherit = "product.template"
def action_see_quality_control_points(self):
action = super().action_see_quality_control_points()
action['context'].update({'search_default_quality_points': 1})
action['domain'] = AND([action['domain'], ['|', '|', ('operation_id', '=', False), ('bom_id', '=', False), ('bom_active', '=', True)]])
return action
def action_see_quality_checks(self):
action = super().action_see_quality_checks()
action['context'].update({'search_default_quality_checks': 1})
return action
class ProductProduct(models.Model):
_inherit = "product.product"
def action_see_quality_control_points(self):
action = super().action_see_quality_control_points()
action['context'].update({'search_default_quality_points': 1})
action['domain'] = AND([action['domain'], ['|', '|', ('operation_id', '=', False), ('bom_id', '=', False), ('bom_active', '=', True)]])
return action
def action_see_quality_checks(self):
action = super().action_see_quality_checks()
action['context'].update({'search_default_quality_checks': 1})
return action
def _additional_quality_point_where_clause(self):
return super()._additional_quality_point_where_clause() + """
AND (
operation_id IS NULL
OR operation_id IN (
SELECT ope.id FROM mrp_routing_workcenter AS ope
INNER JOIN mrp_bom as bom ON ope.bom_id = bom.id
WHERE bom.active = 't' ))
"""

View File

@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, _
from odoo.osv.expression import AND
class QualityPoint(models.Model):
_inherit = "quality.point"
@api.model
def _get_domain_for_production(self, quality_points_domain):
quality_points_domain = super()._get_domain_for_production(quality_points_domain)
return AND([quality_points_domain, [('operation_id', '=', False)]])
class QualityCheck(models.Model):
_inherit = "quality.check"
def do_pass(self):
self.ensure_one()
super().do_pass()
def do_fail(self):
self.ensure_one()
return super().do_fail()
def do_measure(self):
self.ensure_one()
res = super().do_measure()
return self._next() if self.workorder_id else res
def _next(self, continue_production=False):
self.ensure_one()
result = super()._next(continue_production=continue_production)
if self.quality_state == 'fail':
return {
'name': _('Quality Check Failed'),
'type': 'ir.actions.act_window',
'res_model': 'quality.check.wizard',
'views': [(self.env.ref('quality_control.quality_check_wizard_form_failure').id, 'form')],
'target': 'new',
'context': {
**self.env.context,
'default_check_ids': [self.id],
'default_current_check_id': self.id,
'default_test_type': self.test_type,
'default_failure_message': self.failure_message,
'default_warning_message': self.warning_message,
},
}
return result
def _get_check_result(self):
if self.test_type == 'passfail':
return _('Success') if self.quality_state == 'pass' else _('Failure')
elif self.test_type == 'measure':
return '{} {}'.format(self.measure, self.norm_unit)
return super(QualityCheck, self)._get_check_result()
def _check_to_unlink(self):
self.ensure_one()
return super()._check_to_unlink() and not self.workorder_id
def action_pass_and_next(self):
self.ensure_one()
super().do_pass()
return self._next()
def action_fail_and_next(self):
self.ensure_one()
super().do_fail()
return self._next()

View File

@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class StockMoveLine(models.Model):
_inherit = 'stock.move.line'
def _without_quality_checks(self):
self.ensure_one()
return super()._without_quality_checks() or not self.quality_check_ids.filtered(lambda qc: qc.measure_on != 'move_line')