This commit is contained in:
parent
61a746c2d8
commit
7ba2e8d4c5
|
@ -979,6 +979,13 @@ INSERT INTO `vn`.`priceFixed`(`id`, `itemFk`, `rate0`, `rate1`, `rate2`, `rate3`
|
|||
(2, 3, 10, 10, 10, 10, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 0, 1, util.VN_CURDATE()),
|
||||
(3, 13, 8.5, 10, 7.5, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 1, 2, util.VN_CURDATE());
|
||||
|
||||
INSERT INTO `vn`.`itemMinimumQuantity`(`itemFk`, `quantity`, `started`, `ended`, `warehouseFk`)
|
||||
VALUES
|
||||
(1, 5, util.VN_CURDATE() - INTERVAL 4 DAY, util.VN_CURDATE() + INTERVAL 1 MONTH, 1),
|
||||
(2, 10, util.VN_CURDATE() - INTERVAL 2 DAY, NULL, 2),
|
||||
(3, 15, util.VN_CURDATE() + INTERVAL 3 DAY, util.VN_CURDATE() + INTERVAL 2 WEEK, 3),
|
||||
(2, 10, util.VN_CURDATE() + INTERVAL 2 MONTH, NULL, 5);
|
||||
|
||||
INSERT INTO `vn`.`expeditionBoxVol`(`boxFk`, `m3`, `ratio`)
|
||||
VALUES
|
||||
(71,0.141,1);
|
||||
|
|
|
@ -127,15 +127,15 @@ module.exports = Self => {
|
|||
w.firstName,
|
||||
tci.priceKg,
|
||||
ink.hex,
|
||||
i.minQuantity
|
||||
mq.quantity minQuantity
|
||||
FROM tmp.ticketCalculateItem tci
|
||||
JOIN vn.item i ON i.id = tci.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.worker w on w.id = it.workerFk
|
||||
LEFT JOIN vn.ink ON ink.id = i.inkFk
|
||||
LEFT JOIN tmp.ticketComponentPrice tcp ON tcp.itemFk = i.id
|
||||
LEFT JOIN tmp.ticketLot tl ON tl.itemFk = i.id
|
||||
LEFT JOIN minQuantity mq ON mq.itemFk = i.id
|
||||
AND (mq.warehouseFk = tpc.warehouseFk OR mq.warehouseFk IS NULL)
|
||||
AND (mq.warehouseFk = tl.warehouseFk OR mq.warehouseFk IS NULL)
|
||||
`);
|
||||
|
||||
// Apply order by tag
|
||||
|
|
|
@ -112,7 +112,7 @@ module.exports = Self => {
|
|||
limit: 1
|
||||
}, ctx.options);
|
||||
|
||||
if (newQuantity < minQuantity.quantity && newQuantity != available)
|
||||
if (newQuantity < minQuantity?.quantity && newQuantity != available)
|
||||
throw new UserError('The amount cannot be less than the minimum');
|
||||
|
||||
if (ctx.isNewInstance || isReduction) return;
|
||||
|
|
|
@ -112,14 +112,10 @@ describe('sale model ', () => {
|
|||
it('should throw an error if the quantity is less than the minimum quantity of the item', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const itemId = 2;
|
||||
const saleId = 17;
|
||||
const minQuantity = 30;
|
||||
const newQuantity = minQuantity - 1;
|
||||
const newQuantity = 1;
|
||||
|
||||
try {
|
||||
const item = await models.Item.findById(itemId, null, opts);
|
||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY
|
||||
|
@ -138,13 +134,8 @@ describe('sale model ', () => {
|
|||
it('should change quantity if has minimum quantity and new quantity is equal than item available', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const itemId = 2;
|
||||
const saleId = 17;
|
||||
const minQuantity = 30;
|
||||
const newQuantity = minQuantity - 1;
|
||||
|
||||
const item = await models.Item.findById(itemId, null, opts);
|
||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
||||
const newQuantity = 8;
|
||||
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
|
@ -162,13 +153,9 @@ describe('sale model ', () => {
|
|||
it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const itemId = 2;
|
||||
const saleId = 17;
|
||||
const minQuantity = 30;
|
||||
const newQuantity = 31;
|
||||
|
||||
const item = await models.Item.findById(itemId, null, opts);
|
||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
sqlStatement = `
|
||||
|
@ -185,13 +172,9 @@ describe('sale model ', () => {
|
|||
it('should increase quantity when the new price is lower than the previous one', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const itemId = 2;
|
||||
const saleId = 17;
|
||||
const minQuantity = 30;
|
||||
const newQuantity = 31;
|
||||
|
||||
const item = await models.Item.findById(itemId, null, opts);
|
||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
sqlStatement = `
|
||||
|
@ -208,14 +191,10 @@ describe('sale model ', () => {
|
|||
it('should throw error when increase quantity and the new price is higher than the previous one', async() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true));
|
||||
|
||||
const itemId = 2;
|
||||
const saleId = 17;
|
||||
const minQuantity = 30;
|
||||
const newQuantity = 31;
|
||||
|
||||
try {
|
||||
const item = await models.Item.findById(itemId, null, opts);
|
||||
await item.updateAttribute('minQuantity', minQuantity, opts);
|
||||
spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => {
|
||||
if (sqlStatement.includes('catalog_calcFromItem')) {
|
||||
sqlStatement = `
|
||||
|
|
Loading…
Reference in New Issue