Allow select a lost and found location in inventory

#035150
This commit is contained in:
Raimon Esteve 2019-01-15 12:10:57 +01:00
parent 1b587d1a9e
commit ed7692f585
5 changed files with 74 additions and 47 deletions

View file

@ -22,6 +22,7 @@ import { Routing } from '../../../pages/routing/routing';
export class InventoriesPage extends InfiniteList{
inventory: Inventory;
location: Location;
lost_found: Location;
title: string;
local_storage = this.locker.useDriver(Locker.DRIVERS.LOCAL)
loading: any;
@ -61,7 +62,7 @@ export class InventoriesPage extends InfiniteList{
date: item.date,
state: item.state,
location: this.location,
lost_found: 7, // TODO: hardcode lost found ID location
lost_found: this.lost_found,
id: item.id
}
this.navCtrl.push(new Routing().getNext(this.constructor.name), {params:

View file

@ -73,8 +73,7 @@ export class InventoryListPage {
this.blur_element = true;
this.setDefaultFields();
if (this.new_inventory.constructor.name != 'Object' &&
this.new_inventory == false) {
if (this.new_inventory.constructor.name != 'Object' && this.new_inventory == false) {
this.showLoading();
this.not_checking = false;
this.saved = true;
@ -88,9 +87,9 @@ export class InventoryListPage {
this.inventory = {
date: this.format_date(current_date),
location: navParams.get('params').location,
lost_found: navParams.get('params').lost_found || 7,
state: "draft",
id: -1,
lost_found: 7, // TODO: hardcode lost found ID location
lines: []
}
this.save();
@ -482,8 +481,8 @@ export class InventoryListPage {
let values = {
company: this.inventory.company,
location: this.inventory.location.id,
date: this.inventory.date,
lost_found: this.inventory.lost_found
lost_found: this.inventory.lost_found.id,
date: this.inventory.date
}
json_constructor.addNode(method, [id, values])
let json = json_constructor.createJSON()

View file

@ -37,7 +37,7 @@
</ion-buttons>
<ion-buttons right>
<button [disabled]="!elementInput" ion-button icon-right (click)="goForward()">
{{'Done' | translate}}
{{'Save' | translate}}
</button>
<ion-icon name="ion-ios-arrow-forward"></ion-icon>
</ion-buttons>

View file

@ -21,6 +21,7 @@ import { Routing } from '../../../pages/routing/routing';
*/
export class LocationInventoryPage extends InfiniteList implements AfterViewInit{
itemInput: string = '';
lostInput: string = '';
location_code: string = '';
@ViewChild('focusInput') myInput;
item: string;
@ -33,37 +34,40 @@ export class LocationInventoryPage extends InfiniteList implements AfterViewInit
super(navCtrl, trytond_provider, events)
this.method = "stock.location";
this.domain = [new EncodeJSONRead().createDomain("type", "=", "storage")];
this.fields = ["name", "code"]
this.fields = ["name", "code"];
this.loadData();
this.blur_element = true;
this.elementInput = false;
}
ngAfterViewInit() {
console.log("set input")
// console.log("set input");
//document.getElementById('test').focus()
Keyboard.close()
}
blurInput(event){
if (this.blur_element){
document.getElementById('test').focus()
//Keyboard.close()
}
this.blur_element = false;
}
ionViewDidEnter() {
this.blur_element = true;
Keyboard.close()
}
setFocus(event) {
console.log("Focus set")
}
/**
* Clears the input
*/
public clearInput(): void{
blurInput(event){
if (this.blur_element){
document.getElementById('test').focus()
//Keyboard.close()
}
this.blur_element = false;
}
ionViewDidEnter() {
this.blur_element = true;
Keyboard.close()
}
setFocus(event) {
console.log("Focus set");
}
/**
* Clears the input
*/
public clearInput(): void{
this.itemInput = '';
this.location_code = '';
}
@ -75,7 +79,6 @@ export class LocationInventoryPage extends InfiniteList implements AfterViewInit
* @returns Go to the next page
*/
itemSelected(event, item) {
console.log("Item selected", item, "Going to next page", this.navParams.get('param'))
this.navCtrl.push(new Routing().getNext(this.constructor.name), { params: {
location: item,
new_inventory: true}} )
@ -85,29 +88,45 @@ export class LocationInventoryPage extends InfiniteList implements AfterViewInit
* Go to the next stage, check if the entered location is valid
*/
goForward() {
console.log("Searching for code", this.itemInput);
// console.log("Searching for code", this.itemInput, this.lostInput);
let json_constructor = new EncodeJSONRead();
let search_domain = [json_constructor.createDomain("rec_name", "=", this.itemInput)]
let fields = ['name', 'code']
let method = "stock.location"
json_constructor.addNode(method, search_domain, fields)
let json = json_constructor.createJson()
let search_domain = [json_constructor.createDomain("name", "in", [this.itemInput, this.lostInput])];
let fields = ['name', 'code', 'type'];
let method = "stock.location";
json_constructor.addNode(method, search_domain, fields);
let json = json_constructor.createJson();
this.trytond_provider.search(json).subscribe(
data => {
if (data[method].length > 0) {
this.location = data[method];
// Clear input field
this.itemInput = '';
this.location_code = '';
this.navCtrl.push(new Routing().getNext(this.constructor.name), { params: {
location: this.location[0],
new_inventory: true}} )
}
else{
let storage = undefined;
let lost_found = undefined;
if (data[method].length === 2) {
for (let location of data[method]) {
if (location['type'] == 'storage') {
storage = location;
}
if (location['type'] == 'lost_found') {
lost_found = location;
}
}
if ((lost_found != undefined) && (storage != undefined)) {
this.itemInput = '';
this.lostInput = '';
this.location_code = '';
this.navCtrl.push(new Routing().getNext(this.constructor.name), { params: {
location: storage,
lost_found: lost_found,
new_inventory: true}} )
} else {
alert("Incorrect Location");
this.itemInput = '';
this.lostInput = '';
this.location_code = '';
}
} else{
alert("Incorrect Location");
this.itemInput = '';
this.lostInput = '';
this.location_code = '';
}
},

View file

@ -29,12 +29,20 @@ export class InventoryTypePage extends MenuPage {
{
name: "Products Inventory",
page: new Routing().getNext(this.constructor.name),
params: {location:params.location, new_inventory: true, products_inventory: true}
params: {
location: params.location,
lost_found: params.lost_found,
new_inventory: true,
products_inventory: true}
},
{
name: "Complete Inventory",
page: new Routing().getNext(this.constructor.name),
params: {location:params.location, new_inventory:true, products_inventory: false}
params: {
location: params.location,
lost_found: params.lost_found,
new_inventory: true,
products_inventory: false}
}
]
}