Call calculate_taxes_and_totals after mapping
This commit is contained in:
parent
4bb87373dc
commit
b054eb7a4f
@ -12,6 +12,7 @@ from frappe import _, msgprint, throw
|
||||
|
||||
from erpnext.accounts.party import get_party_account, get_due_date
|
||||
from erpnext.controllers.stock_controller import update_gl_entries_after
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
|
||||
|
||||
@ -781,10 +782,9 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_delivery_note(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("onload_post_render")
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(source_doc, target_doc, source_parent):
|
||||
target_doc.base_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \
|
||||
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cstr, flt
|
||||
from frappe import msgprint, _, throw
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
|
||||
class PurchaseOrder(BuyingController):
|
||||
@ -180,10 +181,9 @@ class PurchaseOrder(BuyingController):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_receipt(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.qty = flt(obj.qty) - flt(obj.received_qty)
|
||||
@ -218,10 +218,9 @@ def make_purchase_receipt(source_name, target_doc=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_invoice(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.amount = flt(obj.amount) - flt(obj.billed_amt)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
class SupplierQuotation(BuyingController):
|
||||
@ -52,11 +53,10 @@ class SupplierQuotation(BuyingController):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_order(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("get_schedule_dates")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.conversion_factor = 1
|
||||
|
@ -11,10 +11,6 @@ from erpnext.accounts.party import get_party_details
|
||||
from erpnext.controllers.stock_controller import StockController
|
||||
|
||||
class BuyingController(StockController):
|
||||
def onload_post_render(self):
|
||||
# contact, address, item details
|
||||
self.set_missing_values()
|
||||
|
||||
def validate(self):
|
||||
super(BuyingController, self).validate()
|
||||
if getattr(self, "supplier", None) and not self.supplier_name:
|
||||
|
@ -10,10 +10,6 @@ from frappe import _, throw
|
||||
from erpnext.controllers.stock_controller import StockController
|
||||
|
||||
class SellingController(StockController):
|
||||
def onload_post_render(self):
|
||||
# contact, address, item details and pos details (if applicable)
|
||||
self.set_missing_values()
|
||||
|
||||
def validate(self):
|
||||
super(SellingController, self).validate()
|
||||
self.validate_max_discount()
|
||||
|
@ -39,20 +39,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
|
||||
onload_post_render: function() {
|
||||
var me = this;
|
||||
if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) {
|
||||
if(!this.frm.doc.customer || !this.frm.doc.supplier) {
|
||||
return this.frm.call({
|
||||
doc: this.frm.doc,
|
||||
method: "onload_post_render",
|
||||
freeze: true,
|
||||
callback: function(r) {
|
||||
// remove this call when using client side mapper
|
||||
me.set_dynamic_labels();
|
||||
me.calculate_taxes_and_totals();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.calculate_taxes_and_totals();
|
||||
}
|
||||
this.calculate_taxes_and_totals();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -6,7 +6,7 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import cstr, validate_email_add, cint, comma_and
|
||||
from frappe import session
|
||||
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
from erpnext.controllers.selling_controller import SellingController
|
||||
|
||||
@ -76,8 +76,6 @@ def make_customer(source_name, target_doc=None):
|
||||
return _make_customer(source_name, target_doc)
|
||||
|
||||
def _make_customer(source_name, target_doc=None, ignore_permissions=False):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
if source.company_name:
|
||||
target.customer_type = "Company"
|
||||
@ -103,8 +101,6 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_opportunity(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
doclist = get_mapped_doc("Lead", source_name,
|
||||
{"Lead": {
|
||||
"doctype": "Opportunity",
|
||||
|
@ -3,11 +3,9 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.utils import cstr, cint
|
||||
|
||||
from frappe import msgprint, _
|
||||
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
from erpnext.utilities.transaction_base import TransactionBase
|
||||
|
||||
@ -129,11 +127,9 @@ class Opportunity(TransactionBase):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_quotation(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def set_missing_values(source, target):
|
||||
quotation = frappe.get_doc(target)
|
||||
quotation.run_method("onload_post_render")
|
||||
quotation.run_method("set_missing_values")
|
||||
quotation.run_method("calculate_taxes_and_totals")
|
||||
|
||||
doclist = get_mapped_doc("Opportunity", source_name, {
|
||||
|
@ -4,7 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cstr
|
||||
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe import _
|
||||
|
||||
from erpnext.controllers.selling_controller import SellingController
|
||||
@ -96,8 +96,6 @@ def make_sales_order(source_name, target_doc=None):
|
||||
return _make_sales_order(source_name, target_doc)
|
||||
|
||||
def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
customer = _make_customer(source_name, ignore_permissions)
|
||||
|
||||
def set_missing_values(source, target):
|
||||
@ -105,9 +103,9 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
|
||||
target.customer = customer.name
|
||||
target.customer_name = customer.customer_name
|
||||
|
||||
si = frappe.get_doc(target)
|
||||
si.ignore_permissions = ignore_permissions
|
||||
si.run_method("onload_post_render")
|
||||
target.ignore_permissions = ignore_permissions
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
doclist = get_mapped_doc("Quotation", source_name, {
|
||||
"Quotation": {
|
||||
|
@ -247,7 +247,8 @@ class SalesOrder(SellingController):
|
||||
return "order" if self.docstatus==1 else None
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.run_method("onload_post_render")
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_material_request(source_name, target_doc=None):
|
||||
@ -316,7 +317,8 @@ def make_delivery_note(source_name, target_doc=None):
|
||||
def make_sales_invoice(source_name, target_doc=None):
|
||||
def set_missing_values(source, target):
|
||||
target.is_pos = 0
|
||||
target.run_method("onload_post_render")
|
||||
target.run_method("set_missing_values")
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(source, target, source_parent):
|
||||
target.amount = flt(source.amount) - flt(source.billed_amt)
|
||||
|
@ -275,13 +275,14 @@ def make_sales_invoice(source_name, target_doc=None):
|
||||
invoiced_qty_map = get_invoiced_qty_map(source_name)
|
||||
|
||||
def update_accounts(source, target):
|
||||
si = frappe.get_doc(target)
|
||||
si.is_pos = 0
|
||||
si.run_method("onload_post_render")
|
||||
target.is_pos = 0
|
||||
target.run_method("set_missing_values")
|
||||
|
||||
if len(si.get("entries")) == 0:
|
||||
if len(target.get("entries")) == 0:
|
||||
frappe.throw(_("All these items have already been invoiced"))
|
||||
|
||||
target.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(source_doc, target_doc, source_parent):
|
||||
target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0)
|
||||
|
||||
|
@ -9,6 +9,7 @@ import frappe
|
||||
|
||||
from frappe.utils import cstr, flt
|
||||
from frappe import _
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
class MaterialRequest(BuyingController):
|
||||
@ -208,8 +209,8 @@ def _update_requested_qty(doc, mr_obj, mr_items):
|
||||
})
|
||||
|
||||
def set_missing_values(source, target_doc):
|
||||
po = frappe.get_doc(target_doc)
|
||||
po.run_method("set_missing_values")
|
||||
target_doc.run_method("set_missing_values")
|
||||
target_doc.run_method("calculate_taxes_and_totals")
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.conversion_factor = 1
|
||||
@ -217,8 +218,6 @@ def update_item(obj, target, source_parent):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_order(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
doclist = get_mapped_doc("Material Request", source_name, {
|
||||
"Material Request": {
|
||||
"doctype": "Purchase Order",
|
||||
@ -244,23 +243,19 @@ def make_purchase_order(source_name, target_doc=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_order_based_on_supplier(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
if target_doc:
|
||||
if isinstance(target_doc, basestring):
|
||||
import json
|
||||
target_doc = frappe.get_doc(json.loads(target_doc))
|
||||
target_doc = target_doc.get({"parentfield": ["!=", "po_details"]})
|
||||
target_doc.set("po_details", [])
|
||||
|
||||
material_requests, supplier_items = get_material_requests_based_on_supplier(source_name)
|
||||
|
||||
def postprocess(source, target_doc):
|
||||
target_doc[0].supplier = source_name
|
||||
target_doc.supplier = source_name
|
||||
set_missing_values(source, target_doc)
|
||||
|
||||
po_items = target_doc.get({"parentfield": "po_details"})
|
||||
target_doc = target_doc.get({"parentfield": ["!=", "po_details"]}) + \
|
||||
[d for d in po_items
|
||||
if d.get("item_code") in supplier_items and d.get("qty") > 0]
|
||||
target_doc.set("po_details", [d for d in target_doc.get("po_details")
|
||||
if d.get("item_code") in supplier_items and d.get("qty" > 0)])
|
||||
|
||||
return target_doc
|
||||
|
||||
@ -282,7 +277,7 @@ def make_purchase_order_based_on_supplier(source_name, target_doc=None):
|
||||
}
|
||||
}, target_doc, postprocess)
|
||||
|
||||
return target_doc.as_dict()
|
||||
return target_doc
|
||||
|
||||
def get_material_requests_based_on_supplier(supplier):
|
||||
supplier_items = [d[0] for d in frappe.db.get_values("Item",
|
||||
@ -300,8 +295,6 @@ def get_material_requests_based_on_supplier(supplier):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_supplier_quotation(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
doclist = get_mapped_doc("Material Request", source_name, {
|
||||
"Material Request": {
|
||||
"doctype": "Supplier Quotation",
|
||||
@ -324,8 +317,6 @@ def make_supplier_quotation(source_name, target_doc=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_stock_entry(source_name, target_doc=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.conversion_factor = 1
|
||||
target.qty = flt(obj.qty) - flt(obj.ordered_qty)
|
||||
@ -333,8 +324,7 @@ def make_stock_entry(source_name, target_doc=None):
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.purpose = "Material Transfer"
|
||||
se = frappe.get_doc(target)
|
||||
se.run_method("get_stock_and_rate")
|
||||
target.run_method("get_stock_and_rate")
|
||||
|
||||
doclist = get_mapped_doc("Material Request", source_name, {
|
||||
"Material Request": {
|
||||
|
@ -294,6 +294,7 @@ def make_purchase_invoice(source_name, target_doc=None):
|
||||
def set_missing_values(source, target):
|
||||
doc = frappe.get_doc(target)
|
||||
doc.run_method("set_missing_values")
|
||||
doc.run_method("calculate_taxes_and_totals")
|
||||
|
||||
doclist = get_mapped_doc("Purchase Receipt", source_name, {
|
||||
"Purchase Receipt": {
|
||||
|
Loading…
Reference in New Issue
Block a user