diff --git a/modules/supplier/front/agency-term/create/index.html b/modules/supplier/front/agency-term/create/index.html
new file mode 100644
index 000000000..5d0dca4ef
--- /dev/null
+++ b/modules/supplier/front/agency-term/create/index.html
@@ -0,0 +1,75 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/supplier/front/agency-term/create/index.js b/modules/supplier/front/agency-term/create/index.js
new file mode 100644
index 000000000..f876f9003
--- /dev/null
+++ b/modules/supplier/front/agency-term/create/index.js
@@ -0,0 +1,34 @@
+import ngModule from '../../module';
+import Section from 'salix/components/section';
+
+export default class Controller extends Section {
+ constructor($element, $) {
+ super($element, $);
+
+ this.filter = {
+ fields: [
+ 'name'
+ ],
+ include: [{
+ relation: 'supplierAgencyTerm',
+ where: {
+ supplierFk: 1
+ }
+ }],
+ };
+ }
+
+ onSubmit() {
+ this.$.watcher.submit().then(res => {
+ this.$state.go('supplier.card.address.index');
+ });
+ }
+}
+
+ngModule.vnComponent('vnSupplierAgencyTermCreate', {
+ template: require('./index.html'),
+ controller: Controller,
+ bindings: {
+ supplier: '<'
+ }
+});
diff --git a/modules/supplier/front/agency-term/create/index.spec.js b/modules/supplier/front/agency-term/create/index.spec.js
new file mode 100644
index 000000000..026de3769
--- /dev/null
+++ b/modules/supplier/front/agency-term/create/index.spec.js
@@ -0,0 +1,102 @@
+import './index';
+import watcher from 'core/mocks/watcher';
+
+describe('Supplier', () => {
+ describe('Component vnSupplierAddressCreate', () => {
+ let $scope;
+ let controller;
+ let $element;
+ let $state;
+
+ beforeEach(ngModule('supplier'));
+
+ beforeEach(inject(($componentController, $rootScope, _$state_) => {
+ $scope = $rootScope.$new();
+ $state = _$state_;
+ $state.params.id = '1234';
+ $element = angular.element('');
+ controller = $componentController('vnSupplierAddressCreate', {$element, $scope});
+ controller.$.watcher = watcher;
+ controller.$.watcher.submit = () => {
+ return {
+ then: callback => {
+ callback({data: {id: 124}});
+ }
+ };
+ };
+ controller.supplier = {id: 1};
+ }));
+
+ describe('onSubmit()', () => {
+ it('should perform a PATCH and then redirect to the main section', () => {
+ jest.spyOn(controller.$state, 'go');
+ controller.onSubmit();
+
+ expect(controller.$state.go).toHaveBeenCalledWith('supplier.card.address.index');
+ });
+ });
+
+ describe('town() setter', () => {
+ it(`should set provinceFk property`, () => {
+ controller.town = {
+ provinceFk: 1,
+ code: 46001,
+ province: {
+ id: 1,
+ name: 'New york',
+ country: {
+ id: 2,
+ name: 'USA'
+ }
+ },
+ postcodes: []
+ };
+
+ expect(controller.address.provinceFk).toEqual(1);
+ });
+
+ it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
+ controller.town = {
+ provinceFk: 1,
+ code: 46001,
+ province: {
+ id: 1,
+ name: 'New york',
+ country: {
+ id: 2,
+ name: 'USA'
+ }
+ },
+ postcodes: [{code: '46001'}]
+ };
+
+ expect(controller.address.provinceFk).toEqual(1);
+ expect(controller.address.postalCode).toEqual('46001');
+ });
+ });
+
+ describe('postcode() setter', () => {
+ it(`should set the town and province properties`, () => {
+ controller.postcode = {
+ townFk: 1,
+ code: 46001,
+ town: {
+ id: 1,
+ name: 'New York',
+ province: {
+ id: 1,
+ name: 'New york',
+ country: {
+ id: 2,
+ name: 'USA'
+ }
+ }
+ }
+ };
+
+ expect(controller.address.city).toEqual('New York');
+ expect(controller.address.provinceFk).toEqual(1);
+ });
+ });
+ });
+});
diff --git a/modules/supplier/front/agency-term/index.html b/modules/supplier/front/agency-term/index/index.html
similarity index 92%
rename from modules/supplier/front/agency-term/index.html
rename to modules/supplier/front/agency-term/index/index.html
index d58c55528..b472aaf91 100644
--- a/modules/supplier/front/agency-term/index.html
+++ b/modules/supplier/front/agency-term/index/index.html
@@ -15,7 +15,7 @@
-
\ No newline at end of file
+
+
+
diff --git a/modules/supplier/front/agency-term/index.js b/modules/supplier/front/agency-term/index/index.js
similarity index 83%
rename from modules/supplier/front/agency-term/index.js
rename to modules/supplier/front/agency-term/index/index.js
index bfdf58d50..416440ef5 100644
--- a/modules/supplier/front/agency-term/index.js
+++ b/modules/supplier/front/agency-term/index/index.js
@@ -1,4 +1,4 @@
-import ngModule from '../module';
+import ngModule from '../../module';
import Section from 'salix/components/section';
class Controller extends Section {
@@ -15,7 +15,7 @@ class Controller extends Section {
}
}
-ngModule.vnComponent('vnSupplierAgencyTerm', {
+ngModule.vnComponent('vnSupplierAgencyTermIndex', {
template: require('./index.html'),
controller: Controller,
bindings: {
diff --git a/modules/supplier/front/index.js b/modules/supplier/front/index.js
index e52db0675..ba2768854 100644
--- a/modules/supplier/front/index.js
+++ b/modules/supplier/front/index.js
@@ -18,4 +18,5 @@ import './billing-data';
import './address/index';
import './address/create';
import './address/edit';
-import './agency-term';
+import './agency-term/index';
+import './agency-term/create';
diff --git a/modules/supplier/front/routes.json b/modules/supplier/front/routes.json
index 16376e37c..39445e5a1 100644
--- a/modules/supplier/front/routes.json
+++ b/modules/supplier/front/routes.json
@@ -15,7 +15,7 @@
{"state": "supplier.card.address.index", "icon": "icon-delivery"},
{"state": "supplier.card.account", "icon": "icon-account"},
{"state": "supplier.card.contact", "icon": "contact_phone"},
- {"state": "supplier.card.agencyTerm", "icon": "contact_support"},
+ {"state": "supplier.card.agencyTerm.index", "icon": "contact_support"},
{"state": "supplier.card.log", "icon": "history"},
{"state": "supplier.card.consumption", "icon": "show_chart"}
]
@@ -90,9 +90,26 @@
{
"url": "/agency-term",
"state": "supplier.card.agencyTerm",
- "component": "vn-supplier-agency-term",
+ "component": "ui-view",
+ "abstract": true
+ },
+ {
+ "url": "/index?q",
+ "state": "supplier.card.agencyTerm.index",
+ "component": "vn-supplier-agency-term-index",
"description": "Autonomous",
- "acl": ["administrative"]
+ "params": {
+ "supplier": "$ctrl.supplier"
+ }
+ },
+ {
+ "url": "/create",
+ "state": "supplier.card.agencyTerm.create",
+ "component": "vn-supplier-agency-term-create",
+ "description": "New autonomous",
+ "params": {
+ "supplier": "$ctrl.supplier"
+ }
},
{
"url": "/consumption?q",
diff --git a/modules/zone/back/models/agency.json b/modules/zone/back/models/agency.json
index edec36f87..699b60e79 100644
--- a/modules/zone/back/models/agency.json
+++ b/modules/zone/back/models/agency.json
@@ -16,5 +16,12 @@
"type": "string",
"required": false
}
+ },
+ "relations": {
+ "supplierAgencyTerm": {
+ "type": "belongsTo",
+ "model": "SupplierAgencyTerm",
+ "foreignKey": "agencyFk"
+ }
}
}