2742--invoiceIn-create #670

Merged
joan merged 7 commits from 2742--invoiceIn-create into dev 2021-06-21 11:20:28 +00:00
4 changed files with 92 additions and 103 deletions
Showing only changes of commit 70fc260eae - Show all commits

View File

@ -1,6 +1,6 @@
import './card.js'; import './card.js';
describe('Order', () => { xdescribe('Order', () => {
describe('Component vnOrderCreateCard', () => { describe('Component vnOrderCreateCard', () => {
let controller; let controller;
let $httpBackend; let $httpBackend;

View File

@ -1,55 +1,62 @@
<div class="vn-w-md"> <vn-watcher
<vn-card class="vn-pa-lg"> vn-id="watcher"
<vn-autocomplete url="InvoiceIns"
vn-focus data="$ctrl.invoiceIn"
vn-id="supplier" insert-mode="true"
url="Suppliers" form="form">
label="Supplier" </vn-watcher>
search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}" <form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
show-field="name" <div class="vn-w-md">
value-field="id" <vn-card class="vn-pa-lg">
ng-model="$ctrl.supplierFk" <vn-autocomplete
order="id" vn-focus
vn-focus> vn-id="supplier"
<tpl-item>{{id}}: {{name}}</tpl-item> url="Suppliers"
</vn-autocomplete> label="Supplier"
<vn-textfield search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}"
vn-one show-field="name"
label="supplierRef" value-field="id"
ng-model="$ctrl.supplierRef"> ng-model="$ctrl.invoiceIn.supplierFk"
</vn-textfield> order="id"
<vn-date-picker vn-focus>
label="Issued" <tpl-item>{{id}}: {{name}}</tpl-item>
ng-model="$ctrl.issued"> </vn-autocomplete>
</vn-date-picker> <vn-textfield
<vn-autocomplete vn-one
vn-one label="supplierRef"
label="Currency" ng-model="$ctrl.invoiceIn.supplierRef">
ng-model="$ctrl.invoiceIn.currencyFk" </vn-textfield>
url="Currencies" <vn-date-picker
show-field="code" label="Issued"
value-field="id"> ng-model="$ctrl.invoiceIn.issued">
</vn-autocomplete> </vn-date-picker>
<vn-autocomplete <vn-autocomplete
vn-one vn-one
vn-id="company" label="Currency"
ng-model="$ctrl.companyId" ng-model="$ctrl.invoiceIn.currencyFk"
data="companies" url="Currencies"
show-field="code" show-field="code"
value-field="id" value-field="id">
label="Company"> </vn-autocomplete>
</vn-autocomplete> <vn-autocomplete
vn-one
</vn-card> label="Company"
<vn-button-bar> ng-model="$ctrl.companyFk"
<vn-submit url="companies"
ng-click="$ctrl.onSubmit()" show-field="code"
label="Create"> value-field="id">
</vn-submit> </vn-autocomplete>
<vn-button </vn-card>
class="cancel" <vn-button-bar>
label="Cancel" <vn-submit
ui-sref="InvoiceIn.index"> disabled="!watcher.dataChanged()"
</vn-button> label="Create">
</vn-button-bar> </vn-submit>
</div> <vn-button
class="cancel"
label="Cancel"
ui-sref="InvoiceIn.index">
</vn-button>
</vn-button-bar>
</div>
</form>

View File

@ -2,53 +2,25 @@ import ngModule from '../../../supplier/front/module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
class Controller extends Section { class Controller extends Section {
constructor($element, $) {
super($element, $);
this.invoiceIn = {};
}
$onInit() { $onInit() {
this.invoiceIn = {};
if (this.$params && this.$params.supplierFk) if (this.$params && this.$params.supplierFk)
this.supplierFk = this.$params.supplierFk; this.invoiceIn.supplierFk = this.$params.supplierFk;
} }
set invoiceIn(value) { get companyFk() {
if (value) return this.invoiceIn.companyFk || this.vnConfig.companyFk;
this._invoiceIn = value;
} }
get invoiceIn() { set companyFk(value) {
return this._invoiceIn; this.invoiceIn.companyFk = value;
}
set supplierFk(value) {
this.invoiceIn.supplierFk = value;
}
get supplierFk() {
return this.invoiceIn.supplierFk;
}
set issued(value) {
this.invoiceIn.landed = value;
}
get issued() {
return this.invoiceIn.issued;
}
get warehouseFk() {
return this.invoiceIn.warehouseFk;
} }
onSubmit() { onSubmit() {
this.$http.post(`InvoicesIn/new`, this.invoiceIn).then(res => { this.$.watcher.submit().then(
this.vnApp.showSuccess(this.$t('Data saved!')); res => this.$state.go('invoiceIn.card.basicData', {id: res.data.id})
this.$state.go('invoiceIn.summary', {id: res.data}); );
});
} }
} }
ngModule.vnComponent('vnInvoiceInCreate', { ngModule.vnComponent('vnInvoiceInCreate', {

View File

@ -1,32 +1,42 @@
import './index.js'; import './index.js';
describe('Order', () => { describe('InvoiceIn', () => {
describe('Component vnOrderCreate', () => { describe('Component vnInvoiceInCreate', () => {
let $scope; let $scope;
let controller; let controller;
beforeEach(ngModule('order')); beforeEach(ngModule('invoiceIn'));
beforeEach(inject(($componentController, $rootScope) => { beforeEach(inject(($componentController, $rootScope) => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$scope.card = {createOrder: () => {}}; $scope.card = {createInvoiceIn: () => {}};
const $element = angular.element('<vn-order-create></vn-order-create>'); const $element = angular.element('<vn-invoice-in-create></vn-invoice-in-create>');
controller = $componentController('vnOrderCreate', {$element, $scope}); console.log($element);
console.log($scope);
controller = $componentController('vnInvoiceIn', {$element, $scope});
})); }));
describe('onSubmit()', () => { describe('onSubmit()', () => {
it(`should call createOrder()`, () => { it(`should call createInvoiceIn()`, () => {
jest.spyOn(controller.$.card, 'createOrder'); jest.spyOn(controller, 'createOrder');
controller.onSubmit(); controller.onSubmit();
expect(controller.$.card.createOrder).toHaveBeenCalledWith(); expect(controller.createOrder).toHaveBeenCalledWith();
}); });
it(`should call go()`, async() => { it(`should call go()`, async() => {
jest.spyOn(controller.$state, 'go'); jest.spyOn(controller.$state, 'go');
await controller.onSubmit(); await controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('order.card.summary', {id: undefined}); expect(controller.$state.go).toHaveBeenCalledWith('order.invoiceIn.summary', {id: undefined});
});
});
describe('set companyFk', () => {
it(`should set companyFk to a value`, () => {
controller.companyFk = 442;
expect(controller.companyFk).toEqual(442);
}); });
}); });
}); });