Skip to Content
Menú
This question has been flagged
1 Respondre
2137 Vistes

Our company is a print manufacturing firm using odoo15 as our ERP framework.

In our manufacturing environment, we want to initiate a manufacturing order regardless of whether or not there is inventory available on product.product from a sale order.

Product (enable: MTO & Manufacture Routes) >> Sale Order (add product to Sale Order Line) >> Confirm Sale Order >> Generates Manufacturing MRP Order

I thought that what I've done below would work to ensure that a manufacturing order would be generated regardless of whether or not product.product's qty was > 0.

If anyone is familiar with odoo 15, and maybe a method I haven't checked for, please feel free to drop a note. Thanks!

from odoo import models
from odoo import api, models, SUPERUSER_ID, _
from collections import defaultdict


class StockRule(models.Model):
    _inherit = 'stock.rule'
    
    def _should_auto_confirm_procurement_mo(self, p):
        return False

    @api.model
    def _run_manufacture(self, procurements):
        productions_values_by_company = defaultdict(list)
        errors = []
        for procurement, rule in procurements:
            # Removing below to ensure that MOs are generated regardless of circumstance

            # procurement.product_qty = max(1, procurement.product_qty)
            # if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
            #     # If procurement contains negative quantity, don't create a MO that would be for a negative value.
            #     continue

            bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
            if not bom:
                continue

            productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))

        if errors:
            raise ProcurementException(errors)

        for company_id, productions_values in productions_values_by_company.items():
            # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example)
            productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(productions_values)
            self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
            self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
            productions._create_workorder()
            productions.filtered(self._should_auto_confirm_procurement_mo).action_confirm()

            for production in productions:
                origin_production = production.move_dest_ids and production.move_dest_ids[0].raw_material_production_id or False
                orderpoint = production.orderpoint_id
                if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
                    production.message_post(
                        body=_('This production order has been created from Replenishment Report.'),
                        message_type='comment',
                        subtype_xmlid='mail.mt_note')
                elif orderpoint:
                    production.message_post_with_view(
                        'mail.message_origin_link',
                        values={'self': production, 'origin': orderpoint},
                        subtype_id=self.env.ref('mail.mt_note').id)
                elif origin_production:
                    production.message_post_with_view(
                        'mail.message_origin_link',
                        values={'self': production, 'origin': origin_production},
                        subtype_id=self.env.ref('mail.mt_note').id)
        return True


Avatar
Descartar
Best Answer

If you have set up MTO, a manufacturing order will be created automatic, as soon as you confirm the sales order, regardless of any existing stock.  Standard process in Odoo.

The extra workaround is when you want to deliver from stock, and not use the manufacturing order.

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de nov. 23
2248
1
d’oct. 23
2830
1
de jul. 23
3793
1
de gen. 23
3575
2
de gen. 24
5448