Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (c) 2016, Rootstack and contributors
- // For license information, please see license.txt
- (function() {
- var reasons = [];
- var edited_item_qtys = [];
- frappe.ui.form.on("reinventario", "refresh", function(frm) {
- toggleButtonVisivility(frm);
- getProductList(frm);
- frm.set_value('author', frm.doc.owner);
- reasons = frm.fields_dict.reason_list.df.options.split( "\n" );
- });
- frappe.ui.form.on("reinventario", "before_submit", function(frm) {
- frm.set_value("reinventario_status", "Aprobado");
- })
- frappe.ui.form.on("reinventario", "before_save", function(frm) {
- console.log(frm);
- validate = false;
- })
- frappe.ui.form.on("reinventario", "after_save", function(frm) {
- frm.assign_to.add();
- frm.assign_to.dialog.hide();
- frm.assign_to.dialog.set_values({assign_to:frm.doc.quien_aprueba});
- frm.assign_to.dialog.primary_action();
- })
- frappe.ui.form.on("reinventario", "reinventario_status", function(frm) {
- toggleButtonVisivility(frm);
- });
- frappe.ui.form.on("reinventario", "warehouse", function(frm) {
- getProductList(frm);
- });
- frappe.ui.form.on("reinventario", "revert_button", function(frm) {
- clearTable();
- });
- function toggleButtonVisivility(frm) {
- if(frm.doc.reinventario_status == "Aprobado") {
- $(frm.fields_dict['revert_button'].wrapper).hide();
- } else {
- $(frm.fields_dict['revert_button'].wrapper).show();
- }
- }
- function clearTable() {
- $('.productos-body').html('');
- }
- function getProductList(frm) {
- frm.call({
- method: 'erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.get_items',
- args: {
- warehouse:frm.doc.warehouse || "",
- posting_date: getDate(),
- posting_time: "23:59:59"
- },
- callback: function(r) {
- console.log(r)
- edited_item_qtys = [];
- $('.productos-body').html('');
- $.each(r.message, function(index) {
- var item = r.message[index];
- item.parsed_id = item.item_code.replace(' ', '_').toLowerCase();
- //appendTableRow(frm, item);
- var resource = getDetails(frm, r.message[index]);
- resource.success(function(a) {
- console.log('a',a)
- item = $.extend(item, a.message);
- appendTableRow(frm, item);
- });
- });
- }
- })
- }
- function getDate() {
- var today = new Date();
- var dd = today.getDate();
- var mm = today.getMonth()+1; //January is 0!
- var yyyy = today.getFullYear();
- if(dd<10) {
- dd='0'+dd
- }
- if(mm<10) {
- mm='0'+mm
- }
- return mm+'-'+dd+'-'+yyyy;
- }
- function getDetails(frm, item) {
- if(item.item_code) {
- return frm.call({
- method: "erpnext.stock.get_item_details.get_available_qty",
- args: {
- item_code: item.item_code,
- warehouse: item.warehouse
- }
- });
- }
- }
- function addTmpRecord(frm, item) {
- var tmp_obj = {
- id : item.parsed_id,
- reinventario_id : frm.doc.name,
- wharehouse : item.warehouse,
- item_code : item.item_code,
- prev_qty : item.actual_qty || 0,
- next_qty : item.qty || 0,
- reason : item.reason | ""
- };
- edited_item_qtys.push(tmp_obj);
- return tmp_obj;
- }
- function createReasonSelect(item) {
- var reason_select = $("<select class=\"form-control reason-select\" " +
- "id=\""+item.parsed_id+"_reason\" />");
- for(var r_index in reasons) {
- $("<option />", {value: reasons[r_index], text: reasons[r_index]}).appendTo(reason_select);
- }
- reason_select.appendTo("#tempselect");
- return $("#tempselect").html();
- }
- function createNumberFieldQty(item) {
- return '<input ' +
- 'id="'+item.parsed_id+'_qty" ' +
- 'type="number"' +
- 'min="0"' +
- 'class="form-control"' +
- 'value="' + item.actual_qty + '" ' +
- '></input>';
- }
- function appendTableRow(frm, item) {
- console.log(item);
- $('.productos-body').append(
- '<tr><td>' + item.item_code + '</td>' +
- '<td class="producto-cantidad-actual">' + item.actual_qty + '</td>' +
- '<td> ' + createNumberFieldQty(item) + '</td>' +
- '<td> ' + createReasonSelect(item) + '</td></tr>'
- );
- $("#tempselect").html('');
- var tmp_item = addTmpRecord(frm, item);
- $("input#" + item.parsed_id+ "_qty" ).on("change", function() {
- var el = $(this);
- if(el.val() > 0) {
- tmp_item.qty = parseInt(el.val(), 10);
- console.log(el.val(), tmp_item, edited_item_qtys);
- }
- });
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement