Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Javi Gallego 2023-10-11 14:06:32 +02:00
commit 393d1889f7
24 changed files with 245 additions and 38 deletions

View File

@ -0,0 +1,6 @@
UPDATE `vn`.`supplier`
SET account = LPAD(id,10,'0')
WHERE account IS NULL;
ALTER TABLE `vn`.`supplier` ADD CONSTRAINT supplierAccountTooShort CHECK (LENGTH(account) = 10);
ALTER TABLE `vn`.`supplier` MODIFY COLUMN account varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT 4100000000 NOT NULL COMMENT 'Default accounting code for suppliers.';

View File

@ -216,6 +216,7 @@
"The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día", "The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día",
"The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día", "The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día",
"You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado",
"The account size must be exactly 10 characters": "El tamaño de la cuenta debe ser exactamente de 10 caracteres",
"Can't transfer claimed sales": "No puedes transferir lineas reclamadas", "Can't transfer claimed sales": "No puedes transferir lineas reclamadas",
"You don't have privileges to create refund": "No tienes permisos para crear un abono", "You don't have privileges to create refund": "No tienes permisos para crear un abono",
"The item is required": "El artículo es requerido", "The item is required": "El artículo es requerido",

View File

@ -33,6 +33,12 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The company id', description: 'The company id',
required: true required: true
},
{
arg: 'addressId',
type: 'number',
description: 'The address id',
required: true
} }
], ],
returns: { returns: {

View File

@ -21,6 +21,12 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The company id', description: 'The company id',
required: true required: true
},
{
arg: 'addressId',
type: 'number',
description: 'The address id',
required: true
} }
], ],
returns: [ returns: [

View File

@ -21,6 +21,12 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The company id', description: 'The company id',
required: true required: true
},
{
arg: 'addressId',
type: 'number',
description: 'The address id',
required: true
} }
], ],
returns: [ returns: [

View File

@ -8,11 +8,12 @@
auto-load="true" auto-load="true"
url="Samples/visible" url="Samples/visible"
fields="[ fields="[
'id', 'id',
'code', 'code',
'description', 'description',
'model', 'model',
'hasCompany', 'hasCompany',
'hasAddress',
'hasPreview', 'hasPreview',
'datepickerEnabled' 'datepickerEnabled'
]" ]"
@ -65,10 +66,36 @@
model="ClientSample.companyFk" model="ClientSample.companyFk"
data="companiesData" data="companiesData"
show-field="code" show-field="code"
label="Company" label="Company"
ng-if="sampleType.selection.hasCompany" ng-if="sampleType.selection.hasCompany"
required="true"> required="true">
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete
ng-if="sampleType.selection.id == 20"
vn-one
required="true"
data="$ctrl.addresses"
label="Address"
show-field="nickname"
value-field="id"
ng-model="$ctrl.addressId"
model="ClientSample.addressFk"
order="isActive DESC">
<tpl-item class="address" ng-class="::{inactive: !isActive}">
<span class="inactive" translate>{{::!isActive ? '(Inactive)' : ''}}</span>
{{::nickname}}
<span ng-show="city || province || street">
, {{::street}}, {{::city}}, {{::province.name}} - {{::agencyMode.name}}
</span>
</tpl-item>
<append>
<vn-icon-button
ui-sref="client.card.address.edit({id: $ctrl.clientId, addressId: $ctrl.addressId})"
icon="edit"
vn-tooltip="Edit address">
</vn-icon-button>
</append>
</vn-autocomplete>
<vn-date-picker <vn-date-picker
vn-one vn-one
label="From" label="From"
@ -85,7 +112,7 @@
</vn-submit> </vn-submit>
<vn-button <vn-button
disabled="!sampleType.selection.hasPreview" disabled="!sampleType.selection.hasPreview"
label="Preview" label="Preview"
ng-click="$ctrl.preview()"> ng-click="$ctrl.preview()">
</vn-button> </vn-button>
<vn-button <vn-button

View File

@ -15,8 +15,10 @@ class Controller extends Section {
set client(value) { set client(value) {
this._client = value; this._client = value;
if (value) if (value) {
this.setClientSample(value); this.setClientSample(value);
this.clientAddressesList(value.id);
}
} }
get companyId() { get companyId() {
@ -29,6 +31,16 @@ class Controller extends Section {
this.clientSample.companyFk = value; this.clientSample.companyFk = value;
} }
get addressId() {
if (!this.clientSample.addressId)
this.clientSample.addressId = this.client.defaultAddressFk;
return this.clientSample.addressId;
}
set addressId(value) {
this.clientSample.addressId = value;
}
onSubmit() { onSubmit() {
this.$.watcher.check(); this.$.watcher.check();
@ -65,6 +77,9 @@ class Controller extends Section {
if (sampleType.datepickerEnabled) if (sampleType.datepickerEnabled)
params.from = this.clientSample.from; params.from = this.clientSample.from;
if (this.clientSample.addressId)
params.addressId = this.clientSample.addressId;
} }
preview() { preview() {
@ -126,6 +141,40 @@ class Controller extends Section {
}; };
}); });
} }
clientAddressesList(value) {
let filter = {
include: [
{
relation: 'province',
scope: {
fields: ['name']
}
},
{
relation: 'agencyMode',
scope: {
fields: ['name']
}
}
]
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `Clients/${value}/addresses?filter=${filter}`;
this.$http.get(query).then(res => {
if (res.data)
this.addresses = res.data;
});
}
getClientDefaultAddress(value) {
let query = `Clients/${value}`;
this.$http.get(query).then(res => {
if (res.data)
this.addressId = res.data.defaultAddressFk;
});
}
} }
Controller.$inject = ['$element', '$scope', 'vnEmail']; Controller.$inject = ['$element', '$scope', 'vnEmail'];

