Skip to Content
Menu
This question has been flagged

Hi All,

I want to create a quality check on each lot and serial number while manufacturing.
So, I added a new selection on measor_on.



and override the _create_quality_checks_for_mo method.



but when the method got called I'm not getting any quality points.




what I'm doing wrong here?
How can I create the quality check per lot in manufacturing?

Avatar
Discard
Best Answer

Hi,


Try with the following code,


def create_quality_checks_for_mo(self):

    print("create_quality_checks_for_mo .........")

    mo_moves = defaultdict(lambda: self.env['stock.move'])

    check_vals_list = []

   

    # Group moves by manufacturing order

    for move in self:

        if move.production_id and not move.scrapped:

            mo_moves[move.production_id] |= move

   

    for production, moves in mo_moves.items():

        print("production --->", production.name)

        print("picking_type_id --->", production.picking_type_id)

       

        # Search for quality points with 'lots_serial_no' measure_on

        quality_points_lot = self.env['quality.point'].search([

            ('product_id', 'in', [production.product_id.id, False]),

            ('picking_type_id', 'in', [production.picking_type_id.id, False]),

            ('measure_on', '=', 'lots_serial_no'),

            ('company_id', 'in', [production.company_id.id, False]),

        ])

        print("quality_points_lot found:", len(quality_points_lot))

       

        # Create quality checks for each lot in finished moves

        if quality_points_lot:

            for move in production.move_finished_ids.filtered(lambda m: not m.scrapped):

                print("move --->", move.product_id.name)

                for ml in move.move_line_ids:

                    print("ml lot --->", ml.lot_id)

                    if ml.lot_id:

                        for point in quality_points_lot:

                            # Check if point applies to this product

                            if not point.product_id or point.product_id.id == ml.product_id.id:

                                check_vals_list.append({

                                    'point_id': point.id,

                                    'team_id': point.team_id.id,

                                    'measure_on': 'lots_serial_no',

                                    'production_id': production.id,

                                    'lot_id': ml.lot_id.id,

                                    'product_id': ml.product_id.id,

                                    'company_id': production.company_id.id,

                                    'user_id': point.user_id.id or self.env.user.id,

                                })

       

        print("check_vals_list length:", len(check_vals_list))

   

    # Create all quality checks

    if check_vals_list:

        self.env['quality.check'].sudo().create(check_vals_list)

        print(f"Created {len(check_vals_list)} quality checks for lots")


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
1695
1
Oct 24
1586
2
Sep 21
3384
1
Sep 25
250
1
Aug 25
1152