mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 09:54:47 +00:00
Merge branch 'develop' into se-required-items-from-jc
This commit is contained in:
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -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. **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. **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. **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
|
### Feature Request Guidelines
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
[](https://github.com/frappe/erpnext/actions/workflows/server-tests.yml)
|
[](https://github.com/frappe/erpnext/actions/workflows/server-tests.yml)
|
||||||
[](https://www.codetriage.com/frappe/erpnext)
|
[](https://www.codetriage.com/frappe/erpnext)
|
||||||
[](https://codecov.io/gh/frappe/erpnext)
|
[](https://codecov.io/gh/frappe/erpnext)
|
||||||
|
[](https://hub.docker.com/r/frappe/erpnext-worker)
|
||||||
|
|
||||||
[https://erpnext.com](https://erpnext.com)
|
[https://erpnext.com](https://erpnext.com)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ frappe.ui.form.on('Accounting Dimension Filter', {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let help_content =
|
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>
|
<tr><td>
|
||||||
<p>
|
<p>
|
||||||
<i class="fa fa-hand-right"></i>
|
<i class="fa fa-hand-right"></i>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ frappe.provide("erpnext.accounts.dimensions");
|
|||||||
frappe.ui.form.on('Loyalty Program', {
|
frappe.ui.form.on('Loyalty Program', {
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
var help_content =
|
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>
|
<tr><td>
|
||||||
<h4>
|
<h4>
|
||||||
<i class="fa fa-hand-right"></i>
|
<i class="fa fa-hand-right"></i>
|
||||||
|
|||||||
@@ -110,9 +110,15 @@ class POSInvoiceMergeLog(Document):
|
|||||||
|
|
||||||
def merge_pos_invoice_into(self, invoice, data):
|
def merge_pos_invoice_into(self, invoice, data):
|
||||||
items, payments, taxes = [], [], []
|
items, payments, taxes = [], [], []
|
||||||
|
|
||||||
loyalty_amount_sum, loyalty_points_sum = 0, 0
|
loyalty_amount_sum, loyalty_points_sum = 0, 0
|
||||||
|
|
||||||
rounding_adjustment, base_rounding_adjustment = 0, 0
|
rounding_adjustment, base_rounding_adjustment = 0, 0
|
||||||
rounded_total, base_rounded_total = 0, 0
|
rounded_total, base_rounded_total = 0, 0
|
||||||
|
|
||||||
|
loyalty_amount_sum, loyalty_points_sum, idx = 0, 0, 1
|
||||||
|
|
||||||
|
|
||||||
for doc in data:
|
for doc in data:
|
||||||
map_doc(doc, invoice, table_map={ "doctype": invoice.doctype })
|
map_doc(doc, invoice, table_map={ "doctype": invoice.doctype })
|
||||||
|
|
||||||
@@ -146,6 +152,8 @@ class POSInvoiceMergeLog(Document):
|
|||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
tax.charge_type = 'Actual'
|
tax.charge_type = 'Actual'
|
||||||
|
tax.idx = idx
|
||||||
|
idx += 1
|
||||||
tax.included_in_print_rate = 0
|
tax.included_in_print_rate = 0
|
||||||
tax.tax_amount = tax.tax_amount_after_discount_amount
|
tax.tax_amount = tax.tax_amount_after_discount_amount
|
||||||
tax.base_tax_amount = tax.base_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)
|
payments.append(payment)
|
||||||
rounding_adjustment += doc.rounding_adjustment
|
rounding_adjustment += doc.rounding_adjustment
|
||||||
rounded_total += doc.rounded_total
|
rounded_total += doc.rounded_total
|
||||||
base_rounding_adjustment += doc.rounding_adjustment
|
base_rounding_adjustment += doc.base_rounding_adjustment
|
||||||
base_rounded_total += doc.rounded_total
|
base_rounded_total += doc.base_rounded_total
|
||||||
|
|
||||||
|
|
||||||
if loyalty_points_sum:
|
if loyalty_points_sum:
|
||||||
@@ -176,9 +184,9 @@ class POSInvoiceMergeLog(Document):
|
|||||||
invoice.set('payments', payments)
|
invoice.set('payments', payments)
|
||||||
invoice.set('taxes', taxes)
|
invoice.set('taxes', taxes)
|
||||||
invoice.set('rounding_adjustment',rounding_adjustment)
|
invoice.set('rounding_adjustment',rounding_adjustment)
|
||||||
invoice.set('rounding_adjustment',base_rounding_adjustment)
|
invoice.set('base_rounding_adjustment',base_rounding_adjustment)
|
||||||
invoice.set('base_rounded_total',base_rounded_total)
|
|
||||||
invoice.set('rounded_total',rounded_total)
|
invoice.set('rounded_total',rounded_total)
|
||||||
|
invoice.set('base_rounded_total',base_rounded_total)
|
||||||
invoice.additional_discount_percentage = 0
|
invoice.additional_discount_percentage = 0
|
||||||
invoice.discount_amount = 0.0
|
invoice.discount_amount = 0.0
|
||||||
invoice.taxes_and_charges = None
|
invoice.taxes_and_charges = None
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ frappe.ui.form.on('Pricing Rule', {
|
|||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
var help_content =
|
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>
|
<tr><td>
|
||||||
<h4>
|
<h4>
|
||||||
<i class="fa fa-hand-right"></i>
|
<i class="fa fa-hand-right"></i>
|
||||||
|
|||||||
@@ -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',
|
product_discount_fields = ['free_item', 'free_qty', 'free_item_uom',
|
||||||
'free_item_rate', 'same_item', 'is_recursive', 'apply_multiple_pricing_rules']
|
'free_item_rate', 'same_item', 'is_recursive', 'apply_multiple_pricing_rules']
|
||||||
|
|
||||||
|
class TransactionExists(frappe.ValidationError):
|
||||||
|
pass
|
||||||
|
|
||||||
class PromotionalScheme(Document):
|
class PromotionalScheme(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.selling and not self.buying:
|
if not self.selling and not self.buying:
|
||||||
@@ -28,6 +31,40 @@ class PromotionalScheme(Document):
|
|||||||
or self.product_discount_slabs):
|
or self.product_discount_slabs):
|
||||||
frappe.throw(_("Price or product discount slabs are required"))
|
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):
|
def on_update(self):
|
||||||
pricing_rules = frappe.get_all(
|
pricing_rules = frappe.get_all(
|
||||||
'Pricing Rule',
|
'Pricing Rule',
|
||||||
@@ -67,6 +104,13 @@ class PromotionalScheme(Document):
|
|||||||
{'promotional_scheme': self.name}):
|
{'promotional_scheme': self.name}):
|
||||||
frappe.delete_doc('Pricing Rule', rule.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):
|
def get_pricing_rules(doc, rules=None):
|
||||||
if rules is None:
|
if rules is None:
|
||||||
rules = {}
|
rules = {}
|
||||||
@@ -84,45 +128,59 @@ def _get_pricing_rules(doc, child_doc, discount_fields, rules=None):
|
|||||||
new_doc = []
|
new_doc = []
|
||||||
args = get_args_for_pricing_rule(doc)
|
args = get_args_for_pricing_rule(doc)
|
||||||
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
||||||
|
|
||||||
for idx, d in enumerate(doc.get(child_doc)):
|
for idx, d in enumerate(doc.get(child_doc)):
|
||||||
if d.name in rules:
|
if d.name in rules:
|
||||||
for applicable_for_value in args.get(applicable_for):
|
if not args.get(applicable_for):
|
||||||
temp_args = args.copy()
|
docname = get_pricing_rule_docname(d)
|
||||||
docname = frappe.get_all(
|
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields, d, docname)
|
||||||
'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)
|
|
||||||
|
|
||||||
new_doc.append(pr)
|
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 []
|
applicable_for_values = args.get(applicable_for) or []
|
||||||
for applicable_for_value in applicable_for_values:
|
for applicable_for_value in applicable_for_values:
|
||||||
pr = frappe.new_doc("Pricing Rule")
|
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields,
|
||||||
pr.title = doc.name
|
d, applicable_for=applicable_for, value= applicable_for_value)
|
||||||
temp_args = args.copy()
|
|
||||||
temp_args[applicable_for] = applicable_for_value
|
|
||||||
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
|
|
||||||
new_doc.append(pr)
|
new_doc.append(pr)
|
||||||
|
else:
|
||||||
|
pr = prepare_pricing_rule(args, doc, child_doc, discount_fields, d)
|
||||||
|
new_doc.append(pr)
|
||||||
|
|
||||||
return new_doc
|
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):
|
def set_args(args, pr, doc, child_doc, discount_fields, child_doc_fields):
|
||||||
pr.update(args)
|
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),
|
apply_on: d.get(apply_on),
|
||||||
'uom': d.uom
|
'uom': d.uom
|
||||||
})
|
})
|
||||||
|
|
||||||
return pr
|
return pr
|
||||||
|
|
||||||
def get_args_for_pricing_rule(doc):
|
def get_args_for_pricing_rule(doc):
|
||||||
|
|||||||
@@ -5,10 +5,17 @@ import unittest
|
|||||||
|
|
||||||
import frappe
|
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):
|
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):
|
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"],
|
price_rules = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name", "creation"],
|
||||||
filters = {'promotional_scheme': ps.name})
|
filters = {'promotional_scheme': ps.name})
|
||||||
self.assertTrue(len(price_rules),1)
|
self.assertTrue(len(price_rules),1)
|
||||||
@@ -39,22 +46,62 @@ class TestPromotionalScheme(unittest.TestCase):
|
|||||||
filters = {'promotional_scheme': ps.name})
|
filters = {'promotional_scheme': ps.name})
|
||||||
self.assertEqual(price_rules, [])
|
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 = frappe.new_doc('Promotional Scheme')
|
||||||
ps.name = '_Test Scheme'
|
ps.name = '_Test Scheme'
|
||||||
ps.append('items',{
|
ps.append('items',{
|
||||||
'item_code': '_Test Item'
|
'item_code': '_Test Item'
|
||||||
})
|
})
|
||||||
|
|
||||||
ps.selling = 1
|
ps.selling = 1
|
||||||
ps.append('price_discount_slabs',{
|
ps.append('price_discount_slabs',{
|
||||||
'min_qty': 4,
|
'min_qty': 4,
|
||||||
|
'validate_applied_rule': 0,
|
||||||
'discount_percentage': 20,
|
'discount_percentage': 20,
|
||||||
'rule_description': 'Test'
|
'rule_description': 'Test'
|
||||||
})
|
})
|
||||||
ps.applicable_for = 'Customer'
|
|
||||||
ps.append('customer',{
|
ps.company = '_Test Company'
|
||||||
'customer': "_Test Customer"
|
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()
|
ps.save()
|
||||||
|
|
||||||
return ps
|
return ps
|
||||||
|
|||||||
@@ -136,7 +136,7 @@
|
|||||||
"label": "Threshold for Suggestion"
|
"label": "Threshold for Suggestion"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "1",
|
"default": "0",
|
||||||
"fieldname": "validate_applied_rule",
|
"fieldname": "validate_applied_rule",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Validate Applied Rule"
|
"label": "Validate Applied Rule"
|
||||||
@@ -169,7 +169,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-08-19 15:49:29.598727",
|
"modified": "2021-11-16 00:25:33.843996",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Promotional Scheme Price Discount",
|
"name": "Promotional Scheme Price Discount",
|
||||||
|
|||||||
@@ -592,8 +592,17 @@ frappe.ui.form.on("Purchase Invoice", {
|
|||||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||||
|
|
||||||
if (frm.doc.company) {
|
if (frm.doc.company) {
|
||||||
frappe.db.get_value('Company', frm.doc.company, 'default_payable_account', (r) => {
|
frappe.call({
|
||||||
frm.set_value('credit_to', r.default_payable_account);
|
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);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||||
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
|
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
|
||||||
from erpnext.controllers.accounts_controller import get_payment_terms
|
from erpnext.controllers.accounts_controller import get_payment_terms
|
||||||
|
from erpnext.controllers.buying_controller import QtyMismatchError
|
||||||
from erpnext.exceptions import InvalidCurrency
|
from erpnext.exceptions import InvalidCurrency
|
||||||
from erpnext.projects.doctype.project.test_project import make_project
|
from erpnext.projects.doctype.project.test_project import make_project
|
||||||
from erpnext.stock.doctype.item.test_item import create_item
|
from erpnext.stock.doctype.item.test_item import create_item
|
||||||
@@ -35,6 +36,27 @@ class TestPurchaseInvoice(unittest.TestCase):
|
|||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
unlink_payment_on_cancel_of_invoice(0)
|
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):
|
def test_gl_entries_without_perpetual_inventory(self):
|
||||||
frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
|
frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
|
||||||
pi = frappe.copy_doc(test_records[0])
|
pi = frappe.copy_doc(test_records[0])
|
||||||
|
|||||||
@@ -22,10 +22,10 @@
|
|||||||
"received_qty",
|
"received_qty",
|
||||||
"qty",
|
"qty",
|
||||||
"rejected_qty",
|
"rejected_qty",
|
||||||
"stock_uom",
|
|
||||||
"col_break2",
|
"col_break2",
|
||||||
"uom",
|
"uom",
|
||||||
"conversion_factor",
|
"conversion_factor",
|
||||||
|
"stock_uom",
|
||||||
"stock_qty",
|
"stock_qty",
|
||||||
"sec_break1",
|
"sec_break1",
|
||||||
"price_list_rate",
|
"price_list_rate",
|
||||||
@@ -175,7 +175,8 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "received_qty",
|
"fieldname": "received_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Received Qty"
|
"label": "Received Qty",
|
||||||
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bold": 1,
|
"bold": 1,
|
||||||
@@ -223,7 +224,7 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "stock_qty",
|
"fieldname": "stock_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Stock Qty",
|
"label": "Accepted Qty in Stock UOM",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
@@ -870,10 +871,11 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-01 16:04:03.538643",
|
"modified": "2021-11-15 17:04:07.191013",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Purchase Invoice Item",
|
"name": "Purchase Invoice Item",
|
||||||
|
"naming_rule": "Random",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
|
|||||||
@@ -15,8 +15,17 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
|
|||||||
|
|
||||||
let me = this;
|
let me = this;
|
||||||
if (this.frm.doc.company) {
|
if (this.frm.doc.company) {
|
||||||
frappe.db.get_value('Company', this.frm.doc.company, 'default_receivable_account', (r) => {
|
frappe.call({
|
||||||
me.frm.set_value('debit_to', r.default_receivable_account);
|
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);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
|||||||
if party_type=="Customer":
|
if party_type=="Customer":
|
||||||
party_details["sales_team"] = [{
|
party_details["sales_team"] = [{
|
||||||
"sales_person": d.sales_person,
|
"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")]
|
} for d in party.get("sales_team")]
|
||||||
|
|
||||||
# supplier tax withholding category
|
# supplier tax withholding category
|
||||||
@@ -218,7 +219,7 @@ def set_account_and_due_date(party, account, party_type, company, posting_date,
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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`.
|
"""Returns the account for the given `party`.
|
||||||
Will first search in party (Customer / Supplier) record, if not found,
|
Will first search in party (Customer / Supplier) record, if not found,
|
||||||
will search in group (Customer Group / Supplier Group),
|
will search in group (Customer Group / Supplier Group),
|
||||||
@@ -226,8 +227,11 @@ def get_party_account(party_type, party, company=None):
|
|||||||
if not company:
|
if not company:
|
||||||
frappe.throw(_("Please select a Company"))
|
frappe.throw(_("Please select a Company"))
|
||||||
|
|
||||||
if not party:
|
if not party and party_type in ['Customer', 'Supplier']:
|
||||||
return
|
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",
|
account = frappe.db.get_value("Party Account",
|
||||||
{"parenttype": party_type, "parent": party, "company": company}, "account")
|
{"parenttype": party_type, "parent": party, "company": company}, "account")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, _dict
|
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 import get_company_currency, get_default_company
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
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.report.utils import convert_to_presentation_currency, get_currency
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
|
|
||||||
|
# to cache translations
|
||||||
|
TRANSLATIONS = frappe._dict()
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters:
|
if not filters:
|
||||||
@@ -42,10 +44,20 @@ def execute(filters=None):
|
|||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
|
|
||||||
|
update_translations()
|
||||||
|
|
||||||
res = get_result(filters, account_details)
|
res = get_result(filters, account_details)
|
||||||
|
|
||||||
return columns, res
|
return columns, res
|
||||||
|
|
||||||
|
def update_translations():
|
||||||
|
TRANSLATIONS.update(
|
||||||
|
dict(
|
||||||
|
OPENING = _('Opening'),
|
||||||
|
TOTAL = _('Total'),
|
||||||
|
CLOSING_TOTAL = _('Closing (Opening + Total)')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def validate_filters(filters, account_details):
|
def validate_filters(filters, account_details):
|
||||||
if not filters.get("company"):
|
if not filters.get("company"):
|
||||||
@@ -351,9 +363,9 @@ def get_totals_dict():
|
|||||||
credit_in_account_currency=0.0
|
credit_in_account_currency=0.0
|
||||||
)
|
)
|
||||||
return _dict(
|
return _dict(
|
||||||
opening = _get_debit_credit_dict(_('Opening')),
|
opening = _get_debit_credit_dict(TRANSLATIONS.OPENING),
|
||||||
total = _get_debit_credit_dict(_('Total')),
|
total = _get_debit_credit_dict(TRANSLATIONS.TOTAL),
|
||||||
closing = _get_debit_credit_dict(_('Closing (Opening + Total)'))
|
closing = _get_debit_credit_dict(TRANSLATIONS.CLOSING_TOTAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
def group_by_field(group_by):
|
def group_by_field(group_by):
|
||||||
@@ -378,22 +390,23 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
|
|||||||
entries = []
|
entries = []
|
||||||
consolidated_gle = OrderedDict()
|
consolidated_gle = OrderedDict()
|
||||||
group_by = group_by_field(filters.get('group_by'))
|
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'):
|
if filters.get('show_net_values_in_party_account'):
|
||||||
account_type_map = get_account_type_map(filters.get('company'))
|
account_type_map = get_account_type_map(filters.get('company'))
|
||||||
|
|
||||||
def update_value_in_dict(data, key, gle):
|
def update_value_in_dict(data, key, gle):
|
||||||
data[key].debit += flt(gle.debit)
|
data[key].debit += gle.debit
|
||||||
data[key].credit += flt(gle.credit)
|
data[key].credit += gle.credit
|
||||||
|
|
||||||
data[key].debit_in_account_currency += flt(gle.debit_in_account_currency)
|
data[key].debit_in_account_currency += gle.debit_in_account_currency
|
||||||
data[key].credit_in_account_currency += flt(gle.credit_in_account_currency)
|
data[key].credit_in_account_currency += gle.credit_in_account_currency
|
||||||
|
|
||||||
if filters.get('show_net_values_in_party_account') and \
|
if filters.get('show_net_values_in_party_account') and \
|
||||||
account_type_map.get(data[key].account) in ('Receivable', 'Payable'):
|
account_type_map.get(data[key].account) in ('Receivable', 'Payable'):
|
||||||
net_value = flt(data[key].debit) - flt(data[key].credit)
|
net_value = data[key].debit - data[key].credit
|
||||||
net_value_in_account_currency = flt(data[key].debit_in_account_currency) \
|
net_value_in_account_currency = data[key].debit_in_account_currency \
|
||||||
- flt(data[key].credit_in_account_currency)
|
- data[key].credit_in_account_currency
|
||||||
|
|
||||||
if net_value < 0:
|
if net_value < 0:
|
||||||
dr_or_cr = 'credit'
|
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
|
data[key].against_voucher += ', ' + gle.against_voucher
|
||||||
|
|
||||||
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
||||||
for gle in gl_entries:
|
show_opening_entries = filters.get("show_opening_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)
|
|
||||||
|
|
||||||
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing', gle)
|
for gle in gl_entries:
|
||||||
|
group_by_value = gle.get(group_by)
|
||||||
|
|
||||||
|
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)
|
update_value_in_dict(totals, 'closing', gle)
|
||||||
|
|
||||||
elif gle.posting_date <= to_date:
|
elif gle.posting_date <= to_date:
|
||||||
if filters.get("group_by") != 'Group by Voucher (Consolidated)':
|
if not group_by_voucher_consolidated:
|
||||||
gle_map[gle.get(group_by)].entries.append(gle)
|
update_value_in_dict(gle_map[group_by_value].totals, 'total', gle)
|
||||||
elif filters.get("group_by") == 'Group by Voucher (Consolidated)':
|
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")]
|
keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")]
|
||||||
for dim in accounting_dimensions:
|
for dim in accounting_dimensions:
|
||||||
keylist.append(gle.get(dim))
|
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)
|
update_value_in_dict(consolidated_gle, key, gle)
|
||||||
|
|
||||||
for key, value in consolidated_gle.items():
|
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(totals, 'total', value)
|
||||||
update_value_in_dict(gle_map[value.get(group_by)].totals, 'closing', value)
|
|
||||||
update_value_in_dict(totals, 'closing', value)
|
update_value_in_dict(totals, 'closing', value)
|
||||||
entries.append(value)
|
entries.append(value)
|
||||||
|
|
||||||
|
|||||||
@@ -1,184 +1,70 @@
|
|||||||
{
|
{
|
||||||
"allow_copy": 0,
|
"actions": [],
|
||||||
"allow_guest_to_view": 0,
|
"allow_rename": 1,
|
||||||
"allow_import": 0,
|
"autoname": "field:criteria_name",
|
||||||
"allow_rename": 0,
|
"creation": "2017-05-29 01:32:43.064891",
|
||||||
"autoname": "field:criteria_name",
|
"doctype": "DocType",
|
||||||
"beta": 0,
|
"editable_grid": 1,
|
||||||
"creation": "2017-05-29 01:32:43.064891",
|
"engine": "InnoDB",
|
||||||
"custom": 0,
|
"field_order": [
|
||||||
"docstatus": 0,
|
"criteria_name",
|
||||||
"doctype": "DocType",
|
"max_score",
|
||||||
"document_type": "",
|
"formula",
|
||||||
"editable_grid": 1,
|
"weight"
|
||||||
"engine": "InnoDB",
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"fieldname": "criteria_name",
|
||||||
"allow_on_submit": 0,
|
"fieldtype": "Data",
|
||||||
"bold": 0,
|
"label": "Criteria Name",
|
||||||
"collapsible": 0,
|
"reqd": 1,
|
||||||
"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,
|
|
||||||
"unique": 1
|
"unique": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"default": "100",
|
||||||
"allow_on_submit": 0,
|
"fieldname": "max_score",
|
||||||
"bold": 0,
|
"fieldtype": "Float",
|
||||||
"collapsible": 0,
|
"in_list_view": 1,
|
||||||
"columns": 0,
|
"label": "Max Score",
|
||||||
"default": "100",
|
"reqd": 1
|
||||||
"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
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"fieldname": "formula",
|
||||||
"allow_on_submit": 0,
|
"fieldtype": "Small Text",
|
||||||
"bold": 0,
|
"ignore_xss_filter": 1,
|
||||||
"collapsible": 0,
|
"in_list_view": 1,
|
||||||
"columns": 0,
|
"label": "Criteria Formula",
|
||||||
"fieldname": "formula",
|
"reqd": 1
|
||||||
"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
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"fieldname": "weight",
|
||||||
"allow_on_submit": 0,
|
"fieldtype": "Percent",
|
||||||
"bold": 0,
|
"label": "Criteria Weight"
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"has_web_view": 0,
|
"links": [],
|
||||||
"hide_heading": 0,
|
"modified": "2021-11-11 18:34:58.477648",
|
||||||
"hide_toolbar": 0,
|
"modified_by": "Administrator",
|
||||||
"idx": 0,
|
"module": "Buying",
|
||||||
"image_view": 0,
|
"name": "Supplier Scorecard Criteria",
|
||||||
"in_create": 0,
|
"naming_rule": "By fieldname",
|
||||||
"is_submittable": 0,
|
"owner": "Administrator",
|
||||||
"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",
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
"amend": 0,
|
"create": 1,
|
||||||
"apply_user_permissions": 0,
|
"delete": 1,
|
||||||
"cancel": 0,
|
"email": 1,
|
||||||
"create": 1,
|
"export": 1,
|
||||||
"delete": 1,
|
"print": 1,
|
||||||
"email": 1,
|
"read": 1,
|
||||||
"export": 1,
|
"report": 1,
|
||||||
"if_owner": 0,
|
"role": "System Manager",
|
||||||
"import": 0,
|
"share": 1,
|
||||||
"permlevel": 0,
|
|
||||||
"print": 1,
|
|
||||||
"read": 1,
|
|
||||||
"report": 1,
|
|
||||||
"role": "System Manager",
|
|
||||||
"set_user_permissions": 0,
|
|
||||||
"share": 1,
|
|
||||||
"submit": 0,
|
|
||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"read_only": 0,
|
"sort_field": "modified",
|
||||||
"read_only_onload": 0,
|
"sort_order": "DESC",
|
||||||
"show_name_in_global_search": 0,
|
"track_changes": 1
|
||||||
"sort_field": "modified",
|
|
||||||
"sort_order": "DESC",
|
|
||||||
"track_changes": 1,
|
|
||||||
"track_seen": 0
|
|
||||||
}
|
}
|
||||||
@@ -1402,8 +1402,8 @@ class AccountsController(TransactionBase):
|
|||||||
grand_total -= self.get("total_advance")
|
grand_total -= self.get("total_advance")
|
||||||
base_grand_total = flt(grand_total * self.get("conversion_rate"), self.precision("base_grand_total"))
|
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 \
|
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")):
|
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"))
|
frappe.throw(_("Total Payment Amount in Payment Schedule must be equal to Grand / Rounded Total"))
|
||||||
|
|
||||||
def is_rounded_total_disabled(self):
|
def is_rounded_total_disabled(self):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, msgprint
|
from frappe import ValidationError, _, msgprint
|
||||||
from frappe.contacts.doctype.address.address import get_address_display
|
from frappe.contacts.doctype.address.address import get_address_display
|
||||||
from frappe.utils import cint, cstr, flt, getdate
|
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
|
from erpnext.stock.utils import get_incoming_rate
|
||||||
|
|
||||||
|
|
||||||
|
class QtyMismatchError(ValidationError):
|
||||||
|
pass
|
||||||
|
|
||||||
class BuyingController(StockController, Subcontracting):
|
class BuyingController(StockController, Subcontracting):
|
||||||
|
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
@@ -360,19 +363,15 @@ class BuyingController(StockController, Subcontracting):
|
|||||||
def validate_accepted_rejected_qty(self):
|
def validate_accepted_rejected_qty(self):
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
self.validate_negative_quantity(d, ["received_qty","qty", "rejected_qty"])
|
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):
|
if not flt(d.received_qty) and (flt(d.qty) or flt(d.rejected_qty)):
|
||||||
d.qty = flt(d.received_qty) - flt(d.rejected_qty)
|
d.received_qty = flt(d.qty) + flt(d.rejected_qty)
|
||||||
|
|
||||||
elif not flt(d.rejected_qty):
|
|
||||||
d.rejected_qty = flt(d.received_qty) - flt(d.qty)
|
|
||||||
|
|
||||||
val = flt(d.qty) + flt(d.rejected_qty)
|
|
||||||
# Check Received Qty = Accepted Qty + 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"))):
|
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):
|
def validate_negative_quantity(self, item_row, field_list):
|
||||||
if self.is_return:
|
if self.is_return:
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ def verify_request():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if frappe.request.data and \
|
if frappe.request.data and \
|
||||||
frappe.get_request_header("X-Wc-Webhook-Signature") and \
|
not sig == frappe.get_request_header("X-Wc-Webhook-Signature", "").encode():
|
||||||
not sig == bytes(frappe.get_request_header("X-Wc-Webhook-Signature").encode()):
|
|
||||||
frappe.throw(_("Unverified Webhook Data"))
|
frappe.throw(_("Unverified Webhook Data"))
|
||||||
frappe.set_user(woocommerce_settings.creation_user)
|
frappe.set_user(woocommerce_settings.creation_user)
|
||||||
|
|
||||||
|
|||||||
@@ -141,6 +141,9 @@ def verify_transaction(**kwargs):
|
|||||||
transaction_response = frappe._dict(kwargs["Body"]["stkCallback"])
|
transaction_response = frappe._dict(kwargs["Body"]["stkCallback"])
|
||||||
|
|
||||||
checkout_id = getattr(transaction_response, "CheckoutRequestID", "")
|
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)
|
integration_request = frappe.get_doc("Integration Request", checkout_id)
|
||||||
transaction_data = frappe._dict(loads(integration_request.data))
|
transaction_data = frappe._dict(loads(integration_request.data))
|
||||||
total_paid = 0 # for multiple integration request made against a pos invoice
|
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"])
|
account_balance_response = frappe._dict(kwargs["Result"])
|
||||||
|
|
||||||
conversation_id = getattr(account_balance_response, "ConversationID", "")
|
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)
|
request = frappe.get_doc("Integration Request", conversation_id)
|
||||||
|
|
||||||
if request.status == "Completed":
|
if request.status == "Completed":
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ def validate_webhooks_request(doctype, hmac_key, secret_key='secret'):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if frappe.request.data and \
|
if frappe.request.data and \
|
||||||
frappe.get_request_header(hmac_key) and \
|
|
||||||
not sig == bytes(frappe.get_request_header(hmac_key).encode()):
|
not sig == bytes(frappe.get_request_header(hmac_key).encode()):
|
||||||
frappe.throw(_("Unverified Webhook Data"))
|
frappe.throw(_("Unverified Webhook Data"))
|
||||||
frappe.set_user(settings.modified_by)
|
frappe.set_user(settings.modified_by)
|
||||||
|
|||||||
@@ -3,7 +3,39 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import frappe
|
||||||
|
from frappe.utils.data import today
|
||||||
|
|
||||||
# test_records = frappe.get_test_records('Maintenance Visit')
|
# test_records = frappe.get_test_records('Maintenance Visit')
|
||||||
|
|
||||||
class TestMaintenanceVisit(unittest.TestCase):
|
class TestMaintenanceVisit(unittest.TestCase):
|
||||||
pass
|
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
|
||||||
|
|||||||
@@ -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) {
|
refresh: function(frm) {
|
||||||
frappe.flags.pause_job = 0;
|
frappe.flags.pause_job = 0;
|
||||||
frappe.flags.resume_job = 0;
|
frappe.flags.resume_job = 0;
|
||||||
|
|||||||
@@ -396,6 +396,7 @@
|
|||||||
"options": "Batch"
|
"options": "Batch"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"collapsible": 1,
|
||||||
"fieldname": "scrap_items_section",
|
"fieldname": "scrap_items_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Scrap Items"
|
"label": "Scrap Items"
|
||||||
@@ -411,7 +412,7 @@
|
|||||||
],
|
],
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-14 00:38:46.873105",
|
"modified": "2021-11-12 10:15:03.572401",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Job Card",
|
"name": "Job Card",
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ frappe.ui.form.on('Production Plan', {
|
|||||||
}
|
}
|
||||||
frm.trigger("material_requirement");
|
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">
|
<tr><td style="padding-left:25px">
|
||||||
<div>
|
<div>
|
||||||
<h3 style="text-decoration: underline;">
|
<h3 style="text-decoration: underline;">
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ erpnext.patches.v13_0.requeue_failed_reposts
|
|||||||
erpnext.patches.v13_0.update_job_card_status
|
erpnext.patches.v13_0.update_job_card_status
|
||||||
erpnext.patches.v12_0.update_production_plan_status
|
erpnext.patches.v12_0.update_production_plan_status
|
||||||
erpnext.patches.v13_0.healthcare_deprecation_warning
|
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.v14_0.delete_healthcare_doctypes
|
||||||
erpnext.patches.v13_0.update_category_in_ltds_certificate
|
erpnext.patches.v13_0.update_category_in_ltds_certificate
|
||||||
erpnext.patches.v13_0.create_pan_field_for_india #2
|
erpnext.patches.v13_0.create_pan_field_for_india #2
|
||||||
|
|||||||
11
erpnext/patches/v13_0/item_naming_series_not_mandatory.py
Normal file
11
erpnext/patches/v13_0/item_naming_series_not_mandatory.py
Normal file
@@ -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)
|
||||||
@@ -165,45 +165,33 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac
|
|||||||
}
|
}
|
||||||
|
|
||||||
qty(doc, cdt, cdn) {
|
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))) {
|
if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) {
|
||||||
frappe.model.round_floats_in(item, ["qty", "received_qty"]);
|
this.calculate_received_qty(doc, cdt, cdn)
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
super.qty(doc, cdt, cdn);
|
super.qty(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rejected_qty(doc, cdt, cdn) {
|
||||||
|
this.calculate_received_qty(doc, cdt, cdn)
|
||||||
|
}
|
||||||
|
|
||||||
|
calculate_received_qty(doc, cdt, cdn){
|
||||||
|
var item = frappe.get_doc(cdt, cdn);
|
||||||
|
frappe.model.round_floats_in(item, ["qty", "rejected_qty"]);
|
||||||
|
|
||||||
|
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["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);
|
||||||
|
|
||||||
|
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) {
|
batch_no(doc, cdt, cdn) {
|
||||||
super.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)
|
|
||||||
}
|
|
||||||
|
|
||||||
calculate_accepted_qty(doc, cdt, cdn){
|
|
||||||
var item = frappe.get_doc(cdt, cdn);
|
|
||||||
frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]);
|
|
||||||
|
|
||||||
if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["received_qty", "rejected_qty"])){ return }
|
|
||||||
|
|
||||||
item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item));
|
|
||||||
this.qty(doc, cdt, cdn);
|
|
||||||
}
|
|
||||||
|
|
||||||
validate_negative_quantity(cdt, cdn, item, fieldnames){
|
validate_negative_quantity(cdt, cdn, item, fieldnames){
|
||||||
if(!item || !fieldnames) { return }
|
if(!item || !fieldnames) { return }
|
||||||
|
|
||||||
|
|||||||
@@ -248,18 +248,17 @@ class Gstr1Report(object):
|
|||||||
""" % (self.doctype, ', '.join(['%s']*len(self.invoices))), tuple(self.invoices), as_dict=1)
|
""" % (self.doctype, ', '.join(['%s']*len(self.invoices))), tuple(self.invoices), as_dict=1)
|
||||||
|
|
||||||
for d in items:
|
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.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[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:
|
if d.item_tax_rate:
|
||||||
item_tax_rate = json.loads(d.item_tax_rate)
|
item_tax_rate = json.loads(d.item_tax_rate)
|
||||||
|
|
||||||
for account, rate in item_tax_rate.items():
|
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 = self.item_tax_rate.setdefault(d.parent, {}).setdefault(d.item_code, [])
|
||||||
tax_rate_dict.append(rate)
|
tax_rate_dict.append(rate)
|
||||||
|
|
||||||
def get_items_based_on_tax_rate(self):
|
def get_items_based_on_tax_rate(self):
|
||||||
self.tax_details = frappe.db.sql("""
|
self.tax_details = frappe.db.sql("""
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
|
|||||||
title: __('Select Items to Manufacture'),
|
title: __('Select Items to Manufacture'),
|
||||||
fields: fields,
|
fields: fields,
|
||||||
primary_action: function() {
|
primary_action: function() {
|
||||||
var data = d.get_values();
|
var data = {items: d.fields_dict.items.grid.get_selected_children()};
|
||||||
me.frm.call({
|
me.frm.call({
|
||||||
method: 'make_work_orders',
|
method: 'make_work_orders',
|
||||||
args: {
|
args: {
|
||||||
|
|||||||
@@ -223,60 +223,15 @@ class SalesOrder(SellingController):
|
|||||||
check_credit_limit(self.customer, self.company)
|
check_credit_limit(self.customer, self.company)
|
||||||
|
|
||||||
def check_nextdoc_docstatus(self):
|
def check_nextdoc_docstatus(self):
|
||||||
# Checks Delivery Note
|
linked_invoices = frappe.db.sql_list("""select distinct t1.name
|
||||||
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
|
|
||||||
from `tabSales Invoice` t1,`tabSales Invoice Item` t2
|
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)
|
self.name)
|
||||||
|
|
||||||
if submit_rv:
|
if linked_invoices:
|
||||||
submit_rv = [get_link_to_form("Sales Invoice", si) for si in submit_rv]
|
linked_invoices = [get_link_to_form("Sales Invoice", si) for si in linked_invoices]
|
||||||
frappe.throw(_("Sales Invoice {0} must be cancelled before cancelling this Sales Order")
|
frappe.throw(_("Sales Invoice {0} must be deleted before cancelling this Sales Order")
|
||||||
.format(", ".join(submit_rv)))
|
.format(", ".join(linked_invoices)))
|
||||||
|
|
||||||
#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)))
|
|
||||||
|
|
||||||
def check_modified_date(self):
|
def check_modified_date(self):
|
||||||
mod_db = frappe.db.get_value("Sales Order", self.name, "modified")
|
mod_db = frappe.db.get_value("Sales Order", self.name, "modified")
|
||||||
|
|||||||
@@ -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 frappe.utils import add_days, flt, getdate, nowdate
|
||||||
|
|
||||||
from erpnext.controllers.accounts_controller import update_child_qty_rate
|
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.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.product_bundle.test_product_bundle import make_product_bundle
|
||||||
from erpnext.selling.doctype.sales_order.sales_order import (
|
from erpnext.selling.doctype.sales_order.sales_order import (
|
||||||
@@ -1278,6 +1284,72 @@ class TestSalesOrder(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertRaises(frappe.ValidationError, so.cancel)
|
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):
|
def test_payment_terms_are_fetched_when_creating_sales_invoice(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import (
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import (
|
||||||
create_payment_terms_template,
|
create_payment_terms_template,
|
||||||
|
|||||||
@@ -1,247 +1,100 @@
|
|||||||
{
|
{
|
||||||
"allow_copy": 0,
|
"actions": [],
|
||||||
"allow_guest_to_view": 0,
|
"creation": "2013-04-19 13:30:51",
|
||||||
"allow_import": 0,
|
"doctype": "DocType",
|
||||||
"allow_rename": 0,
|
"document_type": "Setup",
|
||||||
"beta": 0,
|
"editable_grid": 1,
|
||||||
"creation": "2013-04-19 13:30:51",
|
"engine": "InnoDB",
|
||||||
"custom": 0,
|
"field_order": [
|
||||||
"docstatus": 0,
|
"sales_person",
|
||||||
"doctype": "DocType",
|
"contact_no",
|
||||||
"document_type": "Setup",
|
"allocated_percentage",
|
||||||
"editable_grid": 1,
|
"allocated_amount",
|
||||||
"engine": "InnoDB",
|
"commission_rate",
|
||||||
|
"incentives"
|
||||||
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_on_submit": 1,
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "sales_person",
|
||||||
"allow_on_submit": 1,
|
"fieldtype": "Link",
|
||||||
"bold": 0,
|
"in_list_view": 1,
|
||||||
"collapsible": 0,
|
"label": "Sales Person",
|
||||||
"columns": 0,
|
"oldfieldname": "sales_person",
|
||||||
"fieldname": "sales_person",
|
"oldfieldtype": "Link",
|
||||||
"fieldtype": "Link",
|
"options": "Sales Person",
|
||||||
"hidden": 0,
|
"print_width": "200px",
|
||||||
"ignore_user_permissions": 0,
|
"reqd": 1,
|
||||||
"ignore_xss_filter": 0,
|
"search_index": 1,
|
||||||
"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,
|
|
||||||
"width": "200px"
|
"width": "200px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_on_submit": 1,
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "contact_no",
|
||||||
"allow_on_submit": 1,
|
"fieldtype": "Data",
|
||||||
"bold": 0,
|
"hidden": 1,
|
||||||
"collapsible": 0,
|
"in_list_view": 1,
|
||||||
"columns": 0,
|
"label": "Contact No.",
|
||||||
"fieldname": "contact_no",
|
"oldfieldname": "contact_no",
|
||||||
"fieldtype": "Data",
|
"oldfieldtype": "Data",
|
||||||
"hidden": 1,
|
"print_width": "100px",
|
||||||
"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,
|
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_on_submit": 1,
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "allocated_percentage",
|
||||||
"allow_on_submit": 1,
|
"fieldtype": "Float",
|
||||||
"bold": 0,
|
"in_list_view": 1,
|
||||||
"collapsible": 0,
|
"label": "Contribution (%)",
|
||||||
"columns": 0,
|
"oldfieldname": "allocated_percentage",
|
||||||
"fieldname": "allocated_percentage",
|
"oldfieldtype": "Currency",
|
||||||
"fieldtype": "Float",
|
"print_width": "100px",
|
||||||
"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,
|
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_on_submit": 1,
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "allocated_amount",
|
||||||
"allow_on_submit": 1,
|
"fieldtype": "Currency",
|
||||||
"bold": 0,
|
"in_list_view": 1,
|
||||||
"collapsible": 0,
|
"label": "Contribution to Net Total",
|
||||||
"columns": 0,
|
"oldfieldname": "allocated_amount",
|
||||||
"fieldname": "allocated_amount",
|
"oldfieldtype": "Currency",
|
||||||
"fieldtype": "Currency",
|
"options": "Company:company:default_currency",
|
||||||
"hidden": 0,
|
"print_width": "120px",
|
||||||
"ignore_user_permissions": 0,
|
"read_only": 1,
|
||||||
"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,
|
|
||||||
"width": "120px"
|
"width": "120px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"fetch_from": "sales_person.commission_rate",
|
||||||
"allow_in_quick_entry": 0,
|
"fetch_if_empty": 1,
|
||||||
"allow_on_submit": 0,
|
"fieldname": "commission_rate",
|
||||||
"bold": 0,
|
"fieldtype": "Data",
|
||||||
"collapsible": 0,
|
"in_list_view": 1,
|
||||||
"columns": 0,
|
"label": "Commission Rate",
|
||||||
"fieldname": "commission_rate",
|
"read_only": 1
|
||||||
"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
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_on_submit": 1,
|
||||||
"allow_in_quick_entry": 0,
|
"fieldname": "incentives",
|
||||||
"allow_on_submit": 1,
|
"fieldtype": "Currency",
|
||||||
"bold": 0,
|
"in_list_view": 1,
|
||||||
"collapsible": 0,
|
"label": "Incentives",
|
||||||
"columns": 0,
|
"oldfieldname": "incentives",
|
||||||
"fieldname": "incentives",
|
"oldfieldtype": "Currency",
|
||||||
"fieldtype": "Currency",
|
"options": "Company:company:default_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
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"has_web_view": 0,
|
"idx": 1,
|
||||||
"hide_heading": 0,
|
"istable": 1,
|
||||||
"hide_toolbar": 0,
|
"links": [],
|
||||||
"idx": 1,
|
"modified": "2021-11-09 23:55:20.670475",
|
||||||
"image_view": 0,
|
"modified_by": "Administrator",
|
||||||
"in_create": 0,
|
"module": "Selling",
|
||||||
"is_submittable": 0,
|
"name": "Sales Team",
|
||||||
"issingle": 0,
|
"owner": "Administrator",
|
||||||
"istable": 1,
|
"permissions": [],
|
||||||
"max_attachments": 0,
|
"quick_entry": 1,
|
||||||
"modified": "2018-09-17 13:03:14.755974",
|
"sort_field": "modified",
|
||||||
"modified_by": "Administrator",
|
"sort_order": "DESC",
|
||||||
"module": "Selling",
|
"track_changes": 1
|
||||||
"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
|
|
||||||
}
|
|
||||||
@@ -43,7 +43,6 @@ class ItemGroup(NestedSet, WebsiteGenerator):
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
NestedSet.on_update(self)
|
NestedSet.on_update(self)
|
||||||
invalidate_cache_for(self)
|
invalidate_cache_for(self)
|
||||||
self.validate_name_with_item()
|
|
||||||
self.validate_one_root()
|
self.validate_one_root()
|
||||||
self.delete_child_item_groups_key()
|
self.delete_child_item_groups_key()
|
||||||
|
|
||||||
@@ -67,10 +66,6 @@ class ItemGroup(NestedSet, WebsiteGenerator):
|
|||||||
WebsiteGenerator.on_trash(self)
|
WebsiteGenerator.on_trash(self)
|
||||||
self.delete_child_item_groups_key()
|
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):
|
def get_context(self, context):
|
||||||
context.show_search=True
|
context.show_search=True
|
||||||
context.page_length = cint(frappe.db.get_single_value('Products Settings', 'products_per_page')) or 6
|
context.page_length = cint(frappe.db.get_single_value('Products Settings', 'products_per_page')) or 6
|
||||||
|
|||||||
@@ -180,11 +180,11 @@ class NamingSeries(Document):
|
|||||||
prefix = parse_naming_series(parts)
|
prefix = parse_naming_series(parts)
|
||||||
return prefix
|
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
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
if naming_series:
|
if naming_series:
|
||||||
make_property_setter(doctype, "naming_series", "hidden", 0, "Check", validate_fields_for_doctype=False)
|
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
|
# set values for mandatory
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ class Item(WebsiteGenerator):
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
invalidate_cache_for_item(self)
|
invalidate_cache_for_item(self)
|
||||||
self.validate_name_with_item_group()
|
|
||||||
self.update_variants()
|
self.update_variants()
|
||||||
self.update_item_price()
|
self.update_item_price()
|
||||||
self.update_template_item()
|
self.update_template_item()
|
||||||
@@ -628,12 +627,6 @@ class Item(WebsiteGenerator):
|
|||||||
where item_code = %s and is_cancelled = 0 limit 1""", self.name))
|
where item_code = %s and is_cancelled = 0 limit 1""", self.name))
|
||||||
return self._stock_ledger_created
|
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):
|
def update_item_price(self):
|
||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
UPDATE `tabItem Price`
|
UPDATE `tabItem Price`
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ erpnext.stock.LandedCostVoucher = class LandedCostVoucher extends erpnext.stock.
|
|||||||
refresh() {
|
refresh() {
|
||||||
var help_content =
|
var help_content =
|
||||||
`<br><br>
|
`<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>
|
<tr><td>
|
||||||
<h4>
|
<h4>
|
||||||
<i class="fa fa-hand-right"></i>
|
<i class="fa fa-hand-right"></i>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from frappe.utils import add_days, cint, cstr, flt, today
|
|||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
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.item.test_item import create_item, make_item
|
||||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
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
|
from erpnext.stock.doctype.serial_no.serial_no import SerialNoDuplicateError, get_serial_nos
|
||||||
@@ -22,20 +23,54 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
|
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):
|
def test_reverse_purchase_receipt_sle(self):
|
||||||
|
|
||||||
pr = make_purchase_receipt(qty=0.5, item_code="_Test Item Home Desktop 200")
|
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",
|
sl_entry = frappe.db.get_all(
|
||||||
"voucher_no": pr.name}, ['actual_qty'])
|
"Stock Ledger Entry",
|
||||||
|
{
|
||||||
|
"voucher_type": "Purchase Receipt",
|
||||||
|
"voucher_no": pr.name
|
||||||
|
},
|
||||||
|
['actual_qty']
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(len(sl_entry), 1)
|
self.assertEqual(len(sl_entry), 1)
|
||||||
self.assertEqual(sl_entry[0].actual_qty, 0.5)
|
self.assertEqual(sl_entry[0].actual_qty, 0.5)
|
||||||
|
|
||||||
pr.cancel()
|
pr.cancel()
|
||||||
|
|
||||||
sl_entry_cancelled = frappe.db.get_all("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
|
sl_entry_cancelled = frappe.db.get_all(
|
||||||
"voucher_no": pr.name}, ['actual_qty'], order_by='creation')
|
"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(len(sl_entry_cancelled), 2)
|
||||||
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
|
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
|
||||||
@@ -61,8 +96,15 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
}]
|
}]
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
template = frappe.db.get_value('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice')
|
template = frappe.db.get_value(
|
||||||
old_template_in_supplier = frappe.db.get_value("Supplier", "_Test Supplier", "payment_terms")
|
"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)
|
frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", template)
|
||||||
|
|
||||||
pr = make_purchase_receipt(do_not_save=True)
|
pr = make_purchase_receipt(do_not_save=True)
|
||||||
@@ -88,30 +130,59 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
# teardown
|
# teardown
|
||||||
pi.delete() # draft PI
|
pi.delete() # draft PI
|
||||||
pr.cancel()
|
pr.cancel()
|
||||||
frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", old_template_in_supplier)
|
frappe.db.set_value(
|
||||||
frappe.get_doc('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice').delete()
|
"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):
|
def test_purchase_receipt_no_gl_entry(self):
|
||||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
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",
|
||||||
existing_bin_qty, existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
|
{
|
||||||
"warehouse": "_Test Warehouse - _TC"}, ["actual_qty", "stock_value"])
|
"item_code": "_Test Item",
|
||||||
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
|
},
|
||||||
|
["actual_qty", "stock_value"]
|
||||||
|
)
|
||||||
|
|
||||||
if existing_bin_qty < 0:
|
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()
|
pr = make_purchase_receipt()
|
||||||
|
|
||||||
stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
|
stock_value_difference = frappe.db.get_value(
|
||||||
{"voucher_type": "Purchase Receipt", "voucher_no": pr.name,
|
"Stock Ledger Entry",
|
||||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, "stock_value_difference")
|
{
|
||||||
|
"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)
|
self.assertEqual(stock_value_difference, 250)
|
||||||
|
|
||||||
current_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
|
current_bin_stock_value = frappe.db.get_value(
|
||||||
"warehouse": "_Test Warehouse - _TC"}, "stock_value")
|
"Bin",
|
||||||
|
{
|
||||||
|
"item_code": "_Test Item",
|
||||||
|
"warehouse": "_Test Warehouse - _TC"
|
||||||
|
},
|
||||||
|
"stock_value"
|
||||||
|
)
|
||||||
self.assertEqual(current_bin_stock_value, existing_bin_stock_value + 250)
|
self.assertEqual(current_bin_stock_value, existing_bin_stock_value + 250)
|
||||||
|
|
||||||
self.assertFalse(get_gl_entries("Purchase Receipt", pr.name))
|
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)
|
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()
|
pr.load_from_db()
|
||||||
batch_no = pr.items[0].batch_no
|
batch_no = pr.items[0].batch_no
|
||||||
pr.cancel()
|
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}))
|
self.assertFalse(frappe.db.get_all('Serial No', {'batch_no': batch_no}))
|
||||||
|
|
||||||
def test_duplicate_serial_nos(self):
|
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 = make_purchase_receipt(item_code=item.name, qty=2, rate=500)
|
||||||
pr.load_from_db()
|
pr.load_from_db()
|
||||||
|
|
||||||
serial_nos = frappe.db.get_value('Stock Ledger Entry',
|
serial_nos = frappe.db.get_value(
|
||||||
{'voucher_type': 'Purchase Receipt', 'voucher_no': pr.name, 'item_code': item.name}, 'serial_no')
|
"Stock Ledger Entry",
|
||||||
|
{
|
||||||
|
"voucher_type": "Purchase Receipt",
|
||||||
|
"voucher_no": pr.name,
|
||||||
|
"item_code": item.name
|
||||||
|
},
|
||||||
|
"serial_no"
|
||||||
|
)
|
||||||
|
|
||||||
serial_nos = get_serial_nos(serial_nos)
|
serial_nos = get_serial_nos(serial_nos)
|
||||||
|
|
||||||
self.assertEquals(get_serial_nos(pr.items[0].serial_no), serial_nos)
|
self.assertEquals(get_serial_nos(pr.items[0].serial_no), serial_nos)
|
||||||
|
|
||||||
# Then tried to receive same serial nos in difference company
|
# Then tried to receive same serial nos in difference company
|
||||||
pr_different_company = make_purchase_receipt(item_code=item.name, qty=2, rate=500,
|
pr_different_company = make_purchase_receipt(
|
||||||
serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True,
|
item_code=item.name,
|
||||||
warehouse = 'Stores - _TC1')
|
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)
|
self.assertRaises(SerialNoDuplicateError, pr_different_company.submit)
|
||||||
|
|
||||||
# Then made delivery note to remove the serial nos from stock
|
# 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()
|
dn.load_from_db()
|
||||||
self.assertEquals(get_serial_nos(dn.items[0].serial_no), serial_nos)
|
self.assertEquals(get_serial_nos(dn.items[0].serial_no), serial_nos)
|
||||||
|
|
||||||
posting_date = add_days(today(), -3)
|
posting_date = add_days(today(), -3)
|
||||||
|
|
||||||
# Try to receive same serial nos again in the same company with backdated.
|
# 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,
|
pr1 = make_purchase_receipt(
|
||||||
posting_date=posting_date, serial_no='\n'.join(serial_nos), do_not_submit=True)
|
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)
|
self.assertRaises(SerialNoExistsInFutureTransaction, pr1.submit)
|
||||||
|
|
||||||
# Try to receive same serial nos with different company with backdated.
|
# Try to receive same serial nos with different company with backdated.
|
||||||
pr2 = make_purchase_receipt(item_code=item.name, qty=2, rate=500,
|
pr2 = make_purchase_receipt(
|
||||||
posting_date=posting_date, serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True,
|
item_code=item.name,
|
||||||
warehouse = 'Stores - _TC1')
|
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)
|
self.assertRaises(SerialNoExistsInFutureTransaction, pr2.submit)
|
||||||
|
|
||||||
# Receive the same serial nos after the delivery note posting date and time
|
# 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
|
# Raise the error for backdated deliver note entry cancel
|
||||||
self.assertRaises(SerialNoExistsInFutureTransaction, dn.cancel)
|
self.assertRaises(SerialNoExistsInFutureTransaction, dn.cancel)
|
||||||
@@ -236,11 +347,23 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
def test_subcontracting(self):
|
def test_subcontracting(self):
|
||||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
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(
|
||||||
make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100)
|
"Buying Settings", None,
|
||||||
make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC",
|
"backflush_raw_materials_of_subcontract_based_on", "BOM"
|
||||||
qty=100, basic_rate=100)
|
)
|
||||||
pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=500, is_subcontracted="Yes")
|
|
||||||
|
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)
|
self.assertEqual(len(pr.get("supplied_items")), 2)
|
||||||
|
|
||||||
rm_supp_cost = sum(d.amount for d in pr.get("supplied_items"))
|
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):
|
def test_subcontracting_gle_fg_item_rate_zero(self):
|
||||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
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",
|
se1 = make_stock_entry(
|
||||||
qty=100, basic_rate=100, company="_Test Company with perpetual inventory")
|
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",
|
se2 = make_stock_entry(
|
||||||
qty=100, basic_rate=100, company="_Test Company with perpetual inventory")
|
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",
|
pr = make_purchase_receipt(
|
||||||
company="_Test Company with perpetual inventory", warehouse='Stores - TCP1',
|
item_code="_Test FG Item",
|
||||||
supplier_warehouse='Work In Progress - TCP1')
|
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)
|
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,
|
po = create_purchase_order(item_code=item_code, qty=1, include_exploded_items=0,
|
||||||
is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC")
|
is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC")
|
||||||
|
|
||||||
#stock raw materials in a warehouse before transfer
|
# stock raw materials in a warehouse before transfer
|
||||||
se1 = make_stock_entry(target="_Test Warehouse - _TC",
|
make_stock_entry(
|
||||||
item_code = "Test Extra Item 1", qty=10, basic_rate=100)
|
target="_Test Warehouse - _TC",
|
||||||
se2 = make_stock_entry(target="_Test Warehouse - _TC",
|
item_code = "Test Extra Item 1",
|
||||||
item_code = "_Test FG Item", qty=1, basic_rate=100)
|
qty=10, basic_rate=100
|
||||||
se3 = make_stock_entry(target="_Test Warehouse - _TC",
|
)
|
||||||
item_code = "Test Extra Item 2", qty=1, 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 = [
|
rm_items = [
|
||||||
{
|
{
|
||||||
"item_code": item_code,
|
"item_code": item_code,
|
||||||
@@ -334,11 +483,17 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
|
|
||||||
def test_serial_no_supplier(self):
|
def test_serial_no_supplier(self):
|
||||||
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
|
pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
|
||||||
self.assertEqual(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"),
|
pr_row_1_serial_no = pr.get("items")[0].serial_no
|
||||||
pr.supplier)
|
|
||||||
|
self.assertEqual(
|
||||||
|
frappe.db.get_value("Serial No", pr_row_1_serial_no, "supplier"),
|
||||||
|
pr.supplier
|
||||||
|
)
|
||||||
|
|
||||||
pr.cancel()
|
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):
|
def test_rejected_serial_no(self):
|
||||||
pr = frappe.copy_doc(test_records[0])
|
pr = frappe.copy_doc(test_records[0])
|
||||||
@@ -365,18 +520,33 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pr.cancel()
|
pr.cancel()
|
||||||
|
|
||||||
def test_purchase_return_partial(self):
|
def test_purchase_return_partial(self):
|
||||||
pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
|
pr = make_purchase_receipt(
|
||||||
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
|
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",
|
return_pr = make_purchase_receipt(
|
||||||
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
|
company="_Test Company with perpetual inventory",
|
||||||
is_return=1, return_against=pr.name, qty=-2, do_not_submit=1)
|
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.items[0].purchase_receipt_item = pr.items[0].name
|
||||||
return_pr.submit()
|
return_pr.submit()
|
||||||
|
|
||||||
# check sle
|
# check sle
|
||||||
outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
|
outgoing_rate = frappe.db.get_value(
|
||||||
"voucher_no": return_pr.name}, "outgoing_rate")
|
"Stock Ledger Entry",
|
||||||
|
{
|
||||||
|
"voucher_type": "Purchase Receipt",
|
||||||
|
"voucher_no": return_pr.name
|
||||||
|
},
|
||||||
|
"outgoing_rate"
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(outgoing_rate, 50)
|
self.assertEqual(outgoing_rate, 50)
|
||||||
|
|
||||||
@@ -440,11 +610,21 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pr.cancel()
|
pr.cancel()
|
||||||
|
|
||||||
def test_purchase_return_full(self):
|
def test_purchase_return_full(self):
|
||||||
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
|
pr = make_purchase_receipt(
|
||||||
supplier_warehouse = "Work in Progress - TCP1")
|
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",
|
return_pr = make_purchase_receipt(
|
||||||
supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, qty=-5, do_not_submit=1)
|
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.items[0].purchase_receipt_item = pr.items[0].name
|
||||||
return_pr.submit()
|
return_pr.submit()
|
||||||
|
|
||||||
@@ -466,15 +646,41 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
|
|
||||||
rejected_warehouse="_Test Rejected Warehouse - TCP1"
|
rejected_warehouse="_Test Rejected Warehouse - TCP1"
|
||||||
if not frappe.db.exists("Warehouse", rejected_warehouse):
|
if not frappe.db.exists("Warehouse", rejected_warehouse):
|
||||||
get_warehouse(company = "_Test Company with perpetual inventory",
|
get_warehouse(
|
||||||
abbr = " - TCP1", warehouse_name = "_Test Rejected Warehouse").name
|
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",
|
actual_qty = frappe.db.get_value(
|
||||||
"voucher_no": return_pr.name, 'warehouse': return_pr.items[0].rejected_warehouse}, "actual_qty")
|
"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)
|
self.assertEqual(actual_qty, -2)
|
||||||
|
|
||||||
@@ -499,8 +705,13 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
"purchase_document_no": pr.name
|
"purchase_document_no": pr.name
|
||||||
})
|
})
|
||||||
|
|
||||||
return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1,
|
return_pr = make_purchase_receipt(
|
||||||
is_return=1, return_against=pr.name, serial_no=serial_no)
|
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, {
|
_check_serial_no_values(serial_no, {
|
||||||
"warehouse": "",
|
"warehouse": "",
|
||||||
@@ -522,9 +733,21 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
})
|
})
|
||||||
row.db_update()
|
row.db_update()
|
||||||
|
|
||||||
pr = make_purchase_receipt(item_code=item_code, qty=1, uom="Box", conversion_factor=1.0)
|
pr = make_purchase_receipt(
|
||||||
return_pr = make_purchase_receipt(item_code=item_code, qty=-10, uom="Unit",
|
item_code=item_code,
|
||||||
stock_uom="Box", conversion_factor=0.1, is_return=1, return_against=pr.name)
|
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)
|
self.assertEqual(abs(return_pr.items[0].stock_qty), 1.0)
|
||||||
|
|
||||||
@@ -540,13 +763,19 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pr.submit()
|
pr.submit()
|
||||||
|
|
||||||
update_purchase_receipt_status(pr.name, "Closed")
|
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.reload()
|
||||||
pr.cancel()
|
pr.cancel()
|
||||||
|
|
||||||
def test_pr_billing_status(self):
|
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 (
|
from erpnext.buying.doctype.purchase_order.purchase_order import (
|
||||||
make_purchase_invoice as make_purchase_invoice_from_po,
|
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,
|
pr_doc = make_purchase_receipt(item_code=item_code,
|
||||||
qty=1, serial_no = serial_no)
|
qty=1, serial_no = serial_no)
|
||||||
|
|
||||||
self.assertEqual(serial_no, frappe.db.get_value("Serial No",
|
self.assertEqual(
|
||||||
{"purchase_document_type": "Purchase Receipt", "purchase_document_no": pr_doc.name}, "name"))
|
serial_no,
|
||||||
|
frappe.db.get_value(
|
||||||
|
"Serial No",
|
||||||
|
{
|
||||||
|
"purchase_document_type": "Purchase Receipt",
|
||||||
|
"purchase_document_no": pr_doc.name
|
||||||
|
},
|
||||||
|
"name"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
pr_doc.cancel()
|
pr_doc.cancel()
|
||||||
|
|
||||||
#check for the auto created serial nos
|
# check for the auto created serial nos
|
||||||
item_code = "Test Auto Created Serial No"
|
item_code = "Test Auto Created Serial No"
|
||||||
if not frappe.db.exists("Item", item_code):
|
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)
|
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]
|
serial_no = get_serial_nos(new_pr_doc.items[0].serial_no)[0]
|
||||||
self.assertEqual(serial_no, frappe.db.get_value("Serial No",
|
self.assertEqual(
|
||||||
{"purchase_document_type": "Purchase Receipt", "purchase_document_no": new_pr_doc.name}, "name"))
|
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()
|
new_pr_doc.cancel()
|
||||||
|
|
||||||
@@ -700,8 +947,12 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
|
|
||||||
def test_purchase_receipt_cost_center(self):
|
def test_purchase_receipt_cost_center(self):
|
||||||
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
||||||
|
|
||||||
cost_center = "_Test Cost Center for BS Account - TCP1"
|
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'):
|
if not frappe.db.exists('Location', 'Test Location'):
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
@@ -709,10 +960,16 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
'location_name': 'Test Location'
|
'location_name': 'Test Location'
|
||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
pr = make_purchase_receipt(cost_center=cost_center, company="_Test Company with perpetual inventory",
|
pr = make_purchase_receipt(
|
||||||
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
|
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)
|
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.assertTrue(gl_entries)
|
||||||
@@ -736,9 +993,16 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
'doctype': 'Location',
|
'doctype': 'Location',
|
||||||
'location_name': 'Test Location'
|
'location_name': 'Test Location'
|
||||||
}).insert()
|
}).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)
|
gl_entries = get_gl_entries("Purchase Receipt", pr.name)
|
||||||
|
|
||||||
self.assertTrue(gl_entries)
|
self.assertTrue(gl_entries)
|
||||||
@@ -766,7 +1030,11 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
po = create_purchase_order()
|
po = create_purchase_order()
|
||||||
pr = create_pr_against_po(po.name)
|
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 = po.name
|
||||||
pr1.items[0].purchase_order_item = po.items[0].name
|
pr1.items[0].purchase_order_item = po.items[0].name
|
||||||
pr1.items[0].purchase_receipt_item = pr.items[0].name
|
pr1.items[0].purchase_receipt_item = pr.items[0].name
|
||||||
@@ -799,7 +1067,11 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pi1.save()
|
pi1.save()
|
||||||
pi1.submit()
|
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.items[0].purchase_receipt_item = pr1.items[0].name
|
||||||
pr2.submit()
|
pr2.submit()
|
||||||
|
|
||||||
@@ -841,14 +1113,22 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pr1.cancel()
|
pr1.cancel()
|
||||||
|
|
||||||
def test_stock_transfer_from_purchase_receipt_with_valuation(self):
|
def test_stock_transfer_from_purchase_receipt_with_valuation(self):
|
||||||
create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory",
|
create_warehouse(
|
||||||
properties={"account": '_Test Account Stock In Hand - TCP1'})
|
"_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',
|
pr1 = make_purchase_receipt(
|
||||||
company="_Test Company with perpetual inventory")
|
warehouse = '_Test Warehouse for Valuation - TCP1',
|
||||||
|
company="_Test Company with perpetual inventory"
|
||||||
|
)
|
||||||
|
|
||||||
pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
|
pr = make_purchase_receipt(
|
||||||
warehouse = "Stores - TCP1", do_not_save=1)
|
company="_Test Company with perpetual inventory",
|
||||||
|
warehouse = "Stores - TCP1",
|
||||||
|
do_not_save=1
|
||||||
|
)
|
||||||
|
|
||||||
pr.items[0].from_warehouse = '_Test Warehouse for Valuation - TCP1'
|
pr.items[0].from_warehouse = '_Test Warehouse for Valuation - TCP1'
|
||||||
pr.supplier_warehouse = ''
|
pr.supplier_warehouse = ''
|
||||||
@@ -930,10 +1210,24 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
rm_items = [
|
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,
|
||||||
{"item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 3","item_name":"_Test Item",
|
"rm_item_code":"Sub Contracted Raw Material 3",
|
||||||
"qty":200,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[0].name}
|
"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)
|
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.items[1].batch_no = ste2.items[0].batch_no
|
||||||
se.submit()
|
se.submit()
|
||||||
|
|
||||||
supplied_qty = frappe.db.get_value("Purchase Order Item Supplied",
|
supplied_qty = frappe.db.get_value(
|
||||||
{"parent": po.name, "rm_item_code": "Sub Contracted Raw Material 3"}, "supplied_qty")
|
"Purchase Order Item Supplied",
|
||||||
|
{
|
||||||
|
"parent": po.name,
|
||||||
|
"rm_item_code": "Sub Contracted Raw Material 3"
|
||||||
|
},
|
||||||
|
"supplied_qty"
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(supplied_qty, 500.00)
|
self.assertEqual(supplied_qty, 500.00)
|
||||||
|
|
||||||
@@ -1016,10 +1316,18 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
company = '_Test Company with perpetual inventory'
|
company = '_Test Company with perpetual inventory'
|
||||||
service_item = '_Test Non Stock Item'
|
service_item = '_Test Non Stock Item'
|
||||||
|
|
||||||
before_test_value = frappe.db.get_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items')
|
before_test_value = frappe.db.get_value(
|
||||||
frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', 1)
|
'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'
|
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(
|
pr = make_purchase_receipt(
|
||||||
company=company, item=service_item,
|
company=company, item=service_item,
|
||||||
@@ -1051,7 +1359,10 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
self.assertEqual(len(item_one_gl_entry), 1)
|
self.assertEqual(len(item_one_gl_entry), 1)
|
||||||
self.assertEqual(len(item_two_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):
|
def test_purchase_receipt_with_exchange_rate_difference(self):
|
||||||
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import (
|
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import (
|
||||||
@@ -1076,10 +1387,19 @@ class TestPurchaseReceipt(ERPNextTestCase):
|
|||||||
pr.submit()
|
pr.submit()
|
||||||
|
|
||||||
# Get exchnage gain and loss account
|
# 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
|
# 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)
|
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)
|
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.return_against = args.return_against
|
||||||
pr.apply_putaway_rule = args.apply_putaway_rule
|
pr.apply_putaway_rule = args.apply_putaway_rule
|
||||||
qty = args.qty or 5
|
qty = args.qty or 5
|
||||||
received_qty = args.received_qty or qty
|
rejected_qty = args.rejected_qty or 0
|
||||||
rejected_qty = args.rejected_qty or flt(received_qty) - flt(qty)
|
received_qty = args.received_qty or flt(rejected_qty) + flt(qty)
|
||||||
|
|
||||||
item_code = args.item or args.item_code or "_Test Item"
|
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"
|
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:
|
if args.get_multiple_items:
|
||||||
pr.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:
|
if args.get_taxes_and_charges:
|
||||||
for tax in get_taxes():
|
for tax in get_taxes():
|
||||||
|
|||||||
@@ -197,6 +197,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bold": 1,
|
"bold": 1,
|
||||||
|
"default": "0",
|
||||||
"fieldname": "received_qty",
|
"fieldname": "received_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Received Quantity",
|
"label": "Received Quantity",
|
||||||
@@ -204,6 +205,7 @@
|
|||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
@@ -219,8 +221,10 @@
|
|||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"columns": 1,
|
||||||
"fieldname": "rejected_qty",
|
"fieldname": "rejected_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
|
"in_list_view": 1,
|
||||||
"label": "Rejected Quantity",
|
"label": "Rejected Quantity",
|
||||||
"oldfieldname": "rejected_qty",
|
"oldfieldname": "rejected_qty",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
@@ -327,7 +331,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bold": 1,
|
"bold": 1,
|
||||||
"columns": 3,
|
"columns": 2,
|
||||||
"fieldname": "rate",
|
"fieldname": "rate",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@@ -543,6 +547,7 @@
|
|||||||
"fieldname": "stock_qty",
|
"fieldname": "stock_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Accepted Qty in Stock UOM",
|
"label": "Accepted Qty in Stock UOM",
|
||||||
|
"no_copy": 1,
|
||||||
"oldfieldname": "stock_qty",
|
"oldfieldname": "stock_qty",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
@@ -882,7 +887,9 @@
|
|||||||
"fieldname": "received_stock_qty",
|
"fieldname": "received_stock_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Received Qty in Stock UOM",
|
"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",
|
"depends_on": "eval: doc.uom != doc.stock_uom",
|
||||||
@@ -969,10 +976,11 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-09-01 16:02:40.338597",
|
"modified": "2021-11-15 15:46:10.591600",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Purchase Receipt Item",
|
"name": "Purchase Receipt Item",
|
||||||
|
"naming_rule": "Random",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ def check_serial_no_validity_on_cancel(serial_no, sle):
|
|||||||
is_stock_reco = sle.voucher_type == "Stock Reconciliation"
|
is_stock_reco = sle.voucher_type == "Stock Reconciliation"
|
||||||
msg = None
|
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
|
# receipt(inward) is being cancelled
|
||||||
msg = _("Cannot cancel {0} {1} as Serial No {2} does not belong to the warehouse {3}").format(
|
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))
|
sle.voucher_type, doc_link, sr_link, frappe.bold(sle.warehouse))
|
||||||
|
|||||||
@@ -399,6 +399,34 @@ class TestStockReconciliation(ERPNextTestCase):
|
|||||||
, do_not_submit=True)
|
, do_not_submit=True)
|
||||||
self.assertRaises(frappe.ValidationError, sr.submit)
|
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):
|
def create_batch_item_with_batch(item_name, batch_id):
|
||||||
batch_item_doc = create_item(item_name, is_stock_item=1)
|
batch_item_doc = create_item(item_name, is_stock_item=1)
|
||||||
if not batch_item_doc.has_batch_no:
|
if not batch_item_doc.has_batch_no:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class StockSettings(Document):
|
|||||||
|
|
||||||
from erpnext.setup.doctype.naming_series.naming_series import set_by_naming_series
|
from erpnext.setup.doctype.naming_series.naming_series import set_by_naming_series
|
||||||
set_by_naming_series("Item", "item_code",
|
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
|
stock_frozen_limit = 356
|
||||||
submitted_stock_frozen = self.stock_frozen_upto_days or 0
|
submitted_stock_frozen = self.stock_frozen_upto_days or 0
|
||||||
|
|||||||
Reference in New Issue
Block a user