View File

@ -32,6 +32,7 @@ describe('Supplier newSupplier()', () => {
const result = await models.Supplier.newSupplier(ctx, options); const result = await models.Supplier.newSupplier(ctx, options);
expect(result.name).toEqual('newSupplier'); expect(result.name).toEqual('newSupplier');
await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
throw e; throw e;

View File

@ -123,5 +123,21 @@ describe('loopback model Supplier', () => {
throw e; throw e;
} }
}); });
it('should update the account attribute when a new supplier is created', async() => {
const tx = await models.Supplier.beginTransaction({});
const options = {transaction: tx};
try {
const newSupplier = await models.Supplier.create({name: 'Alfred Pennyworth'}, options);
const fetchedSupplier = await models.Supplier.findById(newSupplier.id, null, options);
expect(Number(fetchedSupplier.account)).toEqual(4100000000 + newSupplier.id);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
}); });
}); });

View File

@ -117,6 +117,16 @@ module.exports = Self => {
throw new UserError('You can not modify is pay method checked'); throw new UserError('You can not modify is pay method checked');
}); });
Self.observe('after save', async function(ctx) {
if (ctx.instance && ctx.isNewInstance) {
const {id} = ctx.instance;
const {Supplier} = Self.app.models;
const supplier = await Supplier.findById(id, null, ctx.options);
await supplier?.updateAttribute('account', Number(supplier.account) + id, ctx.options);
}
});
Self.validateAsync('name', 'countryFk', hasSupplierSameName, { Self.validateAsync('name', 'countryFk', hasSupplierSameName, {
message: 'A supplier with the same name already exists. Change the country.' message: 'A supplier with the same name already exists. Change the country.'
}); });

View File

@ -18,7 +18,6 @@
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit <vn-submit
disabled="!watcher.dataChanged()"
label="Create"> label="Create">
</vn-submit> </vn-submit>
<vn-button <vn-button

View File

@ -28,6 +28,10 @@ module.exports = {
companyId: { companyId: {
type: Number, type: Number,
required: true required: true
},
addressId: {
type: Number,
required: true
} }
} }
}; };

View File

@ -0,0 +1,12 @@
const Stylesheet = require(`vn-print/core/stylesheet`);
const path = require('path');
const vnPrintPath = path.resolve('print');
module.exports = new Stylesheet([
`${vnPrintPath}/common/css/spacing.css`,
`${vnPrintPath}/common/css/misc.css`,
`${vnPrintPath}/common/css/layout.css`,
`${vnPrintPath}/common/css/email.css`,
`${__dirname}/style.css`])
.mergeStyles();

View File

@ -0,0 +1,8 @@
.jsonSection {
text-align: left;
background-color: #e4e4e4;
padding: 25px;
margin-left: 60px;
margin-right: 60px;
border-radius: 25px;
}

View File

@ -0,0 +1,3 @@
subject: Modified collection volumetry
title: Modified collection volumetry
description: Action performed

View File

@ -0,0 +1,3 @@
subject: Volumetría de colección modificada
title: Volumetría de colección modificada
description: Acción realizada

View File

@ -0,0 +1,15 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<div class="centered">
<h1>{{ $t('title') }}</h1>
<h3>{{ $t('description') }}: <u>{{ data.action }}</u> <i> {{ `(${this.username})` }} </i></h3>
<div class="jsonSection">
<span v-for="(value, key) in data" v-if="key !== 'action' && key !== 'userFk'">
<b> {{ `${key}:` }} </b> {{ value }} <br>
</span>
</div>
</div>
</div>
</div>
</email-body>

View File

