chore: Move buying controller to utils

This commit is contained in:
Deepesh Garg 2023-07-23 18:50:44 +05:30
parent 7205fb9b97
commit 8ccb8e3c5b
10 changed files with 418 additions and 428 deletions

View File

@ -2,11 +2,11 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.accounts");
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.accounts.payment_triggers.setup("Purchase Invoice");
erpnext.accounts.taxes.setup_tax_filters("Purchase Taxes and Charges");
erpnext.accounts.taxes.setup_tax_validations("Purchase Invoice");
erpnext.buying.setup_buying_controller();
erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.BuyingController {
setup(doc) {
@ -550,8 +550,8 @@ frappe.ui.form.on("Purchase Invoice", {
},
mode_of_payment: function(frm) {
get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account){
frm.set_value('cash_bank_account', account);
erpnext.accounts.pos.get_payment_mode_account(frm, frm.doc.mode_of_payment, function(account) {
frm.set_value("cash_bank_account", account);
})
},

View File

@ -1,3 +1,23 @@
{% include "erpnext/regional/italy/sales_invoice.js" %}
erpnext.setup_e_invoice_button('Sales Invoice')
frappe.ui.form.on("Sales Invoice", {
refresh: (frm) => {
if(frm.doc.docstatus == 1) {
frm.add_custom_button('Generate E-Invoice', () => {
frm.call({
method: "erpnext.regional.italy.utils.generate_single_invoice",
args: {
docname: frm.doc.name
},
callback: function(r) {
frm.reload_doc();
if(r.message) {
open_url_post(frappe.request.url, {
cmd: 'frappe.core.doctype.file.file.download_file',
file_url: r.message
});
}
}
});
});
}
}
});

View File

@ -3,11 +3,10 @@
frappe.provide("erpnext.buying");
frappe.provide("erpnext.accounts.dimensions");
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.accounts.taxes.setup_tax_filters("Purchase Taxes and Charges");
erpnext.accounts.taxes.setup_tax_validations("Purchase Order");
erpnext.buying.setup_buying_controller();
frappe.ui.form.on("Purchase Order", {
setup: function(frm) {

View File

@ -1,11 +1,10 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
{% include 'erpnext/public/js/controllers/buying.js' %};
cur_frm.add_fetch('contact', 'email_id', 'email_id')
erpnext.buying.setup_buying_controller();
frappe.ui.form.on("Request for Quotation",{
setup: function(frm) {
frm.custom_make_buttons = {
@ -436,7 +435,7 @@ erpnext.buying.RequestforQuotationController = class RequestforQuotationControll
//Remove blanks
for (var j = 0; j < frm.doc.suppliers.length; j++) {
if(!frm.doc.suppliers[j].hasOwnProperty("supplier")) {
if(!Object.prototype.hasOwnProperty.call(frm.doc.suppliers[j], "supplier")) {
frm.get_field("suppliers").grid.grid_rows[j].remove();
}
}
@ -445,10 +444,11 @@ erpnext.buying.RequestforQuotationController = class RequestforQuotationControll
if(r.message) {
for (var i = 0; i < r.message.length; i++) {
var exists = false;
let supplier = "";
if (r.message[i].constructor === Array){
var supplier = r.message[i][0];
supplier = r.message[i][0];
} else {
var supplier = r.message[i].name;
supplier = r.message[i].name;
}
for (var j = 0; j < doc.suppliers.length;j++) {

View File

@ -1,9 +1,7 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
// attach required files
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.buying.setup_buying_controller();
erpnext.buying.SupplierQuotationController = class SupplierQuotationController extends erpnext.buying.BuyingController {
setup() {
this.frm.custom_make_buttons = {

View File

@ -3,12 +3,11 @@
frappe.provide("erpnext.buying");
cur_frm.cscript.tax_table = "Purchase Taxes and Charges";
{% include 'erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.js' %}
cur_frm.email_field = "contact_email";
// cur_frm.email_field = "contact_email";
// cur_frm.add_fetch('project', 'cost_center', 'cost_center');
erpnext.buying = {
setup_buying_controller: function() {
erpnext.buying.BuyingController = class BuyingController extends erpnext.TransactionController {
setup() {
super.setup();
@ -47,7 +46,6 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac
return erpnext.queries.company_address_query(me.frm.doc)
});
}
/* eslint-enable */
}
setup_queries(doc, cdt, cdn) {
@ -416,8 +414,8 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac
});
}
};
cur_frm.add_fetch('project', 'cost_center', 'cost_center');
}
}
erpnext.buying.link_to_mrs = function(frm) {
frappe.call({

View File

@ -26,6 +26,7 @@ import "./templates/crm_activities.html";
import "./templates/crm_notes.html";
import "./controllers/accounts.js"
import "./utils/landed_taxes_and_charges_common.js";
import "./utils/sales_common.js"
import "./utils/sales_common.js";
import "./controllers/buying.js";
// import { sum } from 'frappe/public/utils/util.js'

View File

@ -1,25 +0,0 @@
erpnext.setup_e_invoice_button = (doctype) => {
frappe.ui.form.on(doctype, {
refresh: (frm) => {
if(frm.doc.docstatus == 1) {
frm.add_custom_button('Generate E-Invoice', () => {
frm.call({
method: "erpnext.regional.italy.utils.generate_single_invoice",
args: {
docname: frm.doc.name
},
callback: function(r) {
frm.reload_doc();
if(r.message) {
open_url_post(frappe.request.url, {
cmd: 'frappe.core.doctype.file.file.download_file',
file_url: r.message
});
}
}
});
});
}
}
});
};

View File

@ -3,7 +3,7 @@
// eslint-disable-next-line
frappe.provide("erpnext.accounts.dimensions");
{% include 'erpnext/public/js/controllers/buying.js' %};
erpnext.buying.setup_buying_controller();
frappe.ui.form.on('Material Request', {
setup: function(frm) {
@ -472,13 +472,13 @@ erpnext.buying.MaterialRequestController = class MaterialRequestController exten
set_schedule_date(this.frm);
}
onload(doc, cdt, cdn) {
this.frm.set_query("item_code", "items", function() {
onload() {
this.frm.set_query("item_code", "items", function(doc, cdt, cdn) {
if (doc.material_request_type == "Customer Provided") {
return{
query: "erpnext.controllers.queries.item_query",
filters:{
'customer': me.frm.doc.customer,
'customer': doc.customer,
'is_stock_item':1
}
}

View File

@ -1,12 +1,11 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
{% include 'erpnext/public/js/controllers/buying.js' %};
frappe.provide("erpnext.stock");
erpnext.accounts.taxes.setup_tax_filters("Purchase Taxes and Charges");
erpnext.accounts.taxes.setup_tax_validations("Purchase Receipt");
erpnext.buying.setup_buying_controller();
frappe.ui.form.on("Purchase Receipt", {
setup: (frm) => {