Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: COGS account in purchase receipt (backport #26735) #28177

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class TestPricingRule(unittest.TestCase):
def setUp(self):
delete_existing_pricing_rules()
setup_pricing_rule_data()

def tearDown(self):
delete_existing_pricing_rules()
Expand Down Expand Up @@ -561,6 +562,8 @@ def test_pricing_rule_for_transaction(self):
for doc in [si, si1]:
doc.delete()

test_dependencies = ["Campaign"]

def make_pricing_rule(**args):
args = frappe._dict(args)

Expand Down Expand Up @@ -607,6 +610,13 @@ def make_pricing_rule(**args):
if 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():
for doctype in ["Pricing Rule", "Pricing Rule Item Code",
Expand Down
6 changes: 3 additions & 3 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,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.whitelist()
def get_company_default(company, fieldname):
value = frappe.get_cached_value('Company', company, fieldname)
def get_company_default(company, fieldname, ignore_validation=False):
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}")
.format(frappe.get_meta("Company").get_label(fieldname), company))

Expand Down
4 changes: 2 additions & 2 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,9 @@ def throw_overbill_exception(self, item, max_allowed_amt):
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))

def get_company_default(self, fieldname):
def get_company_default(self, fieldname, ignore_validation=False):
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):
stock_items = []
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def make_item_gl_entries(self, gl_entries, warehouse_account=None):
if self.is_return or flt(d.item_tax_amount):
loss_account = expenses_included_in_valuation
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")

Expand Down
16 changes: 15 additions & 1 deletion erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,21 @@ def test_subcontracting_over_receipt(self):

pr1.submit()
self.assertRaises(frappe.ValidationError, pr2.submit)
frappe.db.rollback()

pr1.cancel()
se.cancel()
se1.cancel()
se2.cancel()
se3.cancel()
po.reload()
pr2.load_from_db()

if pr2.docstatus == 1 and frappe.db.get_value('Stock Ledger Entry',
{'voucher_no': pr2.name, 'is_cancelled': 0}, 'name'):
pr2.cancel()

po.load_from_db()
po.cancel()

def test_serial_no_supplier(self):
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
Expand Down