Browse Source

Merge branch 'develop' into se-required-items-from-jc

develop
Marica 3 years ago
committed by GitHub
parent
commit
612bb5c749
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/CONTRIBUTING.md
  2. 1
      README.md
  3. 2
      erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
  4. 2
      erpnext/accounts/doctype/loyalty_program/loyalty_program.js
  5. 16
      erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
  6. 2
      erpnext/accounts/doctype/pricing_rule/pricing_rule.js
  7. 113
      erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py
  8. 59
      erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py
  9. 4
      erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json
  10. 13
      erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
  11. 22
      erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
  12. 10
      erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
  13. 13
      erpnext/accounts/doctype/sales_invoice/sales_invoice.js
  14. 12
      erpnext/accounts/party.py
  15. 63
      erpnext/accounts/report/general_ledger/general_ledger.py
  16. 228
      erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.json
  17. 4
      erpnext/controllers/accounts_controller.py
  18. 19
      erpnext/controllers/buying_controller.py
  19. 3
      erpnext/erpnext_integrations/connectors/woocommerce_connection.py
  20. 6
      erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py
  21. 1
      erpnext/erpnext_integrations/utils.py
  22. 32
      erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py
  23. 6
      erpnext/manufacturing/doctype/job_card/job_card.js
  24. 3
      erpnext/manufacturing/doctype/job_card/job_card.json
  25. 2
      erpnext/manufacturing/doctype/production_plan/production_plan.js
  26. 1
      erpnext/patches.txt
  27. 11
      erpnext/patches/v13_0/item_naming_series_not_mandatory.py
  28. 40
      erpnext/public/js/controllers/buying.js
  29. 17
      erpnext/regional/report/gstr_1/gstr_1.py
  30. 2
      erpnext/selling/doctype/sales_order/sales_order.js
  31. 57
      erpnext/selling/doctype/sales_order/sales_order.py
  32. 72
      erpnext/selling/doctype/sales_order/test_sales_order.py
  33. 321
      erpnext/selling/doctype/sales_team/sales_team.json
  34. 5
      erpnext/setup/doctype/item_group/item_group.py
  35. 4
      erpnext/setup/doctype/naming_series/naming_series.py
  36. 7
      erpnext/stock/doctype/item/item.py
  37. 2
      erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js
  38. 553
      erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
  39. 14
      erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
  40. 2
      erpnext/stock/doctype/serial_no/serial_no.py
  41. 28
      erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py
  42. 2
      erpnext/stock/doctype/stock_settings/stock_settings.py

2
.github/CONTRIBUTING.md

@ -23,7 +23,7 @@ If your issue is not clear or does not meet the guidelines, then it will be clos
1. **Steps to Reproduce:** The bug report must have a list of steps needed to reproduce a bug. If we cannot reproduce it, then we cannot solve it.
1. **Version Number:** Please add the version number in your report. Often a bug is fixed in the latest version
1. **Clear Title:** Add a clear subject to your bug report like "Unable to submit Purchase Order without Basic Rate" instead of just "Cannot Submit"
1. **Screenshots:** Screenshots are a great way of communicating the issues. Try adding annotations or using LiceCAP to take a screencast in `gif`.
1. **Screenshots:** Screenshots are a great way of communicating issues. Try adding annotations or using LiceCAP to take a screencast in `gif`.
### Feature Request Guidelines

1
README.md

