根据状态显示不同的颜色
cop_product_id 是Many2one到peoduct.product上的, categ_id是product.product里面的字段,直接拿来用就可以了
def create_eng_bom(self):
if self.cpo_bom_pcb_number:
eng_bom = self.env['bom.eng_bom']
eng_bom_line = self.env['bom.eng_bom_line']
eng_bom_obj = eng_bom.create({"cpo_bom_pcb_number": self.cpo_bom_pcb_number,
'cpo_partner_id': self.cpo_partner_id.id,
'cpo_bom_supply': self.cpo_bom_supply,
'cpo_scr_bom_id': self.id,
'cpo_product_id': self.cpo_product_id.id,
})
for line in self.cpo_bom_line_id:
values = {
'cpo_bom_id': eng_bom_obj.id,
'cpo_bom_line_name': line.cpo_bom_line_name,
'cpo_item': line.cpo_item,
'cpo_qty': line.cpo_qty,
'cpo_pn': line.cpo_pn,
'cpo_detail': line.cpo_detail,
'cpo_supplier': line.cpo_supplier,
'cpo_supplier_pn': line.cpo_supplier_pn,
'cpo_mfr': line.cpo_mfr,
'cpo_mfr_pn': line.cpo_mfr_pn,
'cpo_all_qty': line.cpo_qty * self.cpo_bom_pcb_number
}
eng_bom_line.create(values)
self.state = 'over'
self.ensure_one()
form_view = self.env.ref('cpo_bom.view_eng_bom_form') # view_eng_bom_form 是对应的form视图, cpo_bom是他对应的models
return {
'type': 'ir.actions.act_window',
'name': _('ENG BOM'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'bom.eng_bom',
'res_id': eng_bom_obj.id, # res_id是此次新增数据的id
'view_id': False, #
'views': [
(form_view.id, 'form'),
],
}