@ -0,0 +1,25 @@
const Component = require(`vn-print/core/component`);
const emailBody = new Component('email-body');
const models = require('vn-loopback/server/server').models;
module.exports = {
name: 'modified-collection-volumetry',
components: {
'email-body': emailBody.build(),
},
async serverPrefetch() {
this.username = (this.data.userFk) ? await this.getUsername(this.data.userFk) : 'system';
},
methods: {
async getUsername(id) {
const account = await models.VnUser.findById(id);
return account.name;
}
},
props: {
data: {
type: Object,
required: true
}
}
};

View File

@ -3,16 +3,16 @@
<div class="grid-block"> <div class="grid-block">
<p <p
v-html="$t('description', { v-html="$t('description', {
socialName: client.socialName, socialName: address.nickname,
name: client.name, name: client.name,
address: client.street, address: address.street,
country: client.country, country: client.country,
fiscalID: client.fi fiscalID: client.fi
})" })"
></p> ></p>
<p <p
v-html="$t('declaration', { v-html="$t('declaration', {
socialName: client.socialName socialName: address.nickname
})" })"
></p> ></p>
<p <p
@ -20,7 +20,7 @@
v-html="$t('declarations[' + $index + ']', { v-html="$t('declarations[' + $index + ']', {
companyName: company.name, companyName: company.name,
companyCity: company.city, companyCity: company.city,
socialName: client.socialName, socialName: address.nickname,
destinationCountry: client.country destinationCountry: client.country
})" })"
></p> ></p>

View File

