Merge branch 'develop' of https://github.com/frappe/erpnext into rebrand-ui
This commit is contained in:
@@ -105,10 +105,18 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
frappe.ui.form.on(this.frm.doctype + " Item", {
|
||||
items_add: function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
if(!item.warehouse && frm.doc.set_warehouse) {
|
||||
if (!item.warehouse && frm.doc.set_warehouse) {
|
||||
item.warehouse = frm.doc.set_warehouse;
|
||||
}
|
||||
|
||||
if (!item.target_warehouse && frm.doc.set_target_warehouse) {
|
||||
item.target_warehouse = frm.doc.set_target_warehouse;
|
||||
}
|
||||
|
||||
if (!item.from_warehouse && frm.doc.set_from_warehouse) {
|
||||
item.from_warehouse = frm.doc.set_from_warehouse;
|
||||
}
|
||||
|
||||
erpnext.accounts.dimensions.copy_dimension_from_first_row(frm, cdt, cdn, 'items');
|
||||
}
|
||||
});
|
||||
@@ -227,6 +235,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
};
|
||||
|
||||
this.frm.trigger('set_default_internal_warehouse');
|
||||
|
||||
return frappe.run_serially([
|
||||
() => set_value('currency', currency),
|
||||
() => set_value('price_list_currency', currency),
|
||||
@@ -590,11 +600,21 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
return frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
|
||||
.then((r) => {
|
||||
if (r.message &&
|
||||
(r.message.has_batch_no || r.message.has_serial_no)) {
|
||||
(r.message.has_batch_no || r.message.has_serial_no)) {
|
||||
frappe.flags.hide_serial_batch_dialog = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
() => {
|
||||
// check if batch serial selector is disabled or not
|
||||
if (show_batch_dialog && !frappe.flags.hide_serial_batch_dialog)
|
||||
return frappe.db.get_single_value('Stock Settings', 'disable_serial_no_and_batch_selector')
|
||||
.then((value) => {
|
||||
if (value) {
|
||||
frappe.flags.hide_serial_batch_dialog = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
() => {
|
||||
if(show_batch_dialog && !frappe.flags.hide_serial_batch_dialog) {
|
||||
var d = locals[cdt][cdn];
|
||||
@@ -649,7 +669,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
args: item_args
|
||||
},
|
||||
callback: function(r) {
|
||||
frappe.model.set_value(item.doctype, item.name, 'rate', r.message);
|
||||
frappe.model.set_value(item.doctype, item.name, 'rate', r.message * item.conversion_factor);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -715,6 +735,31 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
this.calculate_taxes_and_totals(false);
|
||||
},
|
||||
|
||||
update_stock: function() {
|
||||
this.frm.trigger('set_default_internal_warehouse');
|
||||
},
|
||||
|
||||
set_default_internal_warehouse: function() {
|
||||
let me = this;
|
||||
if ((this.frm.doc.doctype === 'Sales Invoice' && me.frm.doc.update_stock)
|
||||
|| this.frm.doc.doctype == 'Delivery Note') {
|
||||
if (this.frm.doc.is_internal_customer && this.frm.doc.company === this.frm.doc.represents_company) {
|
||||
frappe.db.get_value('Company', this.frm.doc.company, 'default_in_transit_warehouse', function(value) {
|
||||
me.frm.set_value('set_target_warehouse', value.default_in_transit_warehouse);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if ((this.frm.doc.doctype === 'Purchase Invoice' && me.frm.doc.update_stock)
|
||||
|| this.frm.doc.doctype == 'Purchase Receipt') {
|
||||
if (this.frm.doc.is_internal_supplier && this.frm.doc.company === this.frm.doc.represents_company) {
|
||||
frappe.db.get_value('Company', this.frm.doc.company, 'default_in_transit_warehouse', function(value) {
|
||||
me.frm.set_value('set_from_warehouse', value.default_in_transit_warehouse);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
company: function() {
|
||||
var me = this;
|
||||
var set_pricing = function() {
|
||||
@@ -801,7 +846,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
in_list(['Purchase Order', 'Purchase Receipt', 'Purchase Invoice'], this.frm.doctype)) {
|
||||
erpnext.utils.get_shipping_address(this.frm, function(){
|
||||
set_party_account(set_pricing);
|
||||
})
|
||||
});
|
||||
|
||||
// Get default company billing address in Purchase Invoice, Order and Receipt
|
||||
frappe.call({
|
||||
@@ -1100,6 +1145,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
|
||||
batch_no: function(doc, cdt, cdn) {
|
||||
let item = frappe.get_doc(cdt, cdn);
|
||||
this.apply_price_list(item, true);
|
||||
},
|
||||
|
||||
toggle_conversion_factor: function(item) {
|
||||
// toggle read only property for conversion factor field if the uom and stock uom are same
|
||||
if(this.frm.get_field('items').grid.fields_map.conversion_factor) {
|
||||
@@ -1404,6 +1454,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
"pricing_rules": d.pricing_rules,
|
||||
"warehouse": d.warehouse,
|
||||
"serial_no": d.serial_no,
|
||||
"batch_no": d.batch_no,
|
||||
"price_list_rate": d.price_list_rate,
|
||||
"conversion_factor": d.conversion_factor || 1.0
|
||||
});
|
||||
@@ -1962,6 +2013,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
this.autofill_warehouse(this.frm.doc.items, "warehouse", this.frm.doc.set_warehouse);
|
||||
},
|
||||
|
||||
set_target_warehouse: function() {
|
||||
this.autofill_warehouse(this.frm.doc.items, "target_warehouse", this.frm.doc.set_target_warehouse);
|
||||
},
|
||||
|
||||
set_from_warehouse: function() {
|
||||
this.autofill_warehouse(this.frm.doc.items, "from_warehouse", this.frm.doc.set_from_warehouse);
|
||||
},
|
||||
|
||||
autofill_warehouse : function (child_table, warehouse_field, warehouse) {
|
||||
if (warehouse && child_table && child_table.length) {
|
||||
let doctype = child_table[0].doctype;
|
||||
@@ -2026,3 +2085,35 @@ erpnext.show_serial_batch_selector = function (frm, d, callback, on_close, show_
|
||||
}, show_dialog);
|
||||
});
|
||||
}
|
||||
|
||||
erpnext.apply_putaway_rule = (frm, purpose=null) => {
|
||||
if (!frm.doc.company) {
|
||||
frappe.throw({message: __("Please select a Company first."), title: __("Mandatory")});
|
||||
}
|
||||
if (!frm.doc.items.length) return;
|
||||
|
||||
frappe.call({
|
||||
method: "erpnext.stock.doctype.putaway_rule.putaway_rule.apply_putaway_rule",
|
||||
args: {
|
||||
doctype: frm.doctype,
|
||||
items: frm.doc.items,
|
||||
company: frm.doc.company,
|
||||
sync: true,
|
||||
purpose: purpose
|
||||
},
|
||||
callback: (result) => {
|
||||
if (!result.exc && result.message) {
|
||||
frm.clear_table("items");
|
||||
|
||||
let items = result.message;
|
||||
items.forEach((row) => {
|
||||
delete row["name"]; // dont overwrite name from server side
|
||||
let child = frm.add_child("items");
|
||||
Object.assign(child, row);
|
||||
frm.script_manager.trigger("qty", child.doctype, child.name);
|
||||
});
|
||||
frm.get_field("items").grid.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user