Skip to content

Commit

Permalink
fix(products): import barcodes and subuoms
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhsaikhan committed Jun 22, 2023
1 parent d405dfd commit b54acc4
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions packages/plugin-products-api/src/imports.ts
Expand Up @@ -53,6 +53,8 @@ export default {
const models = await generateModels(subdomain);
const { result, properties } = data;

const defaultUom = await models.ProductsConfigs.getConfig('defaultUOM', '');

const bulkDoc: any = [];

// Iterating field values
Expand All @@ -62,7 +64,6 @@ export default {
};

let colIndex: number = 0;
let barcodes = [];
let subUomNames = [];
let ratios = [];

Expand Down Expand Up @@ -127,29 +128,27 @@ export default {

case 'barcodes':
{
barcodes = value.replace(/\s/g, '').split(',');
barcodes = barcodes.filter(br => br);
doc.barcodes = value
.replace(/\s/g, '')
.split(',')
.filter(br => br);
}
break;

case 'subUoms.uom':
{
subUomNames = value.split(',');
subUomNames = value.replace(/\s/g, '').split(',');
}
break;

case 'subUoms.ratio':
{
ratios = value.split(',');
ratios = value.replace(/\s/g, '').split(',');
}
break;

case 'uom':
{
const defaultUom = await models.ProductsConfigs.getConfig(
'defaultUOM',
''
);
doc.uom = value || defaultUom;
}
break;
Expand Down Expand Up @@ -179,18 +178,10 @@ export default {
let ind = 0;
const subUoms: any = [];

for (const uomVal of subUomNames) {
const uom = await models.Uoms.findOne({
$or: [{ name: uomVal }, { code: uomVal }]
}).lean();
if (!uom) {
ind += 1;
continue;
}

for (const uom of subUomNames) {
subUoms.push({
id: Math.random(),
uom,
uom: uom,
ratio: Number(ratios[ind] || 1)
});
ind += 1;
Expand Down

0 comments on commit b54acc4

Please sign in to comment.