3381-item_diary-claim only the claim contains the item #792

Merged
carlosjr merged 3 commits from 3381-item_diary-claim into dev 2021-11-22 14:21:20 +00:00
10 changed files with 153 additions and 28 deletions
Showing only changes of commit ca0c3be843 - Show all commits

View File

@ -47,19 +47,20 @@ TABLES=(
cplusSubjectOp cplusSubjectOp
cplusTaxBreak cplusTaxBreak
cplusTrascendency472 cplusTrascendency472
pgc
time
claimResponsible claimResponsible
claimReason claimReason
claimRedelivery claimRedelivery
claimResult claimResult
ticketUpdateAction
state
sample
department
component component
componentType componentType
continent continent
department
itemPackingType
pgc
sample
state
ticketUpdateAction
time
volumeConfig volumeConfig
) )
dump_tables ${TABLES[@]} dump_tables ${TABLES[@]}

View File

@ -116,6 +116,7 @@
&:active, &:active,
&:valid { &:valid {
box-shadow: 0 0 0 40px $color-bg-panel inset; box-shadow: 0 0 0 40px $color-bg-panel inset;
-webkit-text-fill-color: $color-primary-medium
} }
} }
} }
@ -198,7 +199,7 @@
} }
&.standout { &.standout {
border-radius: 1px; border-radius: 1px;
background-color: rgba(255, 255, 255, .1); background-color: rgba(161, 161, 161, 0.1);
padding: 0 12px; padding: 0 12px;
transition-property: background-color, color; transition-property: background-color, color;
transition-duration: 200ms; transition-duration: 200ms;
@ -208,6 +209,17 @@
& > .underline { & > .underline {
display: none; display: none;
} }
& > .infix > .control > input {
&:-internal-autofill-selected {
&,
&:hover,
&:active,
&:valid {
box-shadow: 0 0 0 40px #474747 inset;
-webkit-text-fill-color: $color-font-dark
}
}
}
& > .infix > .control > * { & > .infix > .control > * {
color: $color-font-dark; color: $color-font-dark;
@ -225,6 +237,17 @@
background-color: $color-font-dark; background-color: $color-font-dark;
& > .container { & > .container {
& > .infix > .control > input {
&:-internal-autofill-selected {
&,
&:hover,
&:active,
&:valid {
box-shadow: 0 0 0 40px $color-font-dark inset;
-webkit-text-fill-color: $color-font-bg
}
}
}
& > .infix > .control > * { & > .infix > .control > * {
color: $color-marginal; color: $color-marginal;

View File

@ -23,9 +23,12 @@ vn-layout {
padding-right: 16px; padding-right: 16px;
overflow: hidden; overflow: hidden;
& > .logo > img { & > .logo {
height: 32px; outline: 0;
display: block; & > img {
height: 32px;
display: block;
}
} }
& > .main-title { & > .main-title {
font-size: 1.56rem; font-size: 1.56rem;

View File

@ -212,5 +212,6 @@
"You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito", "You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito",
"You can't change the credit set to zero from a manager": "No puedes cambiar el cŕedito establecido a cero por un gerente", "You can't change the credit set to zero from a manager": "No puedes cambiar el cŕedito establecido a cero por un gerente",
"The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'", "The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'",
"The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos" "The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos",
"You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días"
} }

View File

@ -57,8 +57,14 @@ module.exports = Self => {
} }
}, myOptions); }, myOptions);
const landedPlusWeek = new Date(ticket.landed);
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
const isClaimable = landedPlusWeek >= new Date();
if (ticket.isDeleted) if (ticket.isDeleted)
throw new UserError(`You can't create a claim for a removed ticket`); throw new UserError(`You can't create a claim for a removed ticket`);
if (!isClaimable)
throw new UserError(`You can't create a claim from a ticket delivered more than seven days ago`);
const newClaim = await Self.create({ const newClaim = await Self.create({
ticketFk: ticketId, ticketFk: ticketId,

View File

@ -1,31 +1,40 @@
const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('Claim createFromSales()', () => { describe('Claim createFromSales()', () => {
const ticketId = 2; const ticketId = 16;
const newSale = [{ const newSale = [{
id: 3, id: 3,
instance: 0, instance: 0,
quantity: 10 quantity: 10
}]; }];
const ctx = { const activeCtx = {
req: { accessToken: {userId: 1},
accessToken: {userId: 1}, headers: {origin: 'localhost:5000'},
headers: {origin: 'localhost:5000'}, __: () => {}
__: () => {}
}
}; };
const ctx = {
req: activeCtx
};
beforeEach(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
});
it('should create a new claim', async() => { it('should create a new claim', async() => {
const tx = await app.models.Claim.beginTransaction({}); const tx = await models.Claim.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const claim = await app.models.Claim.createFromSales(ctx, ticketId, newSale, options); const claim = await models.Claim.createFromSales(ctx, ticketId, newSale, options);
expect(claim.ticketFk).toEqual(ticketId); expect(claim.ticketFk).toEqual(ticketId);
let claimBeginning = await app.models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options); let claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options);
expect(claimBeginning.saleFk).toEqual(newSale[0].id); expect(claimBeginning.saleFk).toEqual(newSale[0].id);
expect(claimBeginning.quantity).toEqual(newSale[0].quantity); expect(claimBeginning.quantity).toEqual(newSale[0].quantity);
@ -37,17 +46,42 @@ describe('Claim createFromSales()', () => {
} }
}); });
it('should not be able to create a claim if exists that sale', async() => { it('should not be able to create a claim for a ticket delivered more than seven days ago', async() => {
const tx = await app.models.Claim.beginTransaction({}); const tx = await models.Claim.beginTransaction({});
let error; let error;
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
await app.models.Claim.createFromSales(ctx, ticketId, newSale, options); const todayMinusEightDays = new Date();
todayMinusEightDays.setDate(todayMinusEightDays.getDate() - 8);
await app.models.Claim.createFromSales(ctx, ticketId, newSale, options); const ticket = await models.Ticket.findById(ticketId, options);
await ticket.updateAttribute('landed', todayMinusEightDays, options);
await models.Claim.createFromSales(ctx, ticketId, newSale, options);
await tx.rollback();
} catch (e) {
error = e;
await tx.rollback();
}
expect(error.toString()).toContain(`You can't create a claim from a ticket delivered more than seven days ago`);
});
it('should not be able to create a claim if exists that sale', async() => {
const tx = await models.Claim.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await models.Claim.createFromSales(ctx, ticketId, newSale, options);
await models.Claim.createFromSales(ctx, ticketId, newSale, options);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -0,0 +1,26 @@
{
"name": "ItemPackingType",
"base": "VnModel",
"options": {
"mysql": {
"table": "itemPackingType"
}
},
"properties": {
"code": {
"type": "string",
"id": true
},
"description": {
"type": "string"
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -469,7 +469,8 @@
</vn-item> </vn-item>
<vn-item translate <vn-item translate
name="claim" name="claim"
ng-click="$ctrl.createClaim()"> ng-click="$ctrl.createClaim()"
ng-if="$ctrl.isClaimable">
Add claim Add claim
</vn-item> </vn-item>
<vn-item translate <vn-item translate

View File

@ -35,6 +35,16 @@ class Controller extends Section {
return ticketState && ticketState.state.code; return ticketState && ticketState.state.code;
} }
get isClaimable() {
if (this.ticket) {
const landedPlusWeek = new Date(this.ticket.landed);
landedPlusWeek.setDate(landedPlusWeek.getDate() + 7);
return landedPlusWeek >= new Date();
}
return false;
}
getSaleTotal(sale) { getSaleTotal(sale) {
if (sale.quantity == null || sale.price == null) if (sale.quantity == null || sale.price == null)
return null; return null;

View File

@ -15,7 +15,8 @@ describe('Ticket', () => {
const ticket = { const ticket = {
id: 1, id: 1,
clientFk: 1101, clientFk: 1101,
shipped: 1, shipped: new Date(),
landed: new Date(),
created: new Date(), created: new Date(),
client: {salesPersonFk: 1}, client: {salesPersonFk: 1},
address: {mobile: 111111111} address: {mobile: 111111111}
@ -74,6 +75,25 @@ describe('Ticket', () => {
}); });
}); });
describe('isClaimable() getter', () => {
it('should return true for a ticket delivered less than seven days ago', () => {
const result = controller.isClaimable;
expect(result).toEqual(true);
});
it('should return false for a ticket delivered more than seven days ago', () => {
const ticket = controller.ticket;
const landedMinusEightDays = new Date(ticket.landed);
landedMinusEightDays.setDate(landedMinusEightDays.getDate() - 8);
ticket.landed = landedMinusEightDays;
const result = controller.isClaimable;
expect(result).toEqual(false);
});
});
describe('getSaleTotal()', () => { describe('getSaleTotal()', () => {
it('should return the sale total amount', () => { it('should return the sale total amount', () => {
const sale = { const sale = {