Skip to Content
Menu
This question has been flagged
1 Reply
3888 Views

here  i am tring to import bom from xls file by bottun in wizard and it just take first Component 

from BoM Lines/Component

here my xls file ::::::::::

 

Product Quantity BoM Type BoM Lines/Component qty
Test-gahdadadada 3 normal Office Chair Black 2

3 normal Corner Desk Left Sit 2

3 normal Drawer Black 2
Test-gahdadadada22 3 normal Office Chair Black 2

3 normal Corner Desk Left Sit 2

3 normal Drawer Black 2

//here my code 


def import_bom(self):
try:
wb = xlrd.open_workbook(filename=self.file_name)
except FileNotFoundError:
raise UserError('No such file or directory found. \n%s.' % self.file_name)
sheet = wb.sheet_by_index(0)
for row in range(sheet.nrows):
if row >= 1:
product_lines=[]
row_vals = sheet.row_values(row)
product_tmpl_id = self.env['product.template'].search([("name", "ilike", row_vals[0])], limit=1)
# bom_line_ids = self.env['mrp.bom.line'].search([("product_id.name", "ilike", row_vals[3]), ("product_qty", "=", row_vals[4])])
line_products = self.env['product.product'].search([("name", "ilike", row_vals[3])])
# print("llllllllllllllllllllllllllllline",line_products.name)
BomLine = self.env['mrp.bom.line']

mrp_bom_id = self.env['mrp.bom'].create({
'product_tmpl_id': product_tmpl_id.id,
'product_qty': row_vals[1],
'type': row_vals[2],

})
print("product_tmpl_id in mrp line =============",product_tmpl_id)
for r in mrp_bom_id:
for line in line_products:
BomLine.create({
'product_id': line.id,
'product_qty': row_vals[4],
'bom_id': mrp_bom_id.id
})


Avatar
Discard
Best Answer

The module named "VKS Import Excel" can help you solve this problem easily: https://apps.odoo.com/apps/modules/16.0/vks_import_excel.  Please contact me via email anhtuan.acoi@gmail.com  if you need further assistance.

Avatar
Discard