My product codes are unique, and I want to use them for importing instead of using names. How can I accomplish this? I greatly appreciate any assistance.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
- Create a Python function that performs the conversion. This function will take the product name as a parameter, search for the product based on its name, and return its internal code.
from odoo import api, models
class YourBOMImportModel(models.Model):
_name = 'your.bom.import.model'
@api.model
def convert_product_name_to_code(self, product_name):
product = self.env['product.product'].search([('name', '=', product_name)], limit=1)
if product:
return product.default_code
return False
In your import logic, call the convert_product_name_to_code function for each BOM line to convert the product name to its internal code.
# Assuming you have a list of BOM lines with product names
bom_lines = [{'product_name': 'Product A'}, {'product_name': 'Product B'}]
bom_import_model = self.env['your.bom.import.model']
for line in bom_lines:
product_name = line['product_name']
product_code = bom_import_model.convert_product_name_to_code(product_name)
if product_code:
# Use the product code in your import logic
line['product_code'] = product_code
else:
# Handle the case when the product name doesn't exist or conversion fails
line['product_code'] = ''
In the above code, convert_product_name_to_code method performs a search on the product.product model based on the product name. It retrieves the first product that matches the name and returns its default_code field value (the internal code). If no product is found, it returns False.
You can then integrate this code into your BOM import process, where you iterate through each BOM line and call the convert_product_name_to_code function to convert the product name to its internal code. Update your BOM line data with the product code accordingly.
Thank you for your support, it means a lot to me. However, as a beginner programmer, I have limited knowledge of the Excel import process. I'm unsure about how to override the default Excel import process in Odoo. I want to import data using the 'default_code' field, but Odoo requires 'externalId' and the product name, which doesn't align with my requirements.
Hi TTN SOLUTION,
I think this video can help you: https://www.youtube.com/watch?v=UOBxxnYDIsM&list=PLSKcWRTtEl5qzvRaI-VTGavfReiHS_EEb&index=1
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
RegistracijaRelated Posts | Replies | Rodiniai | Veikla | |
---|---|---|---|---|
|
1
saus. 25
|
587 | ||
|
3
liep. 18
|
10420 | ||
|
0
bal. 25
|
13 | ||
|
1
kov. 25
|
463 | ||
|
3
vas. 25
|
354 |