из odoo импортировать модели, поля, api из datetime import datetime, date from odoo.exceptions import UserError, ValidationError
class SaleOrder (models.Model): _inherit = "sale.order"
def action_confirm(self):
print("name===================================",self.name)
order_line_values=[]
for rec in self.order_line:
if rec.bom_id.id == False:
raise ValidationError(("Bill Of Material is required!!!"))
print("shail--------------------------",rec.product_id.id)
sale_order=self.env['product.template'].search([('name','=',rec.product_id.name)])
print("sale_order===========================",sale_order.id)
active_id=self.env['mrp.bom'].browse(self.env.context.get('active_id'))
active_ids=self.env['mrp.bom'].browse(self.env.context.get('active_ids'))
print("active_id============================",active_id)
man_id_cr=self.env['mrp.production'].create({
'product_id': rec.product_id.id,
'bom_id':rec.bom_id.id,
'product_qty':rec.product_uom_qty,
'product_uom_id': sale_order.uom_id.id,
'origin':self.name,
})
return super(SaleOrder,self).action_confirm()
класс SaleOrderLine (models.Model): _inherit = "sale.order.line"
bom_id = fields.Many2one("mrp.bom",string="Bill Of Material")
класс MrpBom (models.Model): _inherit = 'mrp.bom'
[enter image description here][1]