<commit_before># -*- coding: utf-8 -*-
# (c) 2015 <NAME> - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp.tests.common import TransactionCase


class TestQualityControl(TransactionCase):

    def setUp(self):
        super(TestQualityControl, self).setUp()
        self.picking_model = self.env['stock.picking']
        self.operation_model = self.env['stock.pack.operation']
        self.qc_trigger_model = self.env['qc.trigger']
        self.product = self.env.ref('product.product_product_4')
        self.partner = self.env.ref('base.res_partner_2')
        self.test = self.env.ref('quality_control.qc_test_1')
        self.picking_type = self.env.ref('stock.picking_type_out')
        self.trigger = self.qc_trigger_model.search(
            [('picking_type', '=', self.picking_type.id)])
        move_vals = {
            'name': self.product.name,
            'product_id': self.product.id,
            'product_uom': self.product.uom_id.id,
            'location_id': self.picking_type.default_location_src_id.id,
            'location_dest_id': self.picking_type.default_location_dest_id.id,
        }
        self.picking1 = self.picking_model.create({
            'partner_id': self.partner.id,
            'picking_type_id': self.picking_type.id,
            'move_lines': [(0, 0, move_vals)],
        })
        self.picking1.action_confirm()
        self.picking1.action_assign()
        self.picking1.do_prepare_partial()
        for line in self.picking1.move_lines:
            self.operation_model.create({
                'product_id': line.product_id.id,
                'product_qty': line.product_uom_qty,
                'product_uom_id': line.product_uom.id,
                'location_id': line.location_id.id,
                'location_dest_id': line.location_dest_id.id,
                'picking_id': self.picking1.id,
            })

    def test_inspection_create_for_product(self):
        self.product.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertGreater(self.picking1.created_inspections, 0,
                           'Inspections not created')

    def test_inspection_create_for_template(self):
        self.product.product_tmpl_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertGreater(self.picking1.created_inspections, 0,
                           'Inspections not created')

    def test_inspection_create_for_category(self):
        self.product.categ_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertGreater(self.picking1.created_inspections, 0,
                           'Inspections not created')<commit_msg>[IMP] <quality_control_stock> More test... There seems to be one issue in <quality_control><commit_after># -*- coding: utf-8 -*-
# (c) 2015 <NAME> - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp.tests.common import TransactionCase


class TestQualityControl(TransactionCase):

    def setUp(self):
        super(TestQualityControl, self).setUp()
        self.picking_model = self.env['stock.picking']
        self.operation_model = self.env['stock.pack.operation']
        self.qc_trigger_model = self.env['qc.trigger']
        self.product = self.env.ref('product.product_product_4')
        self.partner1 = self.env.ref('base.res_partner_2')
        self.partner2 = self.env.ref('base.res_partner_4')
        self.test = self.env.ref('quality_control.qc_test_1')
        self.picking_type = self.env.ref('stock.picking_type_out')
        self.trigger = self.qc_trigger_model.search(
            [('picking_type', '=', self.picking_type.id)])
        move_vals = {
            'name': self.product.name,
            'product_id': self.product.id,
            'product_uom': self.product.uom_id.id,
            'location_id': self.picking_type.default_location_src_id.id,
            'location_dest_id': self.picking_type.default_location_dest_id.id,
        }
        self.picking1 = self.picking_model.create({
            'partner_id': self.partner1.id,
            'picking_type_id': self.picking_type.id,
            'move_lines': [(0, 0, move_vals)],
        })
        self.picking1.action_confirm()
        self.picking1.action_assign()
        self.picking1.do_prepare_partial()
        for line in self.picking1.move_lines:
            self.operation_model.create({
                'product_id': line.product_id.id,
                'product_qty': line.product_uom_qty,
                'product_uom_id': line.product_uom.id,
                'location_id': line.location_id.id,
                'location_dest_id': line.location_dest_id.id,
                'picking_id': self.picking1.id,
            })

    def test_inspection_create_for_product(self):
        self.product.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_template(self):
        self.product.product_tmpl_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_category(self):
        self.product.categ_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_product_partner(self):
        self.product.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner1.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_template_partner(self):
        self.product.product_tmpl_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner1.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_category_partner(self):
        self.product.categ_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner1.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')

    def test_inspection_create_for_product_wrong_partner(self):
        self.product.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner2.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 0,
                         'No inspection must be created')

    def test_inspection_create_for_template_wrong_partner(self):
        self.product.product_tmpl_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner2.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 0,
                         'No inspection must be created')

    def test_inspection_create_for_category_wrong_partner(self):
        self.product.categ_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
                'partners': [(6, 0, [self.partner2.id])],
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 0,
                         'No inspection must be created')

    def test_inspection_create_only_one(self):
        self.product.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.product.categ_id.qc_triggers = [(
            0, 0, {
                'trigger': self.trigger.id,
                'test': self.test.id,
            }
        )]
        self.picking1.do_transfer()
        self.assertEqual(self.picking1.created_inspections, 1,
                         'Only one inspection must be created')
{'fraction_non_alphanumeric': 0.11893534527926229, 'fraction_numerical': 0.01330818400922142, 'mean_word_length': 1.8413218219708247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '933900', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2910, 'n_words': 425}