@ -8,6 +8,7 @@
[![CI](https://github.com/frappe/erpnext/actions/workflows/server-tests.yml/badge.svg?branch=develop)](https://github.com/frappe/erpnext/actions/workflows/server-tests.yml)
[![Open Source Helpers](https://www.codetriage.com/frappe/erpnext/badges/users.svg)](https://www.codetriage.com/frappe/erpnext)
[![codecov](https://codecov.io/gh/frappe/erpnext/branch/develop/graph/badge.svg?token=0TwvyUg3I5)](https://codecov.io/gh/frappe/erpnext)
[![docker pulls](https://img.shields.io/docker/pulls/frappe/erpnext-worker.svg)](https://hub.docker.com/r/frappe/erpnext-worker)
[https://erpnext.com](https://erpnext.com)

2
erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js

@ -8,7 +8,7 @@ frappe.ui.form.on('Accounting Dimension Filter', {
}
let help_content =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
`<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<p>
<i class="fa fa-hand-right"></i>

2
erpnext/accounts/doctype/loyalty_program/loyalty_program.js

@ -6,7 +6,7 @@ frappe.provide("erpnext.accounts.dimensions");
frappe.ui.form.on('Loyalty Program', {
setup: function(frm) {
var help_content =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
`<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<h4>
<i class="fa fa-hand-right"></i>

16
erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py

@ -110,9 +110,15 @@ class POSInvoiceMergeLog(Document):
def merge_pos_invoice_into(self, invoice, data):
items, payments, taxes = [], [], []
loyalty_amount_sum, loyalty_points_sum = 0, 0
rounding_adjustment, base_rounding_adjustment = 0, 0
rounded_total, base_rounded_total = 0, 0
loyalty_amount_sum, loyalty_points_sum, idx = 0, 0, 1
for doc in data:
map_doc(doc, invoice, table_map={ "doctype": invoice.doctype })
@ -146,6 +152,8 @@ class POSInvoiceMergeLog(Document):
found = True
if not found:
tax.charge_type = 'Actual'
tax.idx = idx
idx += 1
tax.included_in_print_rate = 0
tax.tax_amount = tax.tax_amount_after_discount_amount
tax.base_tax_amount = tax.base_tax_amount_after_discount_amount
@ -163,8 +171,8 @@ class POSInvoiceMergeLog(Document):
payments.append(payment)
rounding_adjustment += doc.rounding_adjustment
rounded_total += doc.rounded_total
base_rounding_adjustment += doc.rounding_adjustment
base_rounded_total += doc.rounded_total
base_rounding_adjustment += doc.base_rounding_adjustment
base_rounded_total += doc.base_rounded_total
if loyalty_points_sum:
@ -176,9 +184,9 @@ class POSInvoiceMergeLog(Document):
invoice.set('payments', payments)
invoice.set('taxes', taxes)
invoice.set('rounding_adjustment',rounding_adjustment)
invoice.set('rounding_adjustment',base_rounding_adjustment)
invoice.set('base_rounded_total',base_rounded_total)
invoice.set('base_rounding_adjustment',base_rounding_adjustment)
invoice.set('rounded_total',rounded_total)
invoice.set('base_rounded_total',base_rounded_total)
invoice.additional_discount_percentage = 0
invoice.discount_amount = 0.0
invoice.taxes_and_charges = None

2
erpnext/accounts/doctype/pricing_rule/pricing_rule.js

@ -38,7 +38,7 @@ frappe.ui.form.on('Pricing Rule', {
refresh: function(frm) {
var help_content =
`<table class="table table-bordered" style="background-color: #f9f9f9;">
`<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<h4>
<i class="fa fa-hand-right"></i>

113
erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py

@ -20,6 +20,9 @@ price_discount_fields = ['rate_or_discount', 'apply_discount_on', 'apply_discoun
product_discount_fields = ['free_item', 'free_qty', 'free_item_uom',
'free_item_rate', 'same_item', 'is_recursive', 'apply_multiple_pricing_rules']
class TransactionExists(frappe.ValidationError):
pass
class PromotionalScheme(Document):
def validate(self):
if not self.selling and not self.buying:
@ -28,6 +31,40 @@ class PromotionalScheme(Document):
or self.product_discount_slabs):
frappe.throw(_("Price or product discount slabs are required"))
self.validate_applicable_for()
self.validate_pricing_rules()
def validate_applicable_for(self):
if self.applicable_for:
applicable_for = frappe.scrub(self.applicable_for)
if not self.get(applicable_for):
msg = (f'The field {frappe.bold(self.applicable_for)} is required')
frappe.throw(_(msg))
def validate_pricing_rules(self):
if self.is_new():
return
transaction_exists = False
docnames = []
# If user has changed applicable for
if self._doc_before_save.applicable_for == self.applicable_for:
return
docnames = frappe.get_all('Pricing Rule',
filters= {'promotional_scheme': self.name})
for docname in docnames:
if frappe.db.exists('Pricing Rule Detail',
{'pricing_rule': docname.name, 'docstatus': ('<', 2)}):
raise_for_transaction_exists(self.name)
if docnames and not transaction_exists:
for docname in docnames:
frappe.delete_doc('Pricing Rule', docname.name)
def on_update(self):
pricing_rules = frappe.get_all(
'Pricing Rule',
@ -67,6 +104,13 @@ class PromotionalScheme(Document):
{'promotional_scheme': self.name}):
frappe.delete_doc('Pricing Rule', rule.name)
def raise_for_transaction_exists(name):
msg = (f"""You can't change the {frappe.bold(_('Applicable For'))}
because transactions are present against the Promotional Scheme {frappe.bold(name)}. """)
msg += 'Kindly disable this Promotional Scheme and create new for new Applicable For.'
frappe.throw(_(msg), TransactionExists)
def get_pricing_rules(doc, rules=None):
if rules is None:
rules = {}
@ -84,45 +128,59 @@ def _get_pricing_rules(doc, child_doc, discount_fields, rules=None):
new_doc = []
args = get_args_for_pricing_rule(doc)
applicable_for = frappe.scrub(doc.get('applicable_for'))
for idx, d in enumerate(doc.get(child_doc)):
if d.name in rules:
for applicable_for_value in args.get(applicable_for):
temp_args = args.copy()
docname = frappe.get_all(
'Pricing Rule',
fields = ["promotional_scheme_id", "name", applicable_for],
filters = {
'promotional_scheme_id': d.name,
applicable_for: applicable_for_value
}
)
if docname:
pr = frappe.get_doc('Pricing Rule', docname[0].get('name'))
temp_args[applicable_for] = applicable_for_value
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
else:
pr = frappe.new_doc("Pricing Rule")
pr.title = doc.name
temp_args[applicable_for] = applicable_for_value
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
if not args.get(applicable_for):
docname = get_pricing_rule_docname(d)
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields, d, docname)
new_doc.append(pr)
else:
for applicable_for_value in args.get(applicable_for):
docname = get_pricing_rule_docname(d, applicable_for, applicable_for_value)
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields,
d, docname, applicable_for, applicable_for_value)
new_doc.append(pr)
else:
elif args.get(applicable_for):
applicable_for_values = args.get(applicable_for) or []
for applicable_for_value in applicable_for_values:
pr = frappe.new_doc("Pricing Rule")
pr.title = doc.name
temp_args = args.copy()
temp_args[applicable_for] = applicable_for_value
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields,
d, applicable_for=applicable_for, value= applicable_for_value)
new_doc.append(pr)
else:
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields, d)
new_doc.append(pr)
return new_doc
def get_pricing_rule_docname(row: dict, applicable_for: str = None, applicable_for_value: str = None) -> str:
fields = ['promotional_scheme_id', 'name']
filters = {
'promotional_scheme_id': row.name
}
if applicable_for:
fields.append(applicable_for)
filters[applicable_for] = applicable_for_value
docname = frappe.get_all('Pricing Rule', fields = fields, filters = filters)
return docname[0].name if docname else ''
def prepare_pricing_rule(args, doc, child_doc, discount_fields, d, docname=None, applicable_for=None, value=None):
if docname:
pr = frappe.get_doc("Pricing Rule", docname)
else:
pr = frappe.new_doc("Pricing Rule")
pr.title = doc.name
temp_args = args.copy()
if value:
temp_args[applicable_for] = value
return set_args(temp_args, pr, doc, child_doc, discount_fields, d)
def set_args(args, pr, doc, child_doc, discount_fields, child_doc_fields):
pr.update(args)
@ -145,6 +203,7 @@ def set_args(args, pr, doc, child_doc, discount_fields, child_doc_fields):
apply_on: d.get(apply_on),
'uom': d.uom
})
return pr
def get_args_for_pricing_rule(doc):

59
erpnext/accounts/doctype/promotional_scheme/test_promotional_scheme.py

@ -5,10 +5,17 @@ import unittest
import frappe
from erpnext.accounts.doctype.promotional_scheme.promotional_scheme import TransactionExists
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
class TestPromotionalScheme(unittest.TestCase):
def setUp(self):
if frappe.db.exists('Promotional Scheme', '_Test Scheme'):
frappe.delete_doc('Promotional Scheme', '_Test Scheme')
def test_promotional_scheme(self):
ps = make_promotional_scheme()
ps = make_promotional_scheme(applicable_for='Customer', customer='_Test Customer')
price_rules = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name", "creation"],
filters = {'promotional_scheme': ps.name})
self.assertTrue(len(price_rules),1)
@ -39,22 +46,62 @@ class TestPromotionalScheme(unittest.TestCase):
filters = {'promotional_scheme': ps.name})
self.assertEqual(price_rules, [])
def make_promotional_scheme():
def test_promotional_scheme_without_applicable_for(self):
ps = make_promotional_scheme()
price_rules = frappe.get_all('Pricing Rule', filters = {'promotional_scheme': ps.name})
self.assertTrue(len(price_rules), 1)
frappe.delete_doc('Promotional Scheme', ps.name)
price_rules = frappe.get_all('Pricing Rule', filters = {'promotional_scheme': ps.name})
self.assertEqual(price_rules, [])
def test_change_applicable_for_in_promotional_scheme(self):
ps = make_promotional_scheme()
price_rules = frappe.get_all('Pricing Rule', filters = {'promotional_scheme': ps.name})
self.assertTrue(len(price_rules), 1)
so = make_sales_order(qty=5, currency='USD', do_not_save=True)
so.set_missing_values()
so.save()
self.assertEqual(price_rules[0].name, so.pricing_rules[0].pricing_rule)
ps.applicable_for = 'Customer'
ps.append('customer', {
'customer': '_Test Customer'
})
self.assertRaises(TransactionExists, ps.save)
frappe.delete_doc('Sales Order', so.name)
frappe.delete_doc('Promotional Scheme', ps.name)
price_rules = frappe.get_all('Pricing Rule', filters = {'promotional_scheme': ps.name})
self.assertEqual(price_rules, [])
def make_promotional_scheme(**args):
args = frappe._dict(args)
ps = frappe.new_doc('Promotional Scheme')
ps.name = '_Test Scheme'
ps.append('items',{
'item_code': '_Test Item'
})
ps.selling = 1
ps.append('price_discount_slabs',{
'min_qty': 4,
'validate_applied_rule': 0,
'discount_percentage': 20,
'rule_description': 'Test'
})
ps.applicable_for = 'Customer'
ps.append('customer',{
'customer': "_Test Customer"
})
ps.company = '_Test Company'
if args.applicable_for:
ps.applicable_for = args.applicable_for
ps.append(frappe.scrub(args.applicable_for), {
frappe.scrub(args.applicable_for): args.get(frappe.scrub(args.applicable_for))
})
ps.save()
return ps

4
erpnext/accounts/doctype/promotional_scheme_price_discount/promotional_scheme_price_discount.json

@ -136,7 +136,7 @@
"label": "Threshold for Suggestion"
},
{
"default": "1",
"default": "0",
"fieldname": "validate_applied_rule",
"fieldtype": "Check",
"label": "Validate Applied Rule"
@ -169,7 +169,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-08-19 15:49:29.598727",
"modified": "2021-11-16 00:25:33.843996",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Promotional Scheme Price Discount",

13
erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js

@ -592,8 +592,17 @@ frappe.ui.form.on("Purchase Invoice", {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
if (frm.doc.company) {
frappe.db.get_value('Company', frm.doc.company, 'default_payable_account', (r) => {
frm.set_value('credit_to', r.default_payable_account);
frappe.call({
method:
"erpnext.accounts.party.get_party_account",
args: {
party_type: 'Supplier',
party: frm.doc.supplier,
company: frm.doc.company
},
callback: (response) => {
if (response) frm.set_value("credit_to", response.message);
},
});
}
},

22
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py

@ -13,6 +13,7 @@ from erpnext.accounts.doctype.account.test_account import create_account, get_in
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
from erpnext.controllers.accounts_controller import get_payment_terms
from erpnext.controllers.buying_controller import QtyMismatchError
from erpnext.exceptions import InvalidCurrency
from erpnext.projects.doctype.project.test_project import make_project
from erpnext.stock.doctype.item.test_item import create_item
@ -35,6 +36,27 @@ class TestPurchaseInvoice(unittest.TestCase):
def tearDownClass(self):
unlink_payment_on_cancel_of_invoice(0)
def test_purchase_invoice_received_qty(self):
"""
1. Test if received qty is validated against accepted + rejected
2. Test if received qty is auto set on save
"""
pi = make_purchase_invoice(
qty=1,
rejected_qty=1,
received_qty=3,
item_code="_Test Item Home Desktop 200",
rejected_warehouse = "_Test Rejected Warehouse - _TC",
update_stock=True, do_not_save=True)
self.assertRaises(QtyMismatchError, pi.save)
pi.items[0].received_qty = 0
pi.save()
self.assertEqual(pi.items[0].received_qty, 2)
# teardown
pi.delete()
def test_gl_entries_without_perpetual_inventory(self):
frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
pi = frappe.copy_doc(test_records[0])

10
erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json

@ -22,10 +22,10 @@
"received_qty",
"qty",
"rejected_qty",
"stock_uom",
"col_break2",
"uom",
"conversion_factor",
"stock_uom",
"stock_qty",
"sec_break1",
"price_list_rate",
@ -175,7 +175,8 @@
{
"fieldname": "received_qty",
"fieldtype": "Float",
"label": "Received Qty"
"label": "Received Qty",
"read_only": 1
},
{
"bold": 1,
@ -223,7 +224,7 @@
{
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Stock Qty",
"label": "Accepted Qty in Stock UOM",
"print_hide": 1,
"read_only": 1,
"reqd": 1
@ -870,10 +871,11 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2021-09-01 16:04:03.538643",
"modified": "2021-11-15 17:04:07.191013",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",

13
erpnext/accounts/doctype/sales_invoice/sales_invoice.js

@ -15,8 +15,17 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
let me = this;
if (this.frm.doc.company) {
frappe.db.get_value('Company', this.frm.doc.company, 'default_receivable_account', (r) => {
me.frm.set_value('debit_to', r.default_receivable_account);
frappe.call({
method:
"erpnext.accounts.party.get_party_account",
args: {
party_type: 'Customer',
party: this.frm.doc.customer,
company: this.frm.doc.company
},
callback: (response) => {
if (response) me.frm.set_value("debit_to", response.message);
},
});
}
}

12
erpnext/accounts/party.py

@ -83,7 +83,8 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
if party_type=="Customer":
party_details["sales_team"] = [{
"sales_person": d.sales_person,
"allocated_percentage": d.allocated_percentage or None
"allocated_percentage": d.allocated_percentage or None,
"commission_rate": d.commission_rate
} for d in party.get("sales_team")]
# supplier tax withholding category
@ -218,7 +219,7 @@ def set_account_and_due_date(party, account, party_type, company, posting_date,
return out
@frappe.whitelist()
def get_party_account(party_type, party, company=None):
def get_party_account(party_type, party=None, company=None):
"""Returns the account for the given `party`.
Will first search in party (Customer / Supplier) record, if not found,
will search in group (Customer Group / Supplier Group),
@ -226,8 +227,11 @@ def get_party_account(party_type, party, company=None):
if not company:
frappe.throw(_("Please select a Company"))
if not party:
return
if not party and party_type in ['Customer', 'Supplier']:
default_account_name = "default_receivable_account" \
if party_type=="Customer" else "default_payable_account"
return frappe.get_cached_value('Company', company, default_account_name)
account = frappe.db.get_value("Party Account",
{"parenttype": party_type, "parent": party, "company": company}, "account")

63
erpnext/accounts/report/general_ledger/general_ledger.py

@ -6,7 +6,7 @@ from collections import OrderedDict
import frappe
from frappe import _, _dict
from frappe.utils import cstr, flt, getdate
from frappe.utils import cstr, getdate
from erpnext import get_company_currency, get_default_company
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
@ -17,6 +17,8 @@ from erpnext.accounts.report.financial_statements import get_cost_centers_with_c
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
from erpnext.accounts.utils import get_account_currency
# to cache translations
TRANSLATIONS = frappe._dict()
def execute(filters=None):
if not filters:
@ -42,10 +44,20 @@ def execute(filters=None):
columns = get_columns(filters)
update_translations()
res = get_result(filters, account_details)
return columns, res
def update_translations():
TRANSLATIONS.update(
dict(
OPENING = _('Opening'),
TOTAL = _('Total'),
CLOSING_TOTAL = _('Closing (Opening + Total)')
)
)
def validate_filters(filters, account_details):
if not filters.get("company"):
@ -351,9 +363,9 @@ def get_totals_dict():
credit_in_account_currency=0.0
)
return _dict(
opening = _get_debit_credit_dict(_('Opening')),
total = _get_debit_credit_dict(_('Total')),
closing = _get_debit_credit_dict(_('Closing (Opening + Total)'))
opening = _get_debit_credit_dict(TRANSLATIONS.OPENING),
total = _get_debit_credit_dict(TRANSLATIONS.TOTAL),
closing = _get_debit_credit_dict(TRANSLATIONS.CLOSING_TOTAL)
)
def group_by_field(group_by):
@ -378,22 +390,23 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
entries = []
consolidated_gle = OrderedDict()
group_by = group_by_field(filters.get('group_by'))
group_by_voucher_consolidated = filters.get("group_by") == 'Group by Voucher (Consolidated)'
if filters.get('show_net_values_in_party_account'):
account_type_map = get_account_type_map(filters.get('company'))
def update_value_in_dict(data, key, gle):
data[key].debit += flt(gle.debit)
data[key].credit += flt(gle.credit)
data[key].debit += gle.debit
data[key].credit += gle.credit
data[key].debit_in_account_currency += flt(gle.debit_in_account_currency)
data[key].credit_in_account_currency += flt(gle.credit_in_account_currency)
data[key].debit_in_account_currency += gle.debit_in_account_currency
data[key].credit_in_account_currency += gle.credit_in_account_currency
if filters.get('show_net_values_in_party_account') and \
account_type_map.get(data[key].account) in ('Receivable', 'Payable'):
net_value = flt(data[key].debit) - flt(data[key].credit)
net_value_in_account_currency = flt(data[key].debit_in_account_currency) \
- flt(data[key].credit_in_account_currency)
net_value = data[key].debit - data[key].credit
net_value_in_account_currency = data[key].debit_in_account_currency \
- data[key].credit_in_account_currency
if net_value < 0:
dr_or_cr = 'credit'
@ -411,19 +424,29 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
data[key].against_voucher += ', ' + gle.against_voucher
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
show_opening_entries = filters.get("show_opening_entries")
for gle in gl_entries:
if (gle.posting_date < from_date or
(cstr(gle.is_opening) == "Yes" and not filters.get("show_opening_entries"))):
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'opening', gle)
update_value_in_dict(totals, 'opening', gle)
group_by_value = gle.get(group_by)
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing', gle)
if (gle.posting_date < from_date or (cstr(gle.is_opening) == "Yes" and not show_opening_entries)):
if not group_by_voucher_consolidated:
update_value_in_dict(gle_map[group_by_value].totals, 'opening', gle)
update_value_in_dict(gle_map[group_by_value].totals, 'closing', gle)
update_value_in_dict(totals, 'opening', gle)
update_value_in_dict(totals, 'closing', gle)
elif gle.posting_date <= to_date:
if filters.get("group_by") != 'Group by Voucher (Consolidated)':
gle_map[gle.get(group_by)].entries.append(gle)
elif filters.get("group_by") == 'Group by Voucher (Consolidated)':
if not group_by_voucher_consolidated:
update_value_in_dict(gle_map[group_by_value].totals, 'total', gle)
update_value_in_dict(gle_map[group_by_value].totals, 'closing', gle)
update_value_in_dict(totals, 'total', gle)
update_value_in_dict(totals, 'closing', gle)
gle_map[group_by_value].entries.append(gle)
elif group_by_voucher_consolidated:
keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")]
for dim in accounting_dimensions:
keylist.append(gle.get(dim))
@ -435,9 +458,7 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
update_value_in_dict(consolidated_gle, key, gle)
for key, value in consolidated_gle.items():
update_value_in_dict(gle_map[value.get(group_by)].totals, 'total', value)
update_value_in_dict(totals, 'total', value)
update_value_in_dict(gle_map[value.get(group_by)].totals, 'closing', value)
update_value_in_dict(totals, 'closing', value)
entries.append(value)

228
erpnext/buying/doctype/supplier_scorecard_criteria/supplier_scorecard_criteria.json

@ -1,184 +1,70 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:criteria_name",
"beta": 0,
"creation": "2017-05-29 01:32:43.064891",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"actions": [],
"allow_rename": 1,
"autoname": "field:criteria_name",
"creation": "2017-05-29 01:32:43.064891",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"criteria_name",
"max_score",
"formula",
"weight"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "criteria_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Criteria Name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"fieldname": "criteria_name",
"fieldtype": "Data",
"label": "Criteria Name",
"reqd": 1,
"unique": 1
},
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"default": "100",
"fieldname": "max_score",
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Max Score",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"default": "100",
"fieldname": "max_score",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Max Score",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "formula",
"fieldtype": "Small Text",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 1,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Criteria Formula",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "formula",
"fieldtype": "Small Text",
"ignore_xss_filter": 1,
"in_list_view": 1,
"label": "Criteria Formula",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "weight",
"fieldtype": "Percent",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Criteria Weight",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
"fieldname": "weight",
"fieldtype": "Percent",
"label": "Criteria Weight"
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-01-22 10:47:00.000822",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier Scorecard Criteria",
"name_case": "",
"owner": "Administrator",
],
"links": [],
"modified": "2021-11-11 18:34:58.477648",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier Scorecard Criteria",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1,
"track_seen": 0
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

4
erpnext/controllers/accounts_controller.py

@ -1402,8 +1402,8 @@ class AccountsController(TransactionBase):
grand_total -= self.get("total_advance")
base_grand_total = flt(grand_total * self.get("conversion_rate"), self.precision("base_grand_total"))
if flt(total, self.precision("grand_total")) != flt(grand_total, self.precision("grand_total")) or \
flt(base_total, self.precision("base_grand_total")) != flt(base_grand_total, self.precision("base_grand_total")):
if flt(total, self.precision("grand_total")) - flt(grand_total, self.precision("grand_total")) > 0.1 or \
flt(base_total, self.precision("base_grand_total")) - flt(base_grand_total, self.precision("base_grand_total")) > 0.1:
frappe.throw(_("Total Payment Amount in Payment Schedule must be equal to Grand / Rounded Total"))
def is_rounded_total_disabled(self):

19
erpnext/controllers/buying_controller.py

@ -3,7 +3,7 @@
import frappe
from frappe import _, msgprint
from frappe import ValidationError, _, msgprint
from frappe.contacts.doctype.address.address import get_address_display
from frappe.utils import cint, cstr, flt, getdate
@ -17,6 +17,9 @@ from erpnext.stock.get_item_details import get_conversion_factor
from erpnext.stock.utils import get_incoming_rate
class QtyMismatchError(ValidationError):
pass
class BuyingController(StockController, Subcontracting):
def get_feed(self):
@ -360,19 +363,15 @@ class BuyingController(StockController, Subcontracting):
def validate_accepted_rejected_qty(self):
for d in self.get("items"):
self.validate_negative_quantity(d, ["received_qty","qty", "rejected_qty"])
if not flt(d.received_qty) and flt(d.qty):
d.received_qty = flt(d.qty) - flt(d.rejected_qty)
elif not flt(d.qty) and flt(d.rejected_qty):
d.qty = flt(d.received_qty) - flt(d.rejected_qty)
elif not flt(d.rejected_qty):
d.rejected_qty = flt(d.received_qty) - flt(d.qty)
if not flt(d.received_qty) and (flt(d.qty) or flt(d.rejected_qty)):
d.received_qty = flt(d.qty) + flt(d.rejected_qty)
val = flt(d.qty) + flt(d.rejected_qty)
# Check Received Qty = Accepted Qty + Rejected Qty
val = flt(d.qty) + flt(d.rejected_qty)
if (flt(val, d.precision("received_qty")) != flt(d.received_qty, d.precision("received_qty"))):
frappe.throw(_("Accepted + Rejected Qty must be equal to Received quantity for Item {0}").format(d.item_code))
message = _("Row #{0}: Received Qty must be equal to Accepted + Rejected Qty for Item {1}").format(d.idx, d.item_code)
frappe.throw(msg=message, title=_("Mismatch"), exc=QtyMismatchError)
def validate_negative_quantity(self, item_row, field_list):
if self.is_return:

3
erpnext/erpnext_integrations/connectors/woocommerce_connection.py

@ -19,8 +19,7 @@ def verify_request():
)
if frappe.request.data and \
frappe.get_request_header("X-Wc-Webhook-Signature") and \
not sig == bytes(frappe.get_request_header("X-Wc-Webhook-Signature").encode()):
not sig == frappe.get_request_header("X-Wc-Webhook-Signature", "").encode():
frappe.throw(_("Unverified Webhook Data"))
frappe.set_user(woocommerce_settings.creation_user)

6
erpnext/erpnext_integrations/doctype/mpesa_settings/mpesa_settings.py

@ -141,6 +141,9 @@ def verify_transaction(**kwargs):
transaction_response = frappe._dict(kwargs["Body"]["stkCallback"])
checkout_id = getattr(transaction_response, "CheckoutRequestID", "")
if not isinstance(checkout_id, str):
frappe.throw(_("Invalid Checkout Request ID"))
integration_request = frappe.get_doc("Integration Request", checkout_id)
transaction_data = frappe._dict(loads(integration_request.data))
total_paid = 0 # for multiple integration request made against a pos invoice
@ -231,6 +234,9 @@ def process_balance_info(**kwargs):
account_balance_response = frappe._dict(kwargs["Result"])
conversation_id = getattr(account_balance_response, "ConversationID", "")
if not isinstance(conversation_id, str):
frappe.throw(_("Invalid Conversation ID"))
request = frappe.get_doc("Integration Request", conversation_id)
if request.status == "Completed":

1
erpnext/erpnext_integrations/utils.py

@ -23,7 +23,6 @@ def validate_webhooks_request(doctype, hmac_key, secret_key='secret'):
)
if frappe.request.data and \
frappe.get_request_header(hmac_key) and \
not sig == bytes(frappe.get_request_header(hmac_key).encode()):
frappe.throw(_("Unverified Webhook Data"))
frappe.set_user(settings.modified_by)

32
erpnext/maintenance/doctype/maintenance_visit/test_maintenance_visit.py

@ -3,7 +3,39 @@
import unittest
import frappe
from frappe.utils.data import today
# test_records = frappe.get_test_records('Maintenance Visit')
class TestMaintenanceVisit(unittest.TestCase):
pass
def make_maintenance_visit():
mv = frappe.new_doc("Maintenance Visit")
mv.company = "_Test Company"
mv.customer = "_Test Customer"
mv.mntc_date = today()
mv.completion_status = "Partially Completed"
sales_person = make_sales_person("Dwight Schrute")
mv.append("purposes", {
"item_code": "_Test Item",
"sales_person": "Sales Team",
"description": "Test Item",
"work_done": "Test Work Done",
"service_person": sales_person.name
})
mv.insert(ignore_permissions=True)
return mv
def make_sales_person(name):
sales_person = frappe.get_doc({
'doctype': "Sales Person",
'sales_person_name': name
})
sales_person.insert(ignore_if_duplicate = True)
return sales_person

6
erpnext/manufacturing/doctype/job_card/job_card.js

@ -23,6 +23,12 @@ frappe.ui.form.on('Job Card', {
);
},
onload: function(frm) {
if (frm.doc.scrap_items.length == 0) {
frm.fields_dict['scrap_items_section'].collapse();
}
},
refresh: function(frm) {
frappe.flags.pause_job = 0;
frappe.flags.resume_job = 0;

3
erpnext/manufacturing/doctype/job_card/job_card.json

@ -396,6 +396,7 @@
"options": "Batch"
},
{
"collapsible": 1,
"fieldname": "scrap_items_section",
"fieldtype": "Section Break",
"label": "Scrap Items"
@ -411,7 +412,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2021-09-14 00:38:46.873105",
"modified": "2021-11-12 10:15:03.572401",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Job Card",

2
erpnext/manufacturing/doctype/production_plan/production_plan.js

@ -105,7 +105,7 @@ frappe.ui.form.on('Production Plan', {
}
frm.trigger("material_requirement");
const projected_qty_formula = ` <table class="table table-bordered" style="background-color: #f9f9f9;">
const projected_qty_formula = ` <table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td style="padding-left:25px">
<div>
<h3 style="text-decoration: underline;">

1
erpnext/patches.txt

@ -306,6 +306,7 @@ erpnext.patches.v13_0.requeue_failed_reposts
erpnext.patches.v13_0.update_job_card_status
erpnext.patches.v12_0.update_production_plan_status
erpnext.patches.v13_0.healthcare_deprecation_warning
erpnext.patches.v13_0.item_naming_series_not_mandatory
erpnext.patches.v14_0.delete_healthcare_doctypes
erpnext.patches.v13_0.update_category_in_ltds_certificate
erpnext.patches.v13_0.create_pan_field_for_india #2

11
erpnext/patches/v13_0/item_naming_series_not_mandatory.py

@ -0,0 +1,11 @@
import frappe
from erpnext.setup.doctype.naming_series.naming_series import set_by_naming_series
def execute():
stock_settings = frappe.get_doc("Stock Settings")
set_by_naming_series("Item", "item_code",
stock_settings.get("item_naming_by")=="Naming Series", hide_name_field=True, make_mandatory=0)

40
erpnext/public/js/controllers/buying.js

@ -165,43 +165,31 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac
}
qty(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) {
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "received_qty"])){ return }
if(!item.rejected_qty && item.qty) {
item.received_qty = item.qty;
}
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty);
this.calculate_received_qty(doc, cdt, cdn)
}
super.qty(doc, cdt, cdn);
}
batch_no(doc, cdt, cdn) {
super.batch_no(doc, cdt, cdn);
}
received_qty(doc, cdt, cdn) {
this.calculate_accepted_qty(doc, cdt, cdn)
}
rejected_qty(doc, cdt, cdn) {
this.calculate_accepted_qty(doc, cdt, cdn)
this.calculate_received_qty(doc, cdt, cdn)
}
calculate_accepted_qty(doc, cdt, cdn){
calculate_received_qty(doc, cdt, cdn){
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return }
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["received_qty", "rejected_qty"])){ return }
let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item));
let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty);
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
this.qty(doc, cdt, cdn);
frappe.model.set_value(cdt, cdn, "received_qty", received_qty);
frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty);
}
batch_no(doc, cdt, cdn) {
super.batch_no(doc, cdt, cdn);
}
validate_negative_quantity(cdt, cdn, item, fieldnames){

17
erpnext/regional/report/gstr_1/gstr_1.py

@ -248,18 +248,17 @@ class Gstr1Report(object):
""" % (self.doctype, ', '.join(['%s']*len(self.invoices))), tuple(self.invoices), as_dict=1)
for d in items:
if d.item_code not in self.invoice_items.get(d.parent, {}):
self.invoice_items.setdefault(d.parent, {}).setdefault(d.item_code, 0.0)
self.invoice_items[d.parent][d.item_code] += d.get('taxable_value', 0) or d.get('base_net_amount', 0)
self.invoice_items.setdefault(d.parent, {}).setdefault(d.item_code, 0.0)
self.invoice_items[d.parent][d.item_code] += d.get('taxable_value', 0) or d.get('base_net_amount', 0)
item_tax_rate = {}
item_tax_rate = {}
if d.item_tax_rate:
item_tax_rate = json.loads(d.item_tax_rate)
if d.item_tax_rate:
item_tax_rate = json.loads(d.item_tax_rate)
for account, rate in item_tax_rate.items():
tax_rate_dict = self.item_tax_rate.setdefault(d.parent, {}).setdefault(d.item_code, [])
tax_rate_dict.append(rate)
for account, rate in item_tax_rate.items():
tax_rate_dict = self.item_tax_rate.setdefault(d.parent, {}).setdefault(d.item_code, [])
tax_rate_dict.append(rate)
def get_items_based_on_tax_rate(self):
self.tax_details = frappe.db.sql("""

2
erpnext/selling/doctype/sales_order/sales_order.js

@ -319,7 +319,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
title: __('Select Items to Manufacture'),
fields: fields,
primary_action: function() {
var data = d.get_values();
var data = {items: d.fields_dict.items.grid.get_selected_children()};
me.frm.call({
method: 'make_work_orders',
args: {

57
erpnext/selling/doctype/sales_order/sales_order.py

@ -223,60 +223,15 @@ class SalesOrder(SellingController):
check_credit_limit(self.customer, self.company)
def check_nextdoc_docstatus(self):
# Checks Delivery Note
submit_dn = frappe.db.sql_list("""
select t1.name
from `tabDelivery Note` t1,`tabDelivery Note Item` t2
where t1.name = t2.parent and t2.against_sales_order = %s and t1.docstatus = 1""", self.name)
if submit_dn:
submit_dn = [get_link_to_form("Delivery Note", dn) for dn in submit_dn]
frappe.throw(_("Delivery Notes {0} must be cancelled before cancelling this Sales Order")
.format(", ".join(submit_dn)))
# Checks Sales Invoice
submit_rv = frappe.db.sql_list("""select t1.name
linked_invoices = frappe.db.sql_list("""select distinct t1.name
from `tabSales Invoice` t1,`tabSales Invoice Item` t2
where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus < 2""",
where t1.name = t2.parent and t2.sales_order = %s and t1.docstatus = 0""",
self.name)
if submit_rv:
submit_rv = [get_link_to_form("Sales Invoice", si) for si in submit_rv]
frappe.throw(_("Sales Invoice {0} must be cancelled before cancelling this Sales Order")
.format(", ".join(submit_rv)))
#check maintenance schedule
submit_ms = frappe.db.sql_list("""
select t1.name
from `tabMaintenance Schedule` t1, `tabMaintenance Schedule Item` t2
where t2.parent=t1.name and t2.sales_order = %s and t1.docstatus = 1""", self.name)
if submit_ms:
submit_ms = [get_link_to_form("Maintenance Schedule", ms) for ms in submit_ms]
frappe.throw(_("Maintenance Schedule {0} must be cancelled before cancelling this Sales Order")
.format(", ".join(submit_ms)))
# check maintenance visit
submit_mv = frappe.db.sql_list("""
select t1.name
from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2
where t2.parent=t1.name and t2.prevdoc_docname = %s and t1.docstatus = 1""",self.name)
if submit_mv:
submit_mv = [get_link_to_form("Maintenance Visit", mv) for mv in submit_mv]
frappe.throw(_("Maintenance Visit {0} must be cancelled before cancelling this Sales Order")
.format(", ".join(submit_mv)))
# check work order
pro_order = frappe.db.sql_list("""
select name
from `tabWork Order`
where sales_order = %s and docstatus = 1""", self.name)
if pro_order:
pro_order = [get_link_to_form("Work Order", po) for po in pro_order]
frappe.throw(_("Work Order {0} must be cancelled before cancelling this Sales Order")
.format(", ".join(pro_order)))
if linked_invoices:
linked_invoices = [get_link_to_form("Sales Invoice", si) for si in linked_invoices]
frappe.throw(_("Sales Invoice {0} must be deleted before cancelling this Sales Order")
.format(", ".join(linked_invoices)))
def check_modified_date(self):
mod_db = frappe.db.get_value("Sales Order", self.name, "modified")

72
erpnext/selling/doctype/sales_order/test_sales_order.py

@ -10,6 +10,12 @@ from frappe.core.doctype.user_permission.test_user_permission import create_user
from frappe.utils import add_days, flt, getdate, nowdate
from erpnext.controllers.accounts_controller import update_child_qty_rate
from erpnext.maintenance.doctype.maintenance_schedule.test_maintenance_schedule import (
make_maintenance_schedule,
)
from erpnext.maintenance.doctype.maintenance_visit.test_maintenance_visit import (
make_maintenance_visit,
)
from erpnext.manufacturing.doctype.blanket_order.test_blanket_order import make_blanket_order
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
from erpnext.selling.doctype.sales_order.sales_order import (
@ -1278,6 +1284,72 @@ class TestSalesOrder(unittest.TestCase):
self.assertRaises(frappe.ValidationError, so.cancel)
def test_so_cancellation_after_si_submission(self):
"""
Test to check if Sales Order gets cancelled when linked Sales Invoice has been Submitted
Expected result: Sales Order should not get cancelled
"""
so = make_sales_order()
so.submit()
si = make_sales_invoice(so.name)
si.submit()
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
def test_so_cancellation_after_dn_submission(self):
"""
Test to check if Sales Order gets cancelled when linked Delivery Note has been Submitted
Expected result: Sales Order should not get cancelled
"""
so = make_sales_order()
so.submit()
dn = make_delivery_note(so.name)
dn.submit()
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
def test_so_cancellation_after_maintenance_schedule_submission(self):
"""
Expected result: Sales Order should not get cancelled
"""
so = make_sales_order()
so.submit()
ms = make_maintenance_schedule()
ms.items[0].sales_order = so.name
ms.submit()
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
def test_so_cancellation_after_maintenance_visit_submission(self):
"""
Expected result: Sales Order should not get cancelled
"""
so = make_sales_order()
so.submit()
mv = make_maintenance_visit()
mv.purposes[0].prevdoc_doctype = "Sales Order"
mv.purposes[0].prevdoc_docname = so.name
mv.submit()
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
def test_so_cancellation_after_work_order_submission(self):
"""
Expected result: Sales Order should not get cancelled
"""
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
so = make_sales_order(item_code="_Test FG Item", qty=10)
so.submit()
make_wo_order_test_record(sales_order=so.name)
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
def test_payment_terms_are_fetched_when_creating_sales_invoice(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import (
create_payment_terms_template,

321
erpnext/selling/doctype/sales_team/sales_team.json

@ -1,247 +1,100 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2013-04-19 13:30:51",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "Setup",
"editable_grid": 1,
"engine": "InnoDB",
"actions": [],
"creation": "2013-04-19 13:30:51",
"doctype": "DocType",
"document_type": "Setup",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"sales_person",
"contact_no",
"allocated_percentage",
"allocated_amount",
"commission_rate",
"incentives"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "sales_person",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Sales Person",
"length": 0,
"no_copy": 0,
"oldfieldname": "sales_person",
"oldfieldtype": "Link",
"options": "Sales Person",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "200px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"allow_on_submit": 1,
"fieldname": "sales_person",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Sales Person",
"oldfieldname": "sales_person",
"oldfieldtype": "Link",
"options": "Sales Person",
"print_width": "200px",
"reqd": 1,
"search_index": 1,
"width": "200px"
},
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "contact_no",
"fieldtype": "Data",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Contact No.",
"length": 0,
"no_copy": 0,
"oldfieldname": "contact_no",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"allow_on_submit": 1,
"fieldname": "contact_no",
"fieldtype": "Data",
"hidden": 1,
"in_list_view": 1,
"label": "Contact No.",
"oldfieldname": "contact_no",
"oldfieldtype": "Data",
"print_width": "100px",
"width": "100px"
},
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "allocated_percentage",
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Contribution (%)",
"length": 0,
"no_copy": 0,
"oldfieldname": "allocated_percentage",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "100px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"allow_on_submit": 1,
"fieldname": "allocated_percentage",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Contribution (%)",
"oldfieldname": "allocated_percentage",
"oldfieldtype": "Currency",
"print_width": "100px",
"width": "100px"
},
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "allocated_amount",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Contribution to Net Total",
"length": 0,
"no_copy": 0,
"oldfieldname": "allocated_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "120px",
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0,
"allow_on_submit": 1,
"fieldname": "allocated_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Contribution to Net Total",
"oldfieldname": "allocated_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"print_width": "120px",
"read_only": 1,
"width": "120px"
},
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "commission_rate",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Commission Rate",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
"fetch_from": "sales_person.commission_rate",
"fetch_if_empty": 1,
"fieldname": "commission_rate",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Commission Rate",
"read_only": 1
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "incentives",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Incentives",
"length": 0,
"no_copy": 0,
"oldfieldname": "incentives",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
"allow_on_submit": 1,
"fieldname": "incentives",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Incentives",
"oldfieldname": "incentives",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency"
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 1,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-09-17 13:03:14.755974",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Team",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"track_changes": 1,
"track_seen": 0,
"track_views": 0
}
],
"idx": 1,
"istable": 1,
"links": [],
"modified": "2021-11-09 23:55:20.670475",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Team",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

5
erpnext/setup/doctype/item_group/item_group.py

@ -43,7 +43,6 @@ class ItemGroup(NestedSet, WebsiteGenerator):
def on_update(self):
NestedSet.on_update(self)
invalidate_cache_for(self)
self.validate_name_with_item()
self.validate_one_root()
self.delete_child_item_groups_key()
@ -67,10 +66,6 @@ class ItemGroup(NestedSet, WebsiteGenerator):
WebsiteGenerator.on_trash(self)
self.delete_child_item_groups_key()
def validate_name_with_item(self):
if frappe.db.exists("Item", self.name):
frappe.throw(frappe._("An item exists with same name ({0}), please change the item group name or rename the item").format(self.name), frappe.NameError)
def get_context(self, context):
context.show_search=True
context.page_length = cint(frappe.db.get_single_value('Products Settings', 'products_per_page')) or 6

4
erpnext/setup/doctype/naming_series/naming_series.py

@ -180,11 +180,11 @@ class NamingSeries(Document):
prefix = parse_naming_series(parts)
return prefix
def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True):
def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True, make_mandatory=1):
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
if naming_series:
make_property_setter(doctype, "naming_series", "hidden", 0, "Check", validate_fields_for_doctype=False)
make_property_setter(doctype, "naming_series", "reqd", 1, "Check", validate_fields_for_doctype=False)
make_property_setter(doctype, "naming_series", "reqd", make_mandatory, "Check", validate_fields_for_doctype=False)
# set values for mandatory
try:

7
erpnext/stock/doctype/item/item.py

@ -152,7 +152,6 @@ class Item(WebsiteGenerator):
def on_update(self):
invalidate_cache_for_item(self)
self.validate_name_with_item_group()
self.update_variants()
self.update_item_price()
self.update_template_item()
@ -628,12 +627,6 @@ class Item(WebsiteGenerator):
where item_code = %s and is_cancelled = 0 limit 1""", self.name))
return self._stock_ledger_created
def validate_name_with_item_group(self):
# causes problem with tree build
if frappe.db.exists("Item Group", self.name):
frappe.throw(
_("An Item Group exists with same name, please change the item name or rename the item group"))
def update_item_price(self):
frappe.db.sql("""
UPDATE `tabItem Price`

2
erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.js

@ -35,7 +35,7 @@ erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.
refresh() {
var help_content =
`<br><br>
<table class="table table-bordered" style="background-color: #f9f9f9;">
<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
<tr><td>
<h4>
<i class="fa fa-hand-right"></i>

553
erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py

@ -10,6 +10,7 @@ from frappe.utils import add_days, cint, cstr, flt, today
import erpnext
from erpnext.accounts.doctype.account.test_account import get_inventory_account
from erpnext.controllers.buying_controller import QtyMismatchError
from erpnext.stock.doctype.item.test_item import create_item, make_item
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
from erpnext.stock.doctype.serial_no.serial_no import SerialNoDuplicateError, get_serial_nos
@ -22,20 +23,54 @@ class TestPurchaseReceipt(ERPNextTestCase):
def setUp(self):
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
def test_purchase_receipt_received_qty(self):
"""
1. Test if received qty is validated against accepted + rejected
2. Test if received qty is auto set on save
"""
pr = make_purchase_receipt(
qty=1,
rejected_qty=1,
received_qty=3,
item_code="_Test Item Home Desktop 200",
do_not_save=True
)
self.assertRaises(QtyMismatchError, pr.save)
pr.items[0].received_qty = 0
pr.save()
self.assertEqual(pr.items[0].received_qty, 2)
# teardown
pr.delete()
def test_reverse_purchase_receipt_sle(self):
pr = make_purchase_receipt(qty=0.5, item_code="_Test Item Home Desktop 200")
sl_entry = frappe.db.get_all("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
"voucher_no": pr.name}, ['actual_qty'])
sl_entry = frappe.db.get_all(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name
},
['actual_qty']
)
self.assertEqual(len(sl_entry), 1)
self.assertEqual(sl_entry[0].actual_qty, 0.5)
pr.cancel()
sl_entry_cancelled = frappe.db.get_all("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
"voucher_no": pr.name}, ['actual_qty'], order_by='creation')
sl_entry_cancelled = frappe.db.get_all(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name
},
['actual_qty'],
order_by='creation'
)
self.assertEqual(len(sl_entry_cancelled), 2)
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
@ -61,8 +96,15 @@ class TestPurchaseReceipt(ERPNextTestCase):
}]
}).insert()
template = frappe.db.get_value('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice')
old_template_in_supplier = frappe.db.get_value("Supplier", "_Test Supplier", "payment_terms")
template = frappe.db.get_value(
"Payment Terms Template",
"_Test Payment Terms Template For Purchase Invoice"
)
old_template_in_supplier = frappe.db.get_value(
"Supplier",
"_Test Supplier",
"payment_terms"
)
frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", template)
pr = make_purchase_receipt(do_not_save=True)
@ -88,30 +130,59 @@ class TestPurchaseReceipt(ERPNextTestCase):
# teardown
pi.delete() # draft PI
pr.cancel()
frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", old_template_in_supplier)
frappe.get_doc('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice').delete()
frappe.db.set_value(
"Supplier",
"_Test Supplier",
"payment_terms",
old_template_in_supplier
)
frappe.get_doc(
"Payment Terms Template",
"_Test Payment Terms Template For Purchase Invoice"
).delete()
def test_purchase_receipt_no_gl_entry(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company')
existing_bin_qty, existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
"warehouse": "_Test Warehouse - _TC"}, ["actual_qty", "stock_value"])
existing_bin_qty, existing_bin_stock_value = frappe.db.get_value(
"Bin",
{
"item_code": "_Test Item",
"warehouse": "_Test Warehouse - _TC"
},
["actual_qty", "stock_value"]
)
if existing_bin_qty < 0:
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=abs(existing_bin_qty))
make_stock_entry(
item_code="_Test Item",
target="_Test Warehouse - _TC",
qty=abs(existing_bin_qty)
)
pr = make_purchase_receipt()
stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
{"voucher_type": "Purchase Receipt", "voucher_no": pr.name,
"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, "stock_value_difference")
stock_value_difference = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name,
"item_code": "_Test Item",
"warehouse": "_Test Warehouse - _TC"
},
"stock_value_difference"
)
self.assertEqual(stock_value_difference, 250)
current_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
"warehouse": "_Test Warehouse - _TC"}, "stock_value")
current_bin_stock_value = frappe.db.get_value(
"Bin",
{
"item_code": "_Test Item",
"warehouse": "_Test Warehouse - _TC"
},
"stock_value"
)
self.assertEqual(current_bin_stock_value, existing_bin_stock_value + 250)
self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))
@ -133,13 +204,17 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr = make_purchase_receipt(item_code=item.name, qty=5, rate=500)
self.assertTrue(frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name}))
self.assertTrue(
frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name})
)
pr.load_from_db()
batch_no = pr.items[0].batch_no
pr.cancel()
self.assertFalse(frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name}))
self.assertFalse(
frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name})
)
self.assertFalse(frappe.db.get_all('Serial No', {'batch_no': batch_no}))
def test_duplicate_serial_nos(self):
@ -158,42 +233,78 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr = make_purchase_receipt(item_code=item.name, qty=2, rate=500)
pr.load_from_db()
serial_nos = frappe.db.get_value('Stock Ledger Entry',
{'voucher_type': 'Purchase Receipt', 'voucher_no': pr.name, 'item_code': item.name}, 'serial_no')
serial_nos = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": pr.name,
"item_code": item.name
},
"serial_no"
)
serial_nos = get_serial_nos(serial_nos)
self.assertEquals(get_serial_nos(pr.items[0].serial_no), serial_nos)
# Then tried to receive same serial nos in difference company
pr_different_company = make_purchase_receipt(item_code=item.name, qty=2, rate=500,
serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True,
warehouse = 'Stores - _TC1')
pr_different_company = make_purchase_receipt(
item_code=item.name,
qty=2,
rate=500,
serial_no='\n'.join(serial_nos),
company='_Test Company 1',
do_not_submit=True,
warehouse = 'Stores - _TC1'
)
self.assertRaises(SerialNoDuplicateError, pr_different_company.submit)
# Then made delivery note to remove the serial nos from stock
dn = create_delivery_note(item_code=item.name, qty=2, rate = 1500, serial_no='\n'.join(serial_nos))
dn = create_delivery_note(
item_code=item.name,
qty=2,
rate=1500,
serial_no='\n'.join(serial_nos)
)
dn.load_from_db()
self.assertEquals(get_serial_nos(dn.items[0].serial_no), serial_nos)
posting_date = add_days(today(), -3)
# Try to receive same serial nos again in the same company with backdated.
pr1 = make_purchase_receipt(item_code=item.name, qty=2, rate=500,
posting_date=posting_date, serial_no='\n'.join(serial_nos), do_not_submit=True)
pr1 = make_purchase_receipt(
item_code=item.name,
qty=2,
rate=500,
posting_date=posting_date,
serial_no='\n'.join(serial_nos),
do_not_submit=True
)
self.assertRaises(SerialNoExistsInFutureTransaction, pr1.submit)
# Try to receive same serial nos with different company with backdated.
pr2 = make_purchase_receipt(item_code=item.name, qty=2, rate=500,
posting_date=posting_date, serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True,
warehouse = 'Stores - _TC1')
pr2 = make_purchase_receipt(
item_code=item.name,
qty=2,
rate=500,
posting_date=posting_date,
serial_no='\n'.join(serial_nos),
company="_Test Company 1",
do_not_submit=True,
warehouse="Stores - _TC1"
)
self.assertRaises(SerialNoExistsInFutureTransaction, pr2.submit)
# Receive the same serial nos after the delivery note posting date and time
make_purchase_receipt(item_code=item.name, qty=2, rate=500, serial_no='\n'.join(serial_nos))
make_purchase_receipt(
item_code=item.name,
qty=2,
rate=500,
serial_no='\n'.join(serial_nos)
)
# Raise the error for backdated deliver note entry cancel
self.assertRaises(SerialNoExistsInFutureTransaction, dn.cancel)
@ -236,11 +347,23 @@ class TestPurchaseReceipt(ERPNextTestCase):
def test_subcontracting(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM")
make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100)
make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC",
qty=100, basic_rate=100)
pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=500, is_subcontracted="Yes")
frappe.db.set_value(
"Buying Settings", None,
"backflush_raw_materials_of_subcontract_based_on", "BOM"
)
make_stock_entry(
item_code="_Test Item", qty=100,
target="_Test Warehouse 1 - _TC", basic_rate=100
)
make_stock_entry(
item_code="_Test Item Home Desktop 100", qty=100,
target="_Test Warehouse 1 - _TC", basic_rate=100
)
pr = make_purchase_receipt(
item_code="_Test FG Item", qty=10,
rate=500, is_subcontracted="Yes"
)
self.assertEqual(len(pr.get("supplied_items")), 2)
rm_supp_cost = sum(d.amount for d in pr.get("supplied_items"))
@ -250,17 +373,33 @@ class TestPurchaseReceipt(ERPNextTestCase):
def test_subcontracting_gle_fg_item_rate_zero(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM")
frappe.db.set_value(
"Buying Settings", None,
"backflush_raw_materials_of_subcontract_based_on", "BOM"
)
se1 = make_stock_entry(item_code="_Test Item", target="Work In Progress - TCP1",
qty=100, basic_rate=100, company="_Test Company with perpetual inventory")
se1 = make_stock_entry(
item_code="_Test Item",
target="Work In Progress - TCP1",
qty=100, basic_rate=100,
company="_Test Company with perpetual inventory"
)
se2 = make_stock_entry(item_code="_Test Item Home Desktop 100", target="Work In Progress - TCP1",
qty=100, basic_rate=100, company="_Test Company with perpetual inventory")
se2 = make_stock_entry(
item_code="_Test Item Home Desktop 100",
target="Work In Progress - TCP1",
qty=100, basic_rate=100,
company="_Test Company with perpetual inventory"
)
pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=0, is_subcontracted="Yes",
company="_Test Company with perpetual inventory", warehouse='Stores - TCP1',
supplier_warehouse='Work In Progress - TCP1')
pr = make_purchase_receipt(
item_code="_Test FG Item",
qty=10, rate=0,
is_subcontracted="Yes",
company="_Test Company with perpetual inventory",
warehouse="Stores - TCP1",
supplier_warehouse="Work In Progress - TCP1"
)
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
@ -294,13 +433,23 @@ class TestPurchaseReceipt(ERPNextTestCase):
po = create_purchase_order(item_code=item_code, qty=1, include_exploded_items=0,
is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC")
#stock raw materials in a warehouse before transfer
se1 = make_stock_entry(target="_Test Warehouse - _TC",
item_code = "Test Extra Item 1", qty=10, basic_rate=100)
se2 = make_stock_entry(target="_Test Warehouse - _TC",
item_code = "_Test FG Item", qty=1, basic_rate=100)
se3 = make_stock_entry(target="_Test Warehouse - _TC",
item_code = "Test Extra Item 2", qty=1, basic_rate=100)
# stock raw materials in a warehouse before transfer
make_stock_entry(
target="_Test Warehouse - _TC",
item_code = "Test Extra Item 1",
qty=10, basic_rate=100
)
make_stock_entry(
target="_Test Warehouse - _TC",
item_code = "_Test FG Item",
qty=1, basic_rate=100
)
make_stock_entry(
target="_Test Warehouse - _TC",
item_code = "Test Extra Item 2",
qty=1, basic_rate=100
)
rm_items = [
{
"item_code": item_code,
@ -334,11 +483,17 @@ class TestPurchaseReceipt(ERPNextTestCase):
def test_serial_no_supplier(self):
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
self.assertEqual(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"),
pr.supplier)
pr_row_1_serial_no = pr.get("items")[0].serial_no
self.assertEqual(
frappe.db.get_value("Serial No", pr_row_1_serial_no, "supplier"),
pr.supplier
)
pr.cancel()
self.assertFalse(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "warehouse"))
self.assertFalse(
frappe.db.get_value("Serial No", pr_row_1_serial_no, "warehouse")
)
def test_rejected_serial_no(self):
pr = frappe.copy_doc(test_records[0])
@ -365,18 +520,33 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr.cancel()
def test_purchase_return_partial(self):
pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1"
)
return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
is_return=1, return_against=pr.name, qty=-2, do_not_submit=1)
return_pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1",
is_return=1,
return_against=pr.name,
qty=-2,
do_not_submit=1
)
return_pr.items[0].purchase_receipt_item = pr.items[0].name
return_pr.submit()
# check sle
outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
"voucher_no": return_pr.name}, "outgoing_rate")
outgoing_rate = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": return_pr.name
},
"outgoing_rate"
)
self.assertEqual(outgoing_rate, 50)
@ -440,11 +610,21 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr.cancel()
def test_purchase_return_full(self):
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1")
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1"
)
return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, qty=-5, do_not_submit=1)
return_pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1",
is_return=1,
return_against=pr.name,
qty=-5,
do_not_submit=1
)
return_pr.items[0].purchase_receipt_item = pr.items[0].name
return_pr.submit()
@ -466,15 +646,41 @@ class TestPurchaseReceipt(ERPNextTestCase):
rejected_warehouse="_Test Rejected Warehouse - TCP1"
if not frappe.db.exists("Warehouse", rejected_warehouse):
get_warehouse(company = "_Test Company with perpetual inventory",
abbr = " - TCP1", warehouse_name = "_Test Rejected Warehouse").name
get_warehouse(
company = "_Test Company with perpetual inventory",
abbr = " - TCP1",
warehouse_name = "_Test Rejected Warehouse"
).name
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", received_qty=4, qty=2, rejected_warehouse=rejected_warehouse)
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1",
qty=2,
rejected_qty=2,
rejected_warehouse=rejected_warehouse
)
return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, received_qty = -4, qty=-2, rejected_warehouse=rejected_warehouse)
return_pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1",
is_return=1,
return_against=pr.name,
qty=-2,
rejected_qty = -2,
rejected_warehouse=rejected_warehouse
)
actual_qty = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
"voucher_no": return_pr.name, 'warehouse': return_pr.items[0].rejected_warehouse}, "actual_qty")
actual_qty = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": "Purchase Receipt",
"voucher_no": return_pr.name,
"warehouse": return_pr.items[0].rejected_warehouse
},
"actual_qty"
)
self.assertEqual(actual_qty, -2)
@ -499,8 +705,13 @@ class TestPurchaseReceipt(ERPNextTestCase):
"purchase_document_no": pr.name
})
return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1,
is_return=1, return_against=pr.name, serial_no=serial_no)
return_pr = make_purchase_receipt(
item_code="_Test Serialized Item With Series",
qty=-1,
is_return=1,
return_against=pr.name,
serial_no=serial_no
)
_check_serial_no_values(serial_no, {
"warehouse": "",
@ -522,9 +733,21 @@ class TestPurchaseReceipt(ERPNextTestCase):
})
row.db_update()
pr = make_purchase_receipt(item_code=item_code, qty=1, uom="Box", conversion_factor=1.0)
return_pr = make_purchase_receipt(item_code=item_code, qty=-10, uom="Unit",
stock_uom="Box", conversion_factor=0.1, is_return=1, return_against=pr.name)
pr = make_purchase_receipt(
item_code=item_code,
qty=1,
uom="Box",
conversion_factor=1.0
)
return_pr = make_purchase_receipt(
item_code=item_code,
qty=-10,
uom="Unit",
stock_uom="Box",
conversion_factor=0.1,
is_return=1,
return_against=pr.name
)
self.assertEqual(abs(return_pr.items[0].stock_qty), 1.0)
@ -540,13 +763,19 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr.submit()
update_purchase_receipt_status(pr.name, "Closed")
self.assertEqual(frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed")
self.assertEqual(
frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed"
)
pr.reload()
pr.cancel()
def test_pr_billing_status(self):
# PO -> PR1 -> PI and PO -> PI and PO -> PR2
"""Flow:
1. PO -> PR1 -> PI
2. PO -> PI
3. PO -> PR2.
"""
from erpnext.buying.doctype.purchase_order.purchase_order import (
make_purchase_invoice as make_purchase_invoice_from_po,
)
@ -610,21 +839,39 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr_doc = make_purchase_receipt(item_code=item_code,
qty=1, serial_no = serial_no)
self.assertEqual(serial_no, frappe.db.get_value("Serial No",
{"purchase_document_type": "Purchase Receipt", "purchase_document_no": pr_doc.name}, "name"))
self.assertEqual(
serial_no,
frappe.db.get_value(
"Serial No",
{
"purchase_document_type": "Purchase Receipt",
"purchase_document_no": pr_doc.name
},
"name"
)
)
pr_doc.cancel()
#check for the auto created serial nos
# check for the auto created serial nos
item_code = "Test Auto Created Serial No"
if not frappe.db.exists("Item", item_code):
item = make_item(item_code, dict(has_serial_no=1, serial_no_series="KLJL.###"))
make_item(item_code, dict(has_serial_no=1, serial_no_series="KLJL.###"))
new_pr_doc = make_purchase_receipt(item_code=item_code, qty=1)
serial_no = get_serial_nos(new_pr_doc.items[0].serial_no)[0]
self.assertEqual(serial_no, frappe.db.get_value("Serial No",
{"purchase_document_type": "Purchase Receipt", "purchase_document_no": new_pr_doc.name}, "name"))
self.assertEqual(
serial_no,
frappe.db.get_value(
"Serial No",
{
"purchase_document_type": "Purchase Receipt",
"purchase_document_no": new_pr_doc.name
},
"name"
)
)
new_pr_doc.cancel()
@ -700,8 +947,12 @@ class TestPurchaseReceipt(ERPNextTestCase):
def test_purchase_receipt_cost_center(self):
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
cost_center = "_Test Cost Center for BS Account - TCP1"
create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company with perpetual inventory")
create_cost_center(
cost_center_name="_Test Cost Center for BS Account",
company="_Test Company with perpetual inventory"
)
if not frappe.db.exists('Location', 'Test Location'):
frappe.get_doc({
@ -709,10 +960,16 @@ class TestPurchaseReceipt(ERPNextTestCase):
'location_name': 'Test Location'
}).insert()
pr = make_purchase_receipt(cost_center=cost_center, company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
pr = make_purchase_receipt(
cost_center=cost_center,
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1"
)
stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
stock_in_hand_account = get_inventory_account(
pr.company, pr.get("items")[0].warehouse
)
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
self.assertTrue(gl_entries)
@ -736,9 +993,16 @@ class TestPurchaseReceipt(ERPNextTestCase):
'doctype': 'Location',
'location_name': 'Test Location'
}).insert()
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
supplier_warehouse = "Work in Progress - TCP1"
)
stock_in_hand_account = get_inventory_account(
pr.company, pr.get("items")[0].warehouse
)
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
self.assertTrue(gl_entries)
@ -766,7 +1030,11 @@ class TestPurchaseReceipt(ERPNextTestCase):
po = create_purchase_order()
pr = create_pr_against_po(po.name)
pr1 = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-1, do_not_submit=True)
pr1 = make_purchase_receipt(
qty=-1,
is_return=1, return_against=pr.name,
do_not_submit=True
)
pr1.items[0].purchase_order = po.name
pr1.items[0].purchase_order_item = po.items[0].name
pr1.items[0].purchase_receipt_item = pr.items[0].name
@ -799,7 +1067,11 @@ class TestPurchaseReceipt(ERPNextTestCase):
pi1.save()
pi1.submit()
pr2 = make_purchase_receipt(is_return=1, return_against=pr1.name, qty=-2, do_not_submit=True)
pr2 = make_purchase_receipt(
qty=-2,
is_return=1, return_against=pr1.name,
do_not_submit=True
)
pr2.items[0].purchase_receipt_item = pr1.items[0].name
pr2.submit()
@ -841,14 +1113,22 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr1.cancel()
def test_stock_transfer_from_purchase_receipt_with_valuation(self):
create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory",
properties={"account": '_Test Account Stock In Hand - TCP1'})
create_warehouse(
"_Test Warehouse for Valuation",
company="_Test Company with perpetual inventory",
properties={"account": '_Test Account Stock In Hand - TCP1'}
)
pr1 = make_purchase_receipt(warehouse = '_Test Warehouse for Valuation - TCP1',
company="_Test Company with perpetual inventory")
pr1 = make_purchase_receipt(
warehouse = '_Test Warehouse for Valuation - TCP1',
company="_Test Company with perpetual inventory"
)
pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", do_not_save=1)
pr = make_purchase_receipt(
company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1",
do_not_save=1
)
pr.items[0].from_warehouse = '_Test Warehouse for Valuation - TCP1'
pr.supplier_warehouse = ''
@ -930,10 +1210,24 @@ class TestPurchaseReceipt(ERPNextTestCase):
}
rm_items = [
{"item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 3","item_name":"_Test Item",
"qty":300,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[0].name},
{"item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 3","item_name":"_Test Item",
"qty":200,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[0].name}
{
"item_code":item_code,
"rm_item_code":"Sub Contracted Raw Material 3",
"item_name":"_Test Item",
"qty":300,
"warehouse":"_Test Warehouse - _TC",
"stock_uom":"Nos",
"name": po.supplied_items[0].name
},
{
"item_code":item_code,
"rm_item_code":"Sub Contracted Raw Material 3",
"item_name":"_Test Item",
"qty":200,
"warehouse":"_Test Warehouse - _TC",
"stock_uom":"Nos",
"name": po.supplied_items[0].name
}
]
rm_item_string = json.dumps(rm_items)
@ -943,8 +1237,14 @@ class TestPurchaseReceipt(ERPNextTestCase):
se.items[1].batch_no = ste2.items[0].batch_no
se.submit()
supplied_qty = frappe.db.get_value("Purchase Order Item Supplied",
{"parent": po.name, "rm_item_code": "Sub Contracted Raw Material 3"}, "supplied_qty")
supplied_qty = frappe.db.get_value(
"Purchase Order Item Supplied",
{
"parent": po.name,
"rm_item_code": "Sub Contracted Raw Material 3"
},
"supplied_qty"
)
self.assertEqual(supplied_qty, 500.00)
@ -1016,10 +1316,18 @@ class TestPurchaseReceipt(ERPNextTestCase):
company = '_Test Company with perpetual inventory'
service_item = '_Test Non Stock Item'
before_test_value = frappe.db.get_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items')
frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', 1)
before_test_value = frappe.db.get_value(
'Company', company, 'enable_perpetual_inventory_for_non_stock_items'
)
frappe.db.set_value(
'Company', company,
'enable_perpetual_inventory_for_non_stock_items', 1
)
srbnb_account = 'Stock Received But Not Billed - TCP1'
frappe.db.set_value('Company', company, 'service_received_but_not_billed', srbnb_account)
frappe.db.set_value(
'Company', company,
'service_received_but_not_billed', srbnb_account
)
pr = make_purchase_receipt(
company=company, item=service_item,
@ -1051,7 +1359,10 @@ class TestPurchaseReceipt(ERPNextTestCase):
self.assertEqual(len(item_one_gl_entry), 1)
self.assertEqual(len(item_two_gl_entry), 1)
frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value)
frappe.db.set_value(
'Company', company,
'enable_perpetual_inventory_for_non_stock_items', before_test_value
)
def test_purchase_receipt_with_exchange_rate_difference(self):
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import (
@ -1076,10 +1387,19 @@ class TestPurchaseReceipt(ERPNextTestCase):
pr.submit()
# Get exchnage gain and loss account
exchange_gain_loss_account = frappe.db.get_value('Company', pr.company, 'exchange_gain_loss_account')
exchange_gain_loss_account = frappe.db.get_value(
'Company', pr.company, 'exchange_gain_loss_account'
)
# fetching the latest GL Entry with exchange gain and loss account account
amount = frappe.db.get_value('GL Entry', {'account': exchange_gain_loss_account, 'voucher_no': pr.name}, 'credit')
amount = frappe.db.get_value(
'GL Entry',
{
'account': exchange_gain_loss_account,
'voucher_no': pr.name
},
'credit'
)
discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount)
self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount)
@ -1225,8 +1545,8 @@ def make_purchase_receipt(**args):
pr.return_against = args.return_against
pr.apply_putaway_rule = args.apply_putaway_rule
qty = args.qty or 5
received_qty = args.received_qty or qty
rejected_qty = args.rejected_qty or flt(received_qty) - flt(qty)
rejected_qty = args.rejected_qty or 0
received_qty = args.received_qty or flt(rejected_qty) + flt(qty)
item_code = args.item or args.item_code or "_Test Item"
uom = args.uom or frappe.db.get_value("Item", item_code, "stock_uom") or "_Test UOM"
@ -1249,9 +1569,12 @@ def make_purchase_receipt(**args):
if args.get_multiple_items:
pr.items = []
for item in get_items(warehouse= args.warehouse, cost_center = args.cost_center or frappe.get_cached_value('Company', pr.company, 'cost_center')):
pr.append("items", item)
company_cost_center = frappe.get_cached_value('Company', pr.company, 'cost_center')
cost_center = args.cost_center or company_cost_center
for item in get_items(warehouse=args.warehouse, cost_center=cost_center):
pr.append("items", item)
if args.get_taxes_and_charges:
for tax in get_taxes():

14
erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json

@ -197,6 +197,7 @@
},
{
"bold": 1,
"default": "0",
"fieldname": "received_qty",
"fieldtype": "Float",
"label": "Received Quantity",
@ -204,6 +205,7 @@
"oldfieldtype": "Currency",
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 1,
"width": "100px"
},
@ -219,8 +221,10 @@
"width": "100px"
},
{
"columns": 1,
"fieldname": "rejected_qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Rejected Quantity",
"oldfieldname": "rejected_qty",
"oldfieldtype": "Currency",
@ -327,7 +331,7 @@
},
{
"bold": 1,
"columns": 3,
"columns": 2,
"fieldname": "rate",
"fieldtype": "Currency",
"in_list_view": 1,
@ -543,6 +547,7 @@
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Accepted Qty in Stock UOM",
"no_copy": 1,
"oldfieldname": "stock_qty",
"oldfieldtype": "Currency",
"print_hide": 1,
@ -882,7 +887,9 @@
"fieldname": "received_stock_qty",
"fieldtype": "Float",
"label": "Received Qty in Stock UOM",
"print_hide": 1
"no_copy": 1,
"print_hide": 1,
"read_only": 1
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
@ -969,10 +976,11 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2021-09-01 16:02:40.338597",
"modified": "2021-11-15 15:46:10.591600",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt Item",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,

2
erpnext/stock/doctype/serial_no/serial_no.py

@ -342,7 +342,7 @@ def check_serial_no_validity_on_cancel(serial_no, sle):
is_stock_reco = sle.voucher_type == "Stock Reconciliation"
msg = None
if sr and (actual_qty < 0 or is_stock_reco) and sr.warehouse != sle.warehouse:
if sr and (actual_qty < 0 or is_stock_reco) and (sr.warehouse and sr.warehouse != sle.warehouse):
# receipt(inward) is being cancelled
msg = _("Cannot cancel {0} {1} as Serial No {2} does not belong to the warehouse {3}").format(
sle.voucher_type, doc_link, sr_link, frappe.bold(sle.warehouse))

28
erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py

@ -399,6 +399,34 @@ class TestStockReconciliation(ERPNextTestCase):
, do_not_submit=True)
self.assertRaises(frappe.ValidationError, sr.submit)
def test_serial_no_cancellation(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
item = create_item("Stock-Reco-Serial-Item-9", is_stock_item=1)
if not item.has_serial_no:
item.has_serial_no = 1
item.serial_no_series = "SRS9.####"
item.save()
item_code = item.name
warehouse = "_Test Warehouse - _TC"
se1 = make_stock_entry(item_code=item_code, target=warehouse, qty=10, basic_rate=700)
serial_nos = get_serial_nos(se1.items[0].serial_no)
# reduce 1 item
serial_nos.pop()
new_serial_nos = "\n".join(serial_nos)
sr = create_stock_reconciliation(item_code=item.name, warehouse=warehouse, serial_no=new_serial_nos, qty=9)
sr.cancel()
active_sr_no = frappe.get_all("Serial No",
filters={"item_code": item_code, "warehouse": warehouse, "status": "Active"})
self.assertEqual(len(active_sr_no), 10)
def create_batch_item_with_batch(item_name, batch_id):
batch_item_doc = create_item(item_name, is_stock_item=1)
if not batch_item_doc.has_batch_no:

2
erpnext/stock/doctype/stock_settings/stock_settings.py

@ -20,7 +20,7 @@ class StockSettings(Document):
from erpnext.setup.doctype.naming_series.naming_series import set_by_naming_series
set_by_naming_series("Item", "item_code",
self.get("item_naming_by")=="Naming Series", hide_name_field=True)
self.get("item_naming_by")=="Naming Series", hide_name_field=True, make_mandatory=0)
stock_frozen_limit = 356
submitted_stock_frozen = self.stock_frozen_upto_days or 0

Loading…
Cancel
Save