Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 3558-setQuantitySale

This commit is contained in:
Alex Moreno 2022-02-08 12:16:41 +01:00
commit d7a3821d05
16 changed files with 318 additions and 10 deletions

View File

@ -12,7 +12,7 @@
<vn-horizontal>
<vn-textfield
vn-one
label="Client Id"]
label="Client Id"
ng-model="filter.clientFk">
</vn-textfield>
<vn-textfield

View File

@ -18,7 +18,7 @@ module.exports = Self => {
}
],
returns: {
type: ['Object'],
type: ['object'],
root: true
},
http: {
@ -42,6 +42,7 @@ module.exports = Self => {
'stickers',
'packing',
'grouping',
'groupingMode',
'quantity',
'packageFk',
'weight',

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models;
describe('Buy latests buys filter()', () => {
describe('Entry latests buys filter()', () => {
it('should return the entry matching "search"', async() => {
const tx = await models.Buy.beginTransaction({});
const options = {transaction: tx};
@ -12,7 +12,7 @@ describe('Buy latests buys filter()', () => {
}
};
const results = await models.Buy.latestBuysFilter(ctx);
const results = await models.Buy.latestBuysFilter(ctx, options);
const firstBuy = results[0];
expect(results.length).toEqual(1);

View File

@ -111,17 +111,45 @@
</vn-input-number>
</td>
<td>
<vn-input-number class="dense"
<vn-input-number
title="{{::buy.packing | dashIfEmpty}}"
ng-model="buy.packing"
on-change="$ctrl.saveBuy(buy)">
<append>
<vn-icon
pointer
ng-show="buy.groupingMode == '2'"
ng-click="$ctrl.toggleGroupingMode(buy, 'packing')"
icon="lock">
</vn-icon>
<vn-icon
pointer
ng-show="buy.groupingMode != '2'"
ng-click="$ctrl.toggleGroupingMode(buy, 'packing')"
icon="lock_open">
</vn-icon>
</append>
</vn-input-number>
</td>
<td>
<vn-input-number class="dense"
<vn-input-number
title="{{::buy.grouping | dashIfEmpty}}"
ng-model="buy.grouping"
on-change="$ctrl.saveBuy(buy)">
<append>
<vn-icon
pointer
ng-show="buy.groupingMode == '1'"
ng-click="$ctrl.toggleGroupingMode(buy, 'grouping')"
icon="lock">
</vn-icon>
<vn-icon
pointer
ng-show="buy.groupingMode != '1'"
ng-click="$ctrl.toggleGroupingMode(buy, 'grouping')"
icon="lock_open">
</vn-icon>
</append>
</vn-input-number>
</td>
<td>
@ -213,7 +241,6 @@
vn-id="item-descriptor"
warehouse-fk="$ctrl.vnConfig.warehouseFk">
</vn-item-descriptor-popover>
<vn-confirm
vn-id="delete-buys"
question="You are going to delete buy(s) from this entry"

View File

@ -56,6 +56,23 @@ export default class Controller extends Section {
this.buys.splice(index, 1);
});
}
toggleGroupingMode(buy, mode) {
const grouping = 1;
const packing = 2;
const groupingMode = mode === 'grouping' ? grouping : packing;
const newGroupingMode = buy.groupingMode === groupingMode ? 0 : groupingMode;
const params = {
groupingMode: newGroupingMode
};
this.$http.patch(`Buys/${buy.id}`, params).then(() => {
buy.groupingMode = newGroupingMode;
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
ngModule.vnComponent('vnEntryBuyIndex', {

View File

@ -1,3 +1,4 @@
/* eslint max-len: ["error", { "code": 150 }]*/
import './index.js';
describe('Entry buy', () => {
@ -64,4 +65,50 @@ describe('Entry buy', () => {
expect(controller.buys.length).toEqual(1);
});
});
describe('toggleGroupingMode()', () => {
it(`should toggle grouping mode from grouping to packing`, () => {
const grouping = 1;
const packing = 2;
const buy = {id: 999, groupingMode: grouping};
const query = `Buys/${buy.id}`;
$httpBackend.expectPATCH(query, {groupingMode: packing}).respond(200);
controller.toggleGroupingMode(buy, 'packing');
$httpBackend.flush();
});
it(`should toggle grouping mode from packing to grouping`, () => {
const grouping = 1;
const packing = 2;
const buy = {id: 999, groupingMode: packing};
const query = `Buys/${buy.id}`;
$httpBackend.expectPATCH(query, {groupingMode: grouping}).respond(200);
controller.toggleGroupingMode(buy, 'grouping');
$httpBackend.flush();
});
it(`should toggle off the grouping mode if it was packing to packing`, () => {
const noGrouping = 0;
const packing = 2;
const buy = {id: 999, groupingMode: packing};
const query = `Buys/${buy.id}`;
$httpBackend.expectPATCH(query, {groupingMode: noGrouping}).respond(200);
controller.toggleGroupingMode(buy, 'packing');
$httpBackend.flush();
});
it(`should toggle off the grouping mode if it was grouping to grouping`, () => {
const noGrouping = 0;
const grouping = 1;
const buy = {id: 999, groupingMode: grouping};
const query = `Buys/${buy.id}`;
$httpBackend.expectPATCH(query, {groupingMode: noGrouping}).respond(200);
controller.toggleGroupingMode(buy, 'grouping');
$httpBackend.flush();
});
});
});

View File

@ -46,6 +46,24 @@ module.exports = Self => {
fields: ['withholding']
}
},
{
relation: 'invoiceInDueDay',
scope: {
fields: [
'id',
'invoiceInFk',
'dueDated',
'bankFk',
'amount',
'foreignValue'],
include: [{
relation: 'bank',
scope: {
fields: ['bank']
}
}]
}
},
{
relation: 'invoiceInTax',
scope: {

View File

@ -30,6 +30,13 @@
"created": {
"type": "date"
}
},
"relations": {
"bank": {
"type": "belongsTo",
"model": "Bank",
"foreignKey": "bankFk"
}
}
}

View File

@ -0,0 +1,68 @@
<vn-crud-model
vn-id="model"
url="InvoiceInDueDays"
data="InvoiceInDueDaysData"
link="{invoiceInFk: $ctrl.$params.id}"
auto-load="true">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="InvoiceInDueDaysData"
form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-card class="vn-pa-lg">
<vn-horizontal ng-repeat="invoiceInDueDay in InvoiceInDueDaysData">
<vn-date-picker
vn-one
label="Date"
ng-model="invoiceInDueDay.dueDated"
vn-focus
rule>
</vn-date-picker>
<vn-autocomplete vn-three
label="Bank"
ng-model="invoiceInDueDay.bankFk"
url="Banks"
show-field="bank"
rule>
<tpl-item>{{id}}: {{bank}}</tpl-item>
</vn-autocomplete>
<vn-input-number vn-one
label="Amount"
ng-model="invoiceInDueDay.amount"
step="0.01"
rule
vn-focus>
</vn-input-number>
<vn-input-number
disabled="$ctrl.invoiceIn.currency.code == 'EUR'"
label="Foreign value"
ng-model="invoiceInDueDay.foreignValue"
rule>
</vn-input-number>
<vn-none>
<vn-icon-button
vn-tooltip="Remove due day"
icon="delete"
ng-click="model.remove($index)"
tabindex="-1">
</vn-icon-button>
</vn-none>
</vn-horizontal>
<vn-one>
<vn-icon-button
vn-bind="+"
vn-tooltip="Add due day"
icon="add_circle"
ng-click="$ctrl.add()">
</vn-icon-button>
</vn-one>
</vn-card>
<vn-button-bar>
<vn-submit
disabled="!watcher.dataChanged()"
label="Save">
</vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,31 @@
import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
add() {
this.$.model.insert({
dueDated: new Date(),
bankFk: this.vnConfig.local.bankFk
});
}
onSubmit() {
this.$.watcher.check();
this.$.model.save().then(() => {
this.$.watcher.notifySaved();
this.$.watcher.updateOriginalData();
this.card.reload();
});
}
}
ngModule.vnComponent('vnInvoiceInDueDay', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnInvoiceInCard'
},
bindings: {
invoiceIn: '<'
}
});

View File

@ -0,0 +1,44 @@
import './index.js';
import watcher from 'core/mocks/watcher';
import crudModel from 'core/mocks/crud-model';
describe('InvoiceIn', () => {
describe('Component due day', () => {
let controller;
let $scope;
let vnApp;
beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, $rootScope, _vnApp_) => {
vnApp = _vnApp_;
jest.spyOn(vnApp, 'showError');
$scope = $rootScope.$new();
$scope.model = crudModel;
$scope.watcher = watcher;
const $element = angular.element('<vn-invoice-in-due-day></vn-invoice-in-due-day>');
controller = $componentController('vnInvoiceInDueDay', {$element, $scope});
controller.invoiceIn = {id: 1};
}));
describe('onSubmit()', () => {
it('should make HTTP POST request to save due day values', () => {
controller.card = {reload: () => {}};
jest.spyOn($scope.watcher, 'check');
jest.spyOn($scope.watcher, 'notifySaved');
jest.spyOn($scope.watcher, 'updateOriginalData');
jest.spyOn(controller.card, 'reload');
jest.spyOn($scope.model, 'save');
controller.onSubmit();
expect($scope.model.save).toHaveBeenCalledWith();
expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith();
expect($scope.watcher.check).toHaveBeenCalledWith();
expect($scope.watcher.notifySaved).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
});
});
});
});

View File

@ -9,5 +9,6 @@ import './descriptor-popover';
import './summary';
import './basic-data';
import './tax';
import './dueDay';
import './create';
import './log';

View File

@ -1,4 +1,5 @@
Add tax: Añadir iva
Add due day: Añadir vencimiento
Amounts do not match: La BI no coincide con el vencimiento ni con el total
Due day: Vencimiento
Entries list: Listado de entradas
@ -9,6 +10,7 @@ InvoiceIn deleted: Factura eliminada
Invoice list: Listado de facturas recibidas
InvoiceIn booked: Factura contabilizada
Remove tax: Quitar iva
Remove due day: Quitar vencimiento
Sage tax: Sage iva
Sage transaction: Sage transaccion
Search invoices in by reference: Buscar facturas recibidas por referencia

View File

@ -21,7 +21,11 @@
},
{
"state": "invoiceIn.card.tax",
"icon": "icon-lines"
"icon": "icon-tax"
},
{
"state": "invoiceIn.card.dueDay",
"icon": "icon-calendar"
},
{
"state": "invoiceIn.card.log",
@ -95,6 +99,16 @@
},
"acl": ["administrative"]
},
{
"url": "/dueDay",
"state": "invoiceIn.card.dueDay",
"component": "vn-invoice-in-due-day",
"description": "Due day",
"params": {
"invoice-in": "$ctrl.invoiceIn"
},
"acl": ["administrative"]
},
{
"url": "/log",
"state": "invoiceIn.card.log",

View File

@ -91,6 +91,35 @@
</vn-table>
</vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-one ng-if="$ctrl.summary.invoiceInDueDay.length != 0">
<h4>
<a
ui-sref="invoiceIn.card.dueDay({id:$ctrl.invoiceIn.id})"
target="_self">
<span translate vn-tooltip="Go to">Due day</span>
</a>
</h4>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th>Date</vn-th>
<vn-th>Bank</vn-th>
<vn-th>Amount</vn-th>
<vn-th>Foreign value</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="dueDay in $ctrl.summary.invoiceInDueDay">
<vn-td shrink-date>{{::dueDay.dueDated | date:'dd/MM/yyyy'}}</vn-td>
<vn-td>{{::dueDay.bank.bank}}</vn-td>
<vn-td>{{::dueDay.amount | currency: 'EUR':2}}</vn-td>
<vn-td shrink>{{::dueDay.foreignValue}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-one>
</vn-horizontal>
</vn-card>
<vn-supplier-descriptor-popover
vn-id="supplierDescriptor">

View File

@ -9,3 +9,5 @@ Doc number: Numero documento
Sage withholding: Retención sage
Undeductible VAT: Iva no deducible
Do not match: No coinciden
VAT: IVA
Due day: Vencimiento