add and get sales now sets item.price from packaging for EMB items
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
df9373aded
commit
72a0b774de
|
@ -774,25 +774,25 @@ INSERT INTO `vn`.`intrastat`(`id`, `description`, `taxClassFk`, `taxCodeFk`)
|
|||
(05080000, 'Coral y materiales similares', 2, 2),
|
||||
(06021010, 'Plantas vivas: Esqueje/injerto, Vid', 1, 1);
|
||||
|
||||
INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `isOnOffer`, `expenceFk`, `isBargain`, `comment`, `relevancy`, `image`, `taxClassFk`, `subName`, `minPrice`, `stars`)
|
||||
INSERT INTO `vn`.`item`(`id`, `typeFk`, `size`, `inkFk`, `stems`, `originFk`, `description`, `producerFk`, `intrastatFk`, `isOnOffer`, `expenceFk`, `isBargain`, `comment`, `relevancy`, `image`, `taxClassFk`, `subName`, `minPrice`, `stars`, `family`)
|
||||
VALUES
|
||||
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '1', 1, NULL, 0, 1),
|
||||
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '2', 1, NULL, 0, 2),
|
||||
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 0, 4751000000, 0, NULL, 0, '3', 1, NULL, 0, 5),
|
||||
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 1, 4751000000, 0, NULL, 0, '4', 2, NULL, 0, 3),
|
||||
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 1, 4751000000, 0, NULL, 0, '5', 2, NULL, 0, 3),
|
||||
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '6', 2, NULL, 0, 4),
|
||||
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '7', 2, NULL, 0, 4),
|
||||
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '8', 1, NULL, 0, 5),
|
||||
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '9', 1, NULL, 0, 4),
|
||||
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 0, 4751000000, 0, NULL, 0, '10', 1, NULL, 0, 4),
|
||||
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 1, 4751000000, 0, NULL, 0, '11', 2, NULL, 0, 4),
|
||||
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 1, 4751000000, 0, NULL, 0, '12', 2, NULL, 0, 3),
|
||||
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '13', 2, NULL, 0, 2),
|
||||
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 4),
|
||||
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0),
|
||||
(16, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0),
|
||||
(71, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 1, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0);
|
||||
(1, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '1', 1, NULL, 0, 1, 'VT'),
|
||||
(2, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '2', 1, NULL, 0, 2, 'VT'),
|
||||
(3, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 0, 4751000000, 0, NULL, 0, '3', 1, NULL, 0, 5, 'VT'),
|
||||
(4, 1, 60, 'YEL', 1, 1, 'Increases block', 1, 05080000, 1, 4751000000, 0, NULL, 0, '4', 2, NULL, 0, 3, 'VT'),
|
||||
(5, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 1, 4751000000, 0, NULL, 0, '5', 2, NULL, 0, 3, 'VT'),
|
||||
(6, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '6', 2, NULL, 0, 4, 'VT'),
|
||||
(7, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '7', 2, NULL, 0, 4, 'VT'),
|
||||
(8, 2, 70, 'YEL', 1, 1, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '8', 1, NULL, 0, 5, 'VT'),
|
||||
(9, 2, 70, 'BLU', 1, 2, NULL, 1, 06021010, 0, 2000000000, 0, NULL, 0, '9', 1, NULL, 0, 4, 'VT'),
|
||||
(10, 1, 60, 'YEL', 1, 3, NULL, 1, 05080000, 0, 4751000000, 0, NULL, 0, '10', 1, NULL, 0, 4, 'VT'),
|
||||
(11, 1, 60, 'YEL', 1, 1, NULL, 1, 05080000, 1, 4751000000, 0, NULL, 0, '11', 2, NULL, 0, 4, 'VT'),
|
||||
(12, 3, 30, 'RED', 1, 2, NULL, 2, 06021010, 1, 4751000000, 0, NULL, 0, '12', 2, NULL, 0, 3, 'VT'),
|
||||
(13, 5, 30, 'RED', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '13', 2, NULL, 0, 2, 'VT'),
|
||||
(14, 5, 90, 'BLU', 1, 2, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 4, 'VT'),
|
||||
(15, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0, 'EMB'),
|
||||
(16, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 0, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0, 'VT'),
|
||||
(71, 4, NULL, NULL, NULL, 1, NULL, NULL, 06021010, 1, 4751000000, 0, NULL, 0, '', 2, NULL, 0, 0, 'VT');
|
||||
|
||||
INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`, `started`, `ended`, `bonus`, `warehouseFk`, `created`)
|
||||
VALUES
|
||||
|
|
|
@ -124,6 +124,10 @@
|
|||
"type": "boolean",
|
||||
"description": "Price per Kg"
|
||||
},
|
||||
"family": {
|
||||
"type": "string",
|
||||
"description": "The item family"
|
||||
},
|
||||
"expenseFk": {
|
||||
"type": "number",
|
||||
"mysql": {
|
||||
|
@ -190,6 +194,11 @@
|
|||
"type": "hasMany",
|
||||
"model": "ItemNiche",
|
||||
"foreignKey": "itemFk"
|
||||
},
|
||||
"packaging": {
|
||||
"type": "hasOne",
|
||||
"model": "Packaging",
|
||||
"foreignKey": "itemFk"
|
||||
}
|
||||
},
|
||||
"scope": {
|
||||
|
|
|
@ -44,7 +44,8 @@ module.exports = Self => {
|
|||
|
||||
const res = await models.Item.getVisibleAvailable(itemId, ticket.warehouseFk, ticket.shipped);
|
||||
|
||||
if (res.available < quantity)
|
||||
const whitelitedFamily = item.family == 'EMB';
|
||||
if (!whitelitedFamily && res.available < quantity)
|
||||
throw new UserError(`This item is not available`);
|
||||
|
||||
const newSale = await models.Sale.create({
|
||||
|
@ -56,10 +57,22 @@ module.exports = Self => {
|
|||
|
||||
await Self.rawSql('CALL vn.sale_calculateComponent(?, NULL)', [newSale.id]);
|
||||
|
||||
return models.Sale.findById(newSale.id, {
|
||||
const sale = await models.Sale.findById(newSale.id, {
|
||||
include: {
|
||||
relation: 'item'
|
||||
relation: 'item',
|
||||
scope: {
|
||||
include: {
|
||||
relation: 'packaging',
|
||||
scope: {
|
||||
fields: ['id', 'price']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (whitelitedFamily) sale.price = sale.item().packaging().price;
|
||||
|
||||
return sale;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -31,8 +31,14 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
let filter = {
|
||||
fields: ['id', 'name', 'tag5', 'value5', 'tag6', 'value6', 'tag7', 'value7', 'tag8', 'value8', 'tag9', 'value9', 'tag10', 'value10'],
|
||||
where: {id: {inq: ids}}
|
||||
where: {id: {inq: ids}},
|
||||
fields: ['id', 'name', 'family', 'tag5', 'value5', 'tag6', 'value6', 'tag7', 'value7', 'tag8', 'value8', 'tag9', 'value9', 'tag10', 'value10'],
|
||||
include: {
|
||||
relation: 'packaging',
|
||||
scope: {
|
||||
fields: ['id', 'price']
|
||||
}
|
||||
}
|
||||
};
|
||||
let items = await Self.app.models.Item.find(filter);
|
||||
|
||||
|
@ -52,6 +58,10 @@ module.exports = Self => {
|
|||
|
||||
for (line of lines) {
|
||||
line.item = map[line.itemFk];
|
||||
|
||||
const embItem = line.item.family == 'EMB';
|
||||
if (embItem) line.price = line.item.packaging().price;
|
||||
|
||||
line.claim = claimMap[line.id];
|
||||
}
|
||||
return lines;
|
||||
|
|
Loading…
Reference in New Issue