how does this look: from odoo import models, fields, api from odoo.exceptions import…
- User
how does this look: from odoo import models, fields, api from odoo.exceptions import UserError
class ProductTemplate(models.Model): _inherit = 'product.template'
def action_create_manufacturing_order(self): self.ensure_one() # Ensure a single record is processed # Fetch the latest active BoM for the product bom = self.env['mrp.bom'].search([ ('product_tmpl_id', '=', self.id), ('active', '=', True) ], order='write_date desc', limit=1) if not bom: raise UserError('No active Bill of Materials found for this product.') # Define default values for the Manufacturing Order mo_vals = { 'product_id': self.product_variant_id.id, 'product_qty': 1.0, # You can customize this as needed 'product_uom_id': self.uom_id.id, 'location_src_id': self.env.ref('stock.stock_location_production').id, 'location_dest_id': self.env.ref('stock.stock_location_production').id, 'company_id': self.env.company.id, 'bom_id': bom.id, # Assign the latest BoM } # Create the Manufacturing Order mo = self.env['mrp.production'].create(mo_vals) # Optionally, open the newly created Manufacturing Order form view return { 'type': 'ir.actions.act_window', 'name': 'Manufacturing Order', 'view_mode': 'form', 'res_model': 'mrp.production', 'res_id': mo.id, 'target': 'current', } - Assistant
Your code for extending the
product.templatemodel in Odoo seems well-structured and appears to follow best practices for creating a manufacturing order. Here's a brief overview and a few suggestions:-
Ensure Single Record: You're using
self.ensure_one(), which ensures the method operates only on a single record. This is good practice for methods that are intended to work with individual records.
-
- User
raise ValueError('External ID not found in the system: %s' % xmlid) ValueError: External ID not found in the system: stock.stock_location_production
- Assistant
The error message you're encountering indicates that Odoo could not find the specified external ID (
stock.stock_location_production). This typically means that the external ID you are trying to reference does not exist in the current database, potentially due to: - User
the odoo bom overview has component product links, but i cant open these links in view tab, they just take me to main odoo page, is there a way to modify the view so i can do this?
- Assistant