Call calculate_taxes_and_totals after mapping

This commit is contained in:
Anand Doshi
2014-04-22 20:35:22 +05:30
parent 4bb87373dc
commit b054eb7a4f
14 changed files with 119 additions and 157 deletions

View File

@@ -12,6 +12,7 @@ from frappe import _, msgprint, throw
from erpnext.accounts.party import get_party_account, get_due_date from erpnext.accounts.party import get_party_account, get_due_date
from erpnext.controllers.stock_controller import update_gl_entries_after 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} 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() @frappe.whitelist()
def make_delivery_note(source_name, target_doc=None): def make_delivery_note(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def set_missing_values(source, target): 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): def update_item(source_doc, target_doc, source_parent):
target_doc.base_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ target_doc.base_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \

View File

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, flt from frappe.utils import cstr, flt
from frappe import msgprint, _, throw from frappe import msgprint, _, throw
from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
class PurchaseOrder(BuyingController): class PurchaseOrder(BuyingController):
@@ -180,10 +181,9 @@ class PurchaseOrder(BuyingController):
@frappe.whitelist() @frappe.whitelist()
def make_purchase_receipt(source_name, target_doc=None): def make_purchase_receipt(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def set_missing_values(source, target): def set_missing_values(source, target):
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.qty = flt(obj.qty) - flt(obj.received_qty) target.qty = flt(obj.qty) - flt(obj.received_qty)
@@ -218,10 +218,9 @@ def make_purchase_receipt(source_name, target_doc=None):
@frappe.whitelist() @frappe.whitelist()
def make_purchase_invoice(source_name, target_doc=None): def make_purchase_invoice(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def set_missing_values(source, target): def set_missing_values(source, target):
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.amount = flt(obj.amount) - flt(obj.billed_amt) target.amount = flt(obj.amount) - flt(obj.billed_amt)

View File

@@ -3,6 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
class SupplierQuotation(BuyingController): class SupplierQuotation(BuyingController):
@@ -52,11 +53,10 @@ class SupplierQuotation(BuyingController):
@frappe.whitelist() @frappe.whitelist()
def make_purchase_order(source_name, target_doc=None): def make_purchase_order(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def set_missing_values(source, target): def set_missing_values(source, target):
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("get_schedule_dates") target.run_method("get_schedule_dates")
target.run_method("calculate_taxes_and_totals")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.conversion_factor = 1 target.conversion_factor = 1

View File

@@ -11,10 +11,6 @@ from erpnext.accounts.party import get_party_details
from erpnext.controllers.stock_controller import StockController from erpnext.controllers.stock_controller import StockController
class BuyingController(StockController): class BuyingController(StockController):
def onload_post_render(self):
# contact, address, item details
self.set_missing_values()
def validate(self): def validate(self):
super(BuyingController, self).validate() super(BuyingController, self).validate()
if getattr(self, "supplier", None) and not self.supplier_name: if getattr(self, "supplier", None) and not self.supplier_name:

View File

@@ -10,10 +10,6 @@ from frappe import _, throw
from erpnext.controllers.stock_controller import StockController from erpnext.controllers.stock_controller import StockController
class SellingController(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): def validate(self):
super(SellingController, self).validate() super(SellingController, self).validate()
self.validate_max_discount() self.validate_max_discount()

View File

@@ -39,21 +39,8 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
onload_post_render: function() { onload_post_render: function() {
var me = this; var me = this;
if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) { 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();
} }
}
}, },
refresh: function() { refresh: function() {

View File

@@ -6,7 +6,7 @@ import frappe
from frappe import _ from frappe import _
from frappe.utils import cstr, validate_email_add, cint, comma_and from frappe.utils import cstr, validate_email_add, cint, comma_and
from frappe import session from frappe import session
from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.selling_controller import SellingController 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) return _make_customer(source_name, target_doc)
def _make_customer(source_name, target_doc=None, ignore_permissions=False): 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): def set_missing_values(source, target):
if source.company_name: if source.company_name:
target.customer_type = "Company" target.customer_type = "Company"
@@ -103,8 +101,6 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False):
@frappe.whitelist() @frappe.whitelist()
def make_opportunity(source_name, target_doc=None): def make_opportunity(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
doclist = get_mapped_doc("Lead", source_name, doclist = get_mapped_doc("Lead", source_name,
{"Lead": { {"Lead": {
"doctype": "Opportunity", "doctype": "Opportunity",

View File

@@ -3,11 +3,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr, cint from frappe.utils import cstr, cint
from frappe import msgprint, _ from frappe import msgprint, _
from frappe.model.mapper import get_mapped_doc
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
@@ -129,11 +127,9 @@ class Opportunity(TransactionBase):
@frappe.whitelist() @frappe.whitelist()
def make_quotation(source_name, target_doc=None): def make_quotation(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def set_missing_values(source, target): def set_missing_values(source, target):
quotation = frappe.get_doc(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") quotation.run_method("calculate_taxes_and_totals")
doclist = get_mapped_doc("Opportunity", source_name, { doclist = get_mapped_doc("Opportunity", source_name, {

View File

@@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.utils import cstr from frappe.utils import cstr
from frappe.model.mapper import get_mapped_doc
from frappe import _ from frappe import _
from erpnext.controllers.selling_controller import SellingController 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) return _make_sales_order(source_name, target_doc)
def _make_sales_order(source_name, target_doc=None, ignore_permissions=False): 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) customer = _make_customer(source_name, ignore_permissions)
def set_missing_values(source, target): 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 = customer.name
target.customer_name = customer.customer_name target.customer_name = customer.customer_name
si = frappe.get_doc(target) target.ignore_permissions = ignore_permissions
si.ignore_permissions = ignore_permissions target.run_method("set_missing_values")
si.run_method("onload_post_render") target.run_method("calculate_taxes_and_totals")
doclist = get_mapped_doc("Quotation", source_name, { doclist = get_mapped_doc("Quotation", source_name, {
"Quotation": { "Quotation": {

View File

@@ -247,7 +247,8 @@ class SalesOrder(SellingController):
return "order" if self.docstatus==1 else None return "order" if self.docstatus==1 else None
def set_missing_values(source, target): 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() @frappe.whitelist()
def make_material_request(source_name, target_doc=None): 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 make_sales_invoice(source_name, target_doc=None):
def set_missing_values(source, target): def set_missing_values(source, target):
target.is_pos = 0 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): def update_item(source, target, source_parent):
target.amount = flt(source.amount) - flt(source.billed_amt) target.amount = flt(source.amount) - flt(source.billed_amt)

View File

@@ -275,13 +275,14 @@ def make_sales_invoice(source_name, target_doc=None):
invoiced_qty_map = get_invoiced_qty_map(source_name) invoiced_qty_map = get_invoiced_qty_map(source_name)
def update_accounts(source, target): def update_accounts(source, target):
si = frappe.get_doc(target) target.is_pos = 0
si.is_pos = 0 target.run_method("set_missing_values")
si.run_method("onload_post_render")
if len(si.get("entries")) == 0: if len(target.get("entries")) == 0:
frappe.throw(_("All these items have already been invoiced")) 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): def update_item(source_doc, target_doc, source_parent):
target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0) target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0)

View File

@@ -9,6 +9,7 @@ import frappe
from frappe.utils import cstr, flt from frappe.utils import cstr, flt
from frappe import _ from frappe import _
from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
class MaterialRequest(BuyingController): class MaterialRequest(BuyingController):
@@ -208,8 +209,8 @@ def _update_requested_qty(doc, mr_obj, mr_items):
}) })
def set_missing_values(source, target_doc): def set_missing_values(source, target_doc):
po = frappe.get_doc(target_doc) target_doc.run_method("set_missing_values")
po.run_method("set_missing_values") target_doc.run_method("calculate_taxes_and_totals")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.conversion_factor = 1 target.conversion_factor = 1
@@ -217,8 +218,6 @@ def update_item(obj, target, source_parent):
@frappe.whitelist() @frappe.whitelist()
def make_purchase_order(source_name, target_doc=None): 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, { doclist = get_mapped_doc("Material Request", source_name, {
"Material Request": { "Material Request": {
"doctype": "Purchase Order", "doctype": "Purchase Order",
@@ -244,23 +243,19 @@ def make_purchase_order(source_name, target_doc=None):
@frappe.whitelist() @frappe.whitelist()
def make_purchase_order_based_on_supplier(source_name, target_doc=None): def make_purchase_order_based_on_supplier(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
if target_doc: if target_doc:
if isinstance(target_doc, basestring): if isinstance(target_doc, basestring):
import json import json
target_doc = frappe.get_doc(json.loads(target_doc)) 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) material_requests, supplier_items = get_material_requests_based_on_supplier(source_name)
def postprocess(source, target_doc): def postprocess(source, target_doc):
target_doc[0].supplier = source_name target_doc.supplier = source_name
set_missing_values(source, target_doc) set_missing_values(source, target_doc)
target_doc.set("po_details", [d for d in target_doc.get("po_details")
po_items = target_doc.get({"parentfield": "po_details"}) if d.get("item_code") in supplier_items and d.get("qty" > 0)])
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]
return target_doc return target_doc
@@ -282,7 +277,7 @@ def make_purchase_order_based_on_supplier(source_name, target_doc=None):
} }
}, target_doc, postprocess) }, target_doc, postprocess)
return target_doc.as_dict() return target_doc
def get_material_requests_based_on_supplier(supplier): def get_material_requests_based_on_supplier(supplier):
supplier_items = [d[0] for d in frappe.db.get_values("Item", 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() @frappe.whitelist()
def make_supplier_quotation(source_name, target_doc=None): 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, { doclist = get_mapped_doc("Material Request", source_name, {
"Material Request": { "Material Request": {
"doctype": "Supplier Quotation", "doctype": "Supplier Quotation",
@@ -324,8 +317,6 @@ def make_supplier_quotation(source_name, target_doc=None):
@frappe.whitelist() @frappe.whitelist()
def make_stock_entry(source_name, target_doc=None): def make_stock_entry(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.conversion_factor = 1 target.conversion_factor = 1
target.qty = flt(obj.qty) - flt(obj.ordered_qty) 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): def set_missing_values(source, target):
target.purpose = "Material Transfer" target.purpose = "Material Transfer"
se = frappe.get_doc(target) target.run_method("get_stock_and_rate")
se.run_method("get_stock_and_rate")
doclist = get_mapped_doc("Material Request", source_name, { doclist = get_mapped_doc("Material Request", source_name, {
"Material Request": { "Material Request": {

View File

@@ -294,6 +294,7 @@ def make_purchase_invoice(source_name, target_doc=None):
def set_missing_values(source, target): def set_missing_values(source, target):
doc = frappe.get_doc(target) doc = frappe.get_doc(target)
doc.run_method("set_missing_values") doc.run_method("set_missing_values")
doc.run_method("calculate_taxes_and_totals")
doclist = get_mapped_doc("Purchase Receipt", source_name, { doclist = get_mapped_doc("Purchase Receipt", source_name, {
"Purchase Receipt": { "Purchase Receipt": {