@ -7,6 +7,7 @@ module.exports = {
this.client = await this.findOneFromDef('client', [this.id]); this.client = await this.findOneFromDef('client', [this.id]);
this.checkMainEntity(this.client); this.checkMainEntity(this.client);
this.company = await this.findOneFromDef('company', [this.companyId]); this.company = await this.findOneFromDef('company', [this.companyId]);
this.address = await this.findOneFromDef('address', [this.addressId]);
}, },
props: { props: {
id: { id: {
@ -17,6 +18,10 @@ module.exports = {
companyId: { companyId: {
type: Number, type: Number,
required: true required: true
},
addressId: {
type: Number,
required: true
} }
} }
}; };

View File

@ -1,28 +1,25 @@
reportName: autorizacion-incoterms reportName: autorizacion-incoterms
description: '<em>{socialName}</em> una sociedad debidamente constituida con responsabilidad <em>limitada</em> description: '<em>{socialName}</em> una sociedad debidamente constituida con responsabilidad <em>limitada</em>
y registrada conforme al derecho de sociedades de {country} y aquí representada por y registrada conforme al derecho de sociedades de {country} y aquí representada por {socialName}, con domicilio en {address},
<span>___________________</span>. {socialName}, con domicilio en {address},
CIF <em>{fiscalID}</em>. En adelante denominada {name}.' CIF <em>{fiscalID}</em>. En adelante denominada {name}.'
issued: 'En {0}, a {1} de {2} de {3}' issued: 'En {0}, a {1} de {2} de {3}'
client: 'Cliente {0}' client: 'Cliente {0}'
declaration: '<em>{socialName}</em> declara por la presente que:' declaration: '<em>{socialName}</em> declara por la presente que:'
declarations: declarations:
- 'Todas las compras realizadas por {socialName} con {companyName} se - 'Todas las compras realizadas por {socialName} con {companyName} se entregan según las condiciones definidas en el incoterm.'
entregan, Ex Works (Incoterms), en el almacén de {companyName} situado en - '{socialName} reconoce que es importante para {companyName} tener
{companyCity}.' comprobante de la entrega intracomunitaria de la mercancía a {destinationCountry} para
- '{socialName} reconoce que es importante para {companyName} tener
comprobante de la entrega intracomunitaria de la mercancía a {destinationCountry} para
poder facturar con 0% de IVA.' poder facturar con 0% de IVA.'
- 'Por tanto, al firmar este acuerdo, {socialName} declara que todos los bienes que - 'Por tanto, al firmar este acuerdo, {socialName} declara que todos los bienes que
se compren a {companyName} serán entregados a {destinationCountry}.' se compren a {companyName} serán entregados a {destinationCountry}.'
- 'Además, {socialName} deberá, a primera solicitud de {companyName}, - 'Además, {socialName} deberá, a primera solicitud de {companyName},
proporcionar una prueba de que todos los productos comprados a {companyName} han proporcionar una prueba de que todos los productos comprados a {companyName} han
sido entregados en {destinationCountry}.' sido entregados en {destinationCountry}.'
- 'Además de lo anterior, {companyName} proporcionará a {socialName} - 'Además de lo anterior, {companyName} proporcionará a {socialName}
un resumen mensual en el que se incluyen todas las facturas (y las entregas correspondientes). un resumen mensual en el que se incluyen todas las facturas (y las entregas correspondientes).
{socialName} firmará y devolverá el resumen mensual a {companyName}, {socialName} firmará y devolverá el resumen mensual a {companyName},
S.L. dentro de los 5 días posteriores a la recepción del resumen.' S.L. dentro de los 5 días posteriores a la recepción del resumen.'
signer: signer:
representative: Representante representative: Representante
representativeRole: Cargo del representante representativeRole: Cargo del representante
signed: Fecha de firma signed: Fecha de firma
@ -39,4 +36,4 @@ months:
- 'Septiembre' - 'Septiembre'
- 'Octubre' - 'Octubre'
- 'Noviembre' - 'Noviembre'
- 'Diciembre' - 'Diciembre'

View File

@ -1,28 +1,27 @@
reportName: autorizacion-incoterms reportName: autorizacion-incoterms
description: '<em>{socialName}</em> uma sociedade devidamente constituída com responsabilidade <em>limitada e registada</em> description: '<em>{socialName}</em> uma sociedade devidamente constituída com responsabilidade <em>limitada e registada</em>
conforme ao direito de sociedades da {country} e aqui representada por conforme ao direito de sociedades da {country} e aqui representada por {socialName}, com domicílio em {address},
<span>___________________</span>. {socialName}, com domicílio em {address},
CIF <em>{fiscalID}</em>. Em adiante denominada {name}.' CIF <em>{fiscalID}</em>. Em adiante denominada {name}.'
issued: 'Em {0}, em {1} de {2} de {3}' issued: 'Em {0}, em {1} de {2} de {3}'
client: 'Cliente {0}' client: 'Cliente {0}'
declaration: '<em>{socialName}</em> declara através da presente que:' declaration: '<em>{socialName}</em> declara através da presente que:'
declarations: declarations:
- 'Todas as compras realizadas por {socialName} a {companyName} se entregam, - 'Todas as compras realizadas por {socialName} a {companyName} se entregam,
Ex Works (Incoterms), no armazém da {companyName} situado em Ex Works (Incoterms), no armazém da {companyName} situado em
{companyCity}.' {companyCity}.'
- '{socialName} reconhece ser importante para {companyName} - '{socialName} reconhece ser importante para {companyName}
ter o comprovante da entrega intracomunitária da mercadoria a {destinationCountry} ter o comprovante da entrega intracomunitária da mercadoria em {destinationCountry}
para poder faturar com 0% de IVA.' para poder faturar com 0% de IVA.'
- 'Portanto, ao assinar este acordo, {socialName} declara que todos os bens - 'Portanto, ao assinar este acordo, {socialName} declara que todos os bens
que se comprem na {companyName} serão entregues na {destinationCountry}.' que se comprem na {companyName} serão entregues na {destinationCountry}.'
- 'Além disto, {socialName} deverá, na primeira solicitude da {companyName}, - 'Além disto, {socialName} deverá, na primeira solicitude da {companyName},
proporcionar uma prova de que todos os produtos comprados na {companyName} proporcionar uma prova de que todos os produtos comprados em {companyName}
foram entregues na {destinationCountry}.' foram entregues em {destinationCountry}.'
- 'Além do anterio, {companyName} proporcionará a {socialName} - 'Além do anterior, {companyName} proporcionará a {socialName}
um resumo mensal onde se incluem todas as faturas (e as entregas correspondentes). um resumo mensal onde se incluem todas as faturas (e as entregas correspondentes).
{socialName} assinará e devolverá o resumo mensal à {companyName}, {socialName} assinará e devolverá o resumo mensal à {companyName},
dentro dos 5 dias posteriores à receção do resumo.' dentro dos 5 dias posteriores à receção do resumo.'
signer: signer:
representative: Representante representative: Representante
representativeRole: Cargo de representante representativeRole: Cargo de representante
signed: Data da assinatura signed: Data da assinatura
@ -39,4 +38,4 @@ months:
- 'Setembro' - 'Setembro'
- 'Outubro' - 'Outubro'
- 'Novembro' - 'Novembro'
- 'Dezembro' - 'Dezembro'

View File

@ -0,0 +1,9 @@
SELECT
a.nickname,
a.street,
a.postalCode,
a.city,
p.name province
FROM address a
LEFT JOIN province p ON p.id = a.provinceFk
WHERE a.id = ?

View File

@ -1,8 +1,8 @@
SELECT SELECT
s.name, s.name,
s.city, s.city,
cl.name AS manager cl.name AS manager
FROM company c FROM company c
JOIN supplier s ON s.id = c.id JOIN supplier s ON s.id = c.id
JOIN client cl ON cl.id = c.workerManagerFk JOIN client cl ON cl.id = c.workerManagerFk
WHERE c.id = ? WHERE c.id = ?