Skip to Content
Menu
This question has been flagged
1 Reply
1872 Views

Hello,


When we confirm a sale.order, That's create mrp.production

I'm looking for odoo code where this mrp.production is created because i need to update this code.

Is anybody knows where it's done ?

Avatar
Discard
Best Answer

Hi,

This is the create function inside the model 'mrp.production'

@api.model
    def create(self, values):
        if not values.get('name', False) or values['name'] == _('New'):
            picking_type_id = values.get('picking_type_id') or self._get_default_picking_type()
            picking_type_id = self.env['stock.picking.type'].browse(picking_type_id)
            if picking_type_id:
                values['name'] = picking_type_id.sequence_id.next_by_id()
            else:
                values['name'] = self.env['ir.sequence'].next_by_code('mrp.production') or _('New')
        if not values.get('procurement_group_id'):
            procurement_group_vals = self._prepare_procurement_group_vals(values)
            values['procurement_group_id'] = self.env["procurement.group"].create(procurement_group_vals).id
        production = super(MrpProduction, self).create(values)
        (production.move_raw_ids | production.move_finished_ids).write({
            'group_id': production.procurement_group_id.id,
            'origin': production.name
        })
        production.move_raw_ids.write({'date': production.date_planned_start})
        production.move_finished_ids.write({'date': production.date_planned_finished})
        # Trigger move_raw creation when importing a file
        if 'import_file' in self.env.context:
            production._onchange_move_raw()
            production._onchange_move_finished()
        return production

Thanks

Avatar
Discard
Author

Hi Odoophile for your answer.

In all that code, i don't understand where Odoo create mrp.production lines from sale.order.line ?

Can you help me to understand?

Author

Maybe i found something.

If i browse move_raw_ids, i can go up to stock.move and then, with sale_line_id, i can go up to sale.order.line

I will try that