Merge pull request #26735 from rohitwaghchaure/fixed-cogs-in-purchase-receipt
fix: COGS account in purchase receipt
This commit is contained in:
commit
41da6f0d13
@ -15,6 +15,7 @@ from erpnext.healthcare.doctype.lab_test_template.lab_test_template import make_
|
|||||||
class TestPricingRule(unittest.TestCase):
|
class TestPricingRule(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
delete_existing_pricing_rules()
|
delete_existing_pricing_rules()
|
||||||
|
setup_pricing_rule_data()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
delete_existing_pricing_rules()
|
delete_existing_pricing_rules()
|
||||||
@ -554,6 +555,8 @@ class TestPricingRule(unittest.TestCase):
|
|||||||
for doc in [si, si1]:
|
for doc in [si, si1]:
|
||||||
doc.delete()
|
doc.delete()
|
||||||
|
|
||||||
|
test_dependencies = ["Campaign"]
|
||||||
|
|
||||||
def make_pricing_rule(**args):
|
def make_pricing_rule(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|
||||||
@ -600,6 +603,13 @@ def make_pricing_rule(**args):
|
|||||||
if args.get(applicable_for):
|
if args.get(applicable_for):
|
||||||
doc.db_set(applicable_for, args.get(applicable_for))
|
doc.db_set(applicable_for, args.get(applicable_for))
|
||||||
|
|
||||||
|
def setup_pricing_rule_data():
|
||||||
|
if not frappe.db.exists('Campaign', '_Test Campaign'):
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Campaign',
|
||||||
|
'campaign_name': '_Test Campaign',
|
||||||
|
'name': '_Test Campaign'
|
||||||
|
}).insert()
|
||||||
|
|
||||||
def delete_existing_pricing_rules():
|
def delete_existing_pricing_rules():
|
||||||
for doctype in ["Pricing Rule", "Pricing Rule Item Code",
|
for doctype in ["Pricing Rule", "Pricing Rule Item Code",
|
||||||
|
@ -566,10 +566,10 @@ def remove_ref_doc_link_from_pe(ref_type, ref_no):
|
|||||||
frappe.msgprint(_("Payment Entries {0} are un-linked").format("\n".join(linked_pe)))
|
frappe.msgprint(_("Payment Entries {0} are un-linked").format("\n".join(linked_pe)))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_company_default(company, fieldname):
|
def get_company_default(company, fieldname, ignore_validation=False):
|
||||||
value = frappe.get_cached_value('Company', company, fieldname)
|
value = frappe.get_cached_value('Company', company, fieldname)
|
||||||
|
|
||||||
if not value:
|
if not ignore_validation and not value:
|
||||||
throw(_("Please set default {0} in Company {1}")
|
throw(_("Please set default {0} in Company {1}")
|
||||||
.format(frappe.get_meta("Company").get_label(fieldname), company))
|
.format(frappe.get_meta("Company").get_label(fieldname), company))
|
||||||
|
|
||||||
|
@ -904,9 +904,9 @@ class AccountsController(TransactionBase):
|
|||||||
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
|
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
|
||||||
.format(item.item_code, item.idx, max_allowed_amt))
|
.format(item.item_code, item.idx, max_allowed_amt))
|
||||||
|
|
||||||
def get_company_default(self, fieldname):
|
def get_company_default(self, fieldname, ignore_validation=False):
|
||||||
from erpnext.accounts.utils import get_company_default
|
from erpnext.accounts.utils import get_company_default
|
||||||
return get_company_default(self.company, fieldname)
|
return get_company_default(self.company, fieldname, ignore_validation=ignore_validation)
|
||||||
|
|
||||||
def get_stock_items(self):
|
def get_stock_items(self):
|
||||||
stock_items = []
|
stock_items = []
|
||||||
|
@ -352,7 +352,7 @@ class PurchaseReceipt(BuyingController):
|
|||||||
if self.is_return or flt(d.item_tax_amount):
|
if self.is_return or flt(d.item_tax_amount):
|
||||||
loss_account = expenses_included_in_valuation
|
loss_account = expenses_included_in_valuation
|
||||||
else:
|
else:
|
||||||
loss_account = self.get_company_default("default_expense_account")
|
loss_account = self.get_company_default("default_expense_account", ignore_validation=True) or stock_rbnb
|
||||||
|
|
||||||
cost_center = d.cost_center or frappe.get_cached_value("Company", self.company, "cost_center")
|
cost_center = d.cost_center or frappe.get_cached_value("Company", self.company, "cost_center")
|
||||||
|
|
||||||
|
@ -336,10 +336,13 @@ class TestPurchaseReceipt(unittest.TestCase):
|
|||||||
se3.cancel()
|
se3.cancel()
|
||||||
po.reload()
|
po.reload()
|
||||||
pr2.load_from_db()
|
pr2.load_from_db()
|
||||||
pr2.cancel()
|
|
||||||
|
|
||||||
po.load_from_db()
|
if pr2.docstatus == 1 and frappe.db.get_value('Stock Ledger Entry',
|
||||||
po.cancel()
|
{'voucher_no': pr2.name, 'is_cancelled': 0}, 'name'):
|
||||||
|
pr2.cancel()
|
||||||
|
|
||||||
|
po.load_from_db()
|
||||||
|
po.cancel()
|
||||||
|
|
||||||
def test_serial_no_supplier(self):
|
def test_serial_no_supplier(self):
|
||||||
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
|
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
|
||||||
@ -1044,7 +1047,7 @@ class TestPurchaseReceipt(unittest.TestCase):
|
|||||||
'account': srbnb_account,
|
'account': srbnb_account,
|
||||||
'voucher_detail_no': pr.items[1].name
|
'voucher_detail_no': pr.items[1].name
|
||||||
}, pluck="name")
|
}, pluck="name")
|
||||||
|
|
||||||
# check if the entries are not merged into one
|
# check if the entries are not merged into one
|
||||||
# seperate entries should be made since voucher_detail_no is different
|
# seperate entries should be made since voucher_detail_no is different
|
||||||
self.assertEqual(len(item_one_gl_entry), 1)
|
self.assertEqual(len(item_one_gl_entry), 1)
|
||||||
@ -1055,13 +1058,13 @@ class TestPurchaseReceipt(unittest.TestCase):
|
|||||||
def test_purchase_receipt_with_exchange_rate_difference(self):
|
def test_purchase_receipt_with_exchange_rate_difference(self):
|
||||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice
|
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice
|
||||||
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt
|
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt
|
||||||
|
|
||||||
pi = create_purchase_invoice(company="_Test Company with perpetual inventory",
|
pi = create_purchase_invoice(company="_Test Company with perpetual inventory",
|
||||||
cost_center = "Main - TCP1",
|
cost_center = "Main - TCP1",
|
||||||
warehouse = "Stores - TCP1",
|
warehouse = "Stores - TCP1",
|
||||||
expense_account ="_Test Account Cost for Goods Sold - TCP1",
|
expense_account ="_Test Account Cost for Goods Sold - TCP1",
|
||||||
currency = "USD", conversion_rate = 70)
|
currency = "USD", conversion_rate = 70)
|
||||||
|
|
||||||
pr = create_purchase_receipt(pi.name)
|
pr = create_purchase_receipt(pi.name)
|
||||||
pr.conversion_rate = 80
|
pr.conversion_rate = 80
|
||||||
pr.items[0].purchase_invoice = pi.name
|
pr.items[0].purchase_invoice = pi.name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user