29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from odoo import models, fields
|
||
|
||
|
||
class MrpBom(models.Model):
|
||
_inherit = 'mrp.bom'
|
||
|
||
# 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom
|
||
def bom_create(self, product, bom_type, product_type, code=None):
|
||
bom_id = self.env['mrp.bom'].create({
|
||
'product_tmpl_id': product.product_tmpl_id.id,
|
||
'type': bom_type,
|
||
# 'subcontractor_id': '' or subcontract.partner_id.id,
|
||
'product_qty': 1,
|
||
'product_uom_id': 1,
|
||
'code': code
|
||
})
|
||
if bom_type == 'subcontract' and product_type is not False:
|
||
subcontract = self.get_supplier(product.materials_type_id)
|
||
bom_id.subcontractor_id = subcontract.partner_id.id
|
||
return bom_id
|
||
|
||
def name_get(self):
|
||
"""重写name_get方法,只显示BOM编码"""
|
||
result = []
|
||
for record in self:
|
||
# 只显示BOM编码,如果编码为空则显示产品名称
|
||
display_name = record.code or record.product_tmpl_id.name or f'BOM-{record.id}'
|
||
result.append((record.id, display_name))
|
||
return result |