fix: Reverse provisional entries on Purchase Invoice cancel
This commit is contained in:
parent
c7efa3b44d
commit
61fa4eb6c9
@ -532,7 +532,10 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
||||||
if not gl_entries:
|
if not gl_entries:
|
||||||
gl_entries = self.get_gl_entries()
|
if self.docstatus == 1:
|
||||||
|
gl_entries = self.get_gl_entries()
|
||||||
|
else:
|
||||||
|
gl_entries = self.get_gl_entries(cancel=1)
|
||||||
|
|
||||||
if gl_entries:
|
if gl_entries:
|
||||||
update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
|
update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
|
||||||
@ -545,7 +548,10 @@ class PurchaseInvoice(BuyingController):
|
|||||||
from_repost=from_repost,
|
from_repost=from_repost,
|
||||||
)
|
)
|
||||||
elif self.docstatus == 2:
|
elif self.docstatus == 2:
|
||||||
|
provisional_entries = [a for a in gl_entries if a.voucher_type == "Purchase Receipt"]
|
||||||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||||
|
if provisional_entries:
|
||||||
|
make_gl_entries(provisional_entries)
|
||||||
|
|
||||||
if update_outstanding == "No":
|
if update_outstanding == "No":
|
||||||
update_outstanding_amt(
|
update_outstanding_amt(
|
||||||
@ -559,7 +565,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
|
elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock:
|
||||||
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
|
||||||
|
|
||||||
def get_gl_entries(self, warehouse_account=None):
|
def get_gl_entries(self, warehouse_account=None, cancel=0):
|
||||||
self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company)
|
self.auto_accounting_for_stock = erpnext.is_perpetual_inventory_enabled(self.company)
|
||||||
if self.auto_accounting_for_stock:
|
if self.auto_accounting_for_stock:
|
||||||
self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
|
self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed")
|
||||||
@ -572,7 +578,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
gl_entries = []
|
gl_entries = []
|
||||||
|
|
||||||
self.make_supplier_gl_entry(gl_entries)
|
self.make_supplier_gl_entry(gl_entries)
|
||||||
self.make_item_gl_entries(gl_entries)
|
self.make_item_gl_entries(gl_entries, cancel=cancel)
|
||||||
self.make_discount_gl_entries(gl_entries)
|
self.make_discount_gl_entries(gl_entries)
|
||||||
|
|
||||||
if self.check_asset_cwip_enabled():
|
if self.check_asset_cwip_enabled():
|
||||||
@ -639,7 +645,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_item_gl_entries(self, gl_entries):
|
def make_item_gl_entries(self, gl_entries, cancel=0):
|
||||||
# item gl entries
|
# item gl entries
|
||||||
stock_items = self.get_stock_items()
|
stock_items = self.get_stock_items()
|
||||||
if self.update_stock and self.auto_accounting_for_stock:
|
if self.update_stock and self.auto_accounting_for_stock:
|
||||||
@ -836,7 +842,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
if expense_booked_in_pr:
|
if expense_booked_in_pr:
|
||||||
# Intentionally passing purchase invoice item to handle partial billing
|
# Intentionally passing purchase invoice item to handle partial billing
|
||||||
purchase_receipt_doc.add_provisional_gl_entry(
|
purchase_receipt_doc.add_provisional_gl_entry(
|
||||||
item, gl_entries, self.posting_date, provisional_account, reverse=1
|
item, gl_entries, self.posting_date, provisional_account, reverse=not cancel
|
||||||
)
|
)
|
||||||
|
|
||||||
if not self.is_internal_transfer():
|
if not self.is_internal_transfer():
|
||||||
|
Loading…
Reference in New Issue
Block a user