Update last purchase rate from the purchase invoice (#12189)

This commit is contained in:
rohitwaghchaure 2017-12-28 16:11:27 +05:30 committed by Nabin Hait
parent 31d7433946
commit fe22686a8f
4 changed files with 27 additions and 14 deletions

View File

@ -277,6 +277,8 @@ class PurchaseInvoice(BuyingController):
.format(item.purchase_receipt))
def on_submit(self):
super(PurchaseInvoice, self).on_submit()
self.check_prev_docstatus()
self.update_status_updater_args()
@ -606,6 +608,8 @@ class PurchaseInvoice(BuyingController):
))
def on_cancel(self):
super(PurchaseInvoice, self).on_cancel()
self.check_for_closed_status()
self.update_status_updater_args()

View File

@ -11,8 +11,7 @@ from erpnext.controllers.buying_controller import BuyingController
from erpnext.stock.doctype.item.item import get_last_purchase_details
from erpnext.stock.stock_balance import update_bin_qty, get_ordered_qty
from frappe.desk.notifications import clear_doctype_notifications
from erpnext.buying.utils import (validate_for_items, check_for_closed_status,
update_last_purchase_rate)
from erpnext.buying.utils import validate_for_items, check_for_closed_status
form_grid_templates = {
@ -189,6 +188,8 @@ class PurchaseOrder(BuyingController):
clear_doctype_notifications(self)
def on_submit(self):
super(PurchaseOrder, self).on_submit()
if self.is_against_so():
self.update_status_updater()
@ -199,9 +200,9 @@ class PurchaseOrder(BuyingController):
frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype,
self.company, self.base_grand_total)
update_last_purchase_rate(self, is_submit = 1)
def on_cancel(self):
super(PurchaseOrder, self).on_cancel()
if self.is_against_so():
self.update_status_updater()
@ -218,8 +219,6 @@ class PurchaseOrder(BuyingController):
self.update_requested_qty()
self.update_ordered_qty()
update_last_purchase_rate(self, is_submit = 0)
def on_update(self):
pass

View File

@ -8,7 +8,7 @@ from frappe.utils import flt,cint, cstr, getdate
from erpnext.accounts.party import get_party_details
from erpnext.stock.get_item_details import get_conversion_factor
from erpnext.buying.utils import validate_for_items
from erpnext.buying.utils import validate_for_items, update_last_purchase_rate
from erpnext.stock.stock_ledger import get_valuation_rate
from erpnext.controllers.stock_controller import StockController
@ -409,6 +409,18 @@ class BuyingController(StockController):
"actual_qty": -1*flt(d.consumed_qty),
}))
def on_submit(self):
if self.get('is_return'):
return
update_last_purchase_rate(self, is_submit = 1)
def on_cancel(self):
if self.get('is_return'):
return
update_last_purchase_rate(self, is_submit = 0)
def validate_schedule_date(self):
if not self.schedule_date:
self.schedule_date = min([d.schedule_date for d in self.get("items")])

View File

@ -12,7 +12,7 @@ from frappe.utils import getdate
from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.utils import get_account_currency
from frappe.desk.notifications import clear_doctype_notifications
from erpnext.buying.utils import check_for_closed_status, update_last_purchase_rate
from erpnext.buying.utils import check_for_closed_status
form_grid_templates = {
"items": "templates/form_grid/item_grid.html"
@ -111,6 +111,8 @@ class PurchaseReceipt(BuyingController):
# on submit
def on_submit(self):
super(PurchaseReceipt, self).on_submit()
# Check for Approving Authority
frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype,
self.company, self.base_grand_total)
@ -119,9 +121,6 @@ class PurchaseReceipt(BuyingController):
if self.per_billed < 100:
self.update_billing_status()
if not self.is_return:
update_last_purchase_rate(self, 1)
# Updating stock ledger should always be called after updating prevdoc status,
# because updating ordered qty in bin depends upon updated ordered qty in PO
self.update_stock_ledger()
@ -140,6 +139,8 @@ class PurchaseReceipt(BuyingController):
frappe.throw(_("Purchase Invoice {0} is already submitted").format(self.submit_rv[0][0]))
def on_cancel(self):
super(PurchaseReceipt, self).on_cancel()
self.check_for_closed_status()
# Check if Purchase Invoice has been submitted against current Purchase Order
submitted = frappe.db.sql("""select t1.name
@ -152,9 +153,6 @@ class PurchaseReceipt(BuyingController):
self.update_prevdoc_status()
self.update_billing_status()
if not self.is_return:
update_last_purchase_rate(self, 0)
# Updating stock ledger should always be called after updating prevdoc status,
# because updating ordered qty in bin depends upon updated ordered qty in PO
self.update_stock_ledger()