Merge branch 'version-13-hotfix' of https://github.com/frappe/erpnext into e-commerce-refactor

This commit is contained in:
marination
2021-08-26 16:53:59 +05:30
83 changed files with 2143 additions and 676 deletions

View File

@@ -18,6 +18,7 @@
"delete_linked_ledger_entries",
"book_asset_depreciation_entry_automatically",
"unlink_advance_payment_on_cancelation_of_order",
"enable_common_party_accounting",
"post_change_gl_entries",
"enable_discount_accounting",
"tax_settings_section",
@@ -269,6 +270,12 @@
"fieldname": "enable_discount_accounting",
"fieldtype": "Check",
"label": "Enable Discount Accounting"
},
{
"default": "0",
"fieldname": "enable_common_party_accounting",
"fieldtype": "Check",
"label": "Enable Common Party Accounting"
}
],
"icon": "icon-cog",
@@ -276,7 +283,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-07-12 18:54:29.084958",
"modified": "2021-08-19 11:17:38.788054",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounts Settings",

View File

@@ -21,6 +21,10 @@ class BankTransaction(StatusUpdater):
self.update_allocations()
self.clear_linked_payment_entries()
self.set_status(update=True)
def on_cancel(self):
self.clear_linked_payment_entries(for_cancel=True)
self.set_status(update=True)
def update_allocations(self):
if self.payment_entries:
@@ -41,21 +45,30 @@ class BankTransaction(StatusUpdater):
frappe.db.set_value(self.doctype, self.name, "status", "Reconciled")
self.reload()
def clear_linked_payment_entries(self):
def clear_linked_payment_entries(self, for_cancel=False):
for payment_entry in self.payment_entries:
if payment_entry.payment_document in ["Payment Entry", "Journal Entry", "Purchase Invoice", "Expense Claim"]:
self.clear_simple_entry(payment_entry)
self.clear_simple_entry(payment_entry, for_cancel=for_cancel)
elif payment_entry.payment_document == "Sales Invoice":
self.clear_sales_invoice(payment_entry)
self.clear_sales_invoice(payment_entry, for_cancel=for_cancel)
def clear_simple_entry(self, payment_entry):
frappe.db.set_value(payment_entry.payment_document, payment_entry.payment_entry, "clearance_date", self.date)
def clear_simple_entry(self, payment_entry, for_cancel=False):
clearance_date = self.date if not for_cancel else None
frappe.db.set_value(
payment_entry.payment_document, payment_entry.payment_entry,
"clearance_date", clearance_date)
def clear_sales_invoice(self, payment_entry):
frappe.db.set_value("Sales Invoice Payment", dict(parenttype=payment_entry.payment_document,
parent=payment_entry.payment_entry), "clearance_date", self.date)
def clear_sales_invoice(self, payment_entry, for_cancel=False):
clearance_date = self.date if not for_cancel else None
frappe.db.set_value(
"Sales Invoice Payment",
dict(
parenttype=payment_entry.payment_document,
parent=payment_entry.payment_entry
),
"clearance_date", clearance_date)
def get_total_allocated_amount(payment_entry):
return frappe.db.sql("""

View File

@@ -4,10 +4,12 @@
frappe.listview_settings['Bank Transaction'] = {
add_fields: ["unallocated_amount"],
get_indicator: function(doc) {
if(flt(doc.unallocated_amount)>0) {
return [__("Unreconciled"), "orange", "unallocated_amount,>,0"];
if(doc.docstatus == 2) {
return [__("Cancelled"), "red", "docstatus,=,2"];
} else if(flt(doc.unallocated_amount)<=0) {
return [__("Reconciled"), "green", "unallocated_amount,=,0"];
} else if(flt(doc.unallocated_amount)>0) {
return [__("Unreconciled"), "orange", "unallocated_amount,>,0"];
}
}
};

View File

@@ -25,7 +25,8 @@ class TestBankTransaction(unittest.TestCase):
def tearDownClass(cls):
for bt in frappe.get_all("Bank Transaction"):
doc = frappe.get_doc("Bank Transaction", bt.name)
doc.cancel()
if doc.docstatus == 1:
doc.cancel()
doc.delete()
# Delete directly in DB to avoid validation errors for countries not allowing deletion
@@ -57,6 +58,12 @@ class TestBankTransaction(unittest.TestCase):
clearance_date = frappe.db.get_value("Payment Entry", payment.name, "clearance_date")
self.assertTrue(clearance_date is not None)
bank_transaction.reload()
bank_transaction.cancel()
clearance_date = frappe.db.get_value("Payment Entry", payment.name, "clearance_date")
self.assertFalse(clearance_date)
# Check if ERPNext can correctly filter a linked payments based on the debit/credit amount
def test_debit_credit_output(self):
bank_transaction = frappe.get_doc("Bank Transaction", dict(description="Auszahlung Karte MC/000002916 AUTOMAT 698769 K002 27.10. 14:07"))

View File

@@ -0,0 +1,33 @@
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('Party Link', {
refresh: function(frm) {
frm.set_query('primary_role', () => {
return {
filters: {
name: ['in', ['Customer', 'Supplier']]
}
};
});
frm.set_query('secondary_role', () => {
let party_types = Object.keys(frappe.boot.party_account_types)
.filter(p => p != frm.doc.primary_role);
return {
filters: {
name: ['in', party_types]
}
};
});
},
primary_role(frm) {
frm.set_value('primary_party', '');
frm.set_value('secondary_role', '');
},
secondary_role(frm) {
frm.set_value('secondary_party', '');
}
});

View File

@@ -0,0 +1,102 @@
{
"actions": [],
"autoname": "ACC-PT-LNK-.###.",
"creation": "2021-08-18 21:06:53.027695",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"primary_role",
"secondary_role",
"column_break_2",
"primary_party",
"secondary_party"
],
"fields": [
{
"fieldname": "primary_role",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Primary Role",
"options": "DocType",
"reqd": 1
},
{
"fieldname": "column_break_2",
"fieldtype": "Column Break"
},
{
"depends_on": "primary_role",
"fieldname": "secondary_role",
"fieldtype": "Link",
"label": "Secondary Role",
"mandatory_depends_on": "primary_role",
"options": "DocType"
},
{
"depends_on": "primary_role",
"fieldname": "primary_party",
"fieldtype": "Dynamic Link",
"label": "Primary Party",
"mandatory_depends_on": "primary_role",
"options": "primary_role"
},
{
"depends_on": "secondary_role",
"fieldname": "secondary_party",
"fieldtype": "Dynamic Link",
"label": "Secondary Party",
"mandatory_depends_on": "secondary_role",
"options": "secondary_role"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-08-25 20:08:56.761150",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Party Link",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts User",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "primary_party",
"track_changes": 1
}

View File

@@ -0,0 +1,26 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.model.document import Document
class PartyLink(Document):
def validate(self):
if self.primary_role not in ['Customer', 'Supplier']:
frappe.throw(_("Allowed primary roles are 'Customer' and 'Supplier'. Please select one of these roles only."),
title=_("Invalid Primary Role"))
existing_party_link = frappe.get_all('Party Link', {
'primary_party': self.secondary_party
}, pluck="primary_role")
if existing_party_link:
frappe.throw(_('{} {} is already linked with another {}')
.format(self.secondary_role, self.secondary_party, existing_party_link[0]))
existing_party_link = frappe.get_all('Party Link', {
'secondary_party': self.primary_party
}, pluck="primary_role")
if existing_party_link:
frappe.throw(_('{} {} is already linked with another {}')
.format(self.primary_role, self.primary_party, existing_party_link[0]))

View File

@@ -0,0 +1,8 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
# import frappe
import unittest
class TestPartyLink(unittest.TestCase):
pass

View File

@@ -413,6 +413,8 @@ class PurchaseInvoice(BuyingController):
self.update_project()
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
self.process_common_party_accounting()
def make_gl_entries(self, gl_entries=None, from_repost=False):
if not gl_entries:
gl_entries = self.get_gl_entries()

View File

@@ -247,7 +247,7 @@
"depends_on": "customer",
"fetch_from": "customer.customer_name",
"fieldname": "customer_name",
"fieldtype": "Data",
"fieldtype": "Small Text",
"hide_days": 1,
"hide_seconds": 1,
"in_global_search": 1,
@@ -692,10 +692,11 @@
{
"fieldname": "scan_barcode",
"fieldtype": "Data",
"options": "Barcode",
"hide_days": 1,
"hide_seconds": 1,
"label": "Scan Barcode"
"label": "Scan Barcode",
"length": 1,
"options": "Barcode"
},
{
"allow_bulk_edit": 1,
@@ -1059,6 +1060,7 @@
"hide_days": 1,
"hide_seconds": 1,
"label": "Apply Additional Discount On",
"length": 15,
"options": "\nGrand Total\nNet Total",
"print_hide": 1
},
@@ -1145,7 +1147,7 @@
{
"description": "In Words will be visible once you save the Sales Invoice.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"fieldtype": "Small Text",
"hide_days": 1,
"hide_seconds": 1,
"label": "In Words (Company Currency)",
@@ -1205,7 +1207,7 @@
},
{
"fieldname": "in_words",
"fieldtype": "Data",
"fieldtype": "Small Text",
"hide_days": 1,
"hide_seconds": 1,
"label": "In Words",
@@ -1558,6 +1560,7 @@
"hide_days": 1,
"hide_seconds": 1,
"label": "Print Language",
"length": 6,
"print_hide": 1,
"read_only": 1
},
@@ -1645,6 +1648,7 @@
"hide_seconds": 1,
"in_standard_filter": 1,
"label": "Status",
"length": 30,
"no_copy": 1,
"options": "\nDraft\nReturn\nCredit Note Issued\nSubmitted\nPaid\nUnpaid\nUnpaid and Discounted\nOverdue and Discounted\nOverdue\nCancelled\nInternal Transfer",
"print_hide": 1,
@@ -1704,6 +1708,7 @@
"hide_days": 1,
"hide_seconds": 1,
"label": "Is Opening Entry",
"length": 4,
"oldfieldname": "is_opening",
"oldfieldtype": "Select",
"options": "No\nYes",
@@ -1715,6 +1720,7 @@
"hide_days": 1,
"hide_seconds": 1,
"label": "C-Form Applicable",
"length": 4,
"no_copy": 1,
"options": "No\nYes",
"print_hide": 1
@@ -2017,7 +2023,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2021-08-18 16:07:45.122570",
"modified": "2021-08-25 14:46:05.279588",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@@ -253,6 +253,8 @@ class SalesInvoice(SellingController):
if "Healthcare" in active_domains:
manage_invoice_submit_cancel(self, "on_submit")
self.process_common_party_accounting()
def validate_pos_return(self):
if self.is_pos and self.is_return:

View File

@@ -148,7 +148,7 @@ class TestSalesInvoice(unittest.TestCase):
si1 = create_sales_invoice(rate=1000)
si2 = create_sales_invoice(rate=300)
si3 = create_sales_invoice(qty=-1, rate=300, is_return=1)
pe = get_payment_entry("Sales Invoice", si1.name, bank_account="_Test Bank - _TC")
pe.append('references', {
@@ -1107,6 +1107,18 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEqual(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"), 1500)
def test_incoming_rate_for_stand_alone_credit_note(self):
return_si = create_sales_invoice(is_return=1, update_stock=1, qty=-1, rate=90000, incoming_rate=10,
company='_Test Company with perpetual inventory', warehouse='Stores - TCP1', debit_to='Debtors - TCP1',
income_account='Sales - TCP1', expense_account='Cost of Goods Sold - TCP1', cost_center='Main - TCP1')
incoming_rate = frappe.db.get_value('Stock Ledger Entry', {'voucher_no': return_si.name}, 'incoming_rate')
debit_amount = frappe.db.get_value('GL Entry',
{'voucher_no': return_si.name, 'account': 'Stock In Hand - TCP1'}, 'debit')
self.assertEqual(debit_amount, 10.0)
self.assertEqual(incoming_rate, 10.0)
def test_discount_on_net_total(self):
si = frappe.copy_doc(test_records[2])
si.apply_discount_on = "Net Total"
@@ -1783,23 +1795,13 @@ class TestSalesInvoice(unittest.TestCase):
acc_settings.save()
def test_inter_company_transaction(self):
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
if not frappe.db.exists("Customer", "_Test Internal Customer"):
customer = frappe.get_doc({
"customer_group": "_Test Customer Group",
"customer_name": "_Test Internal Customer",
"customer_type": "Individual",
"doctype": "Customer",
"territory": "_Test Territory",
"is_internal_customer": 1,
"represents_company": "_Test Company 1"
})
customer.append("companies", {
"company": "Wind Power LLC"
})
customer.insert()
create_internal_customer(
customer_name="_Test Internal Customer",
represents_company="_Test Company 1",
allowed_to_interact_with="Wind Power LLC"
)
if not frappe.db.exists("Supplier", "_Test Internal Supplier"):
supplier = frappe.get_doc({
@@ -1842,8 +1844,43 @@ class TestSalesInvoice(unittest.TestCase):
self.assertEqual(target_doc.company, "_Test Company 1")
self.assertEqual(target_doc.supplier, "_Test Internal Supplier")
def test_sle_if_target_warehouse_exists_accidentally(self):
"""
Check if inward entry exists if Target Warehouse accidentally exists
but Customer is not an internal customer.
"""
se = make_stock_entry(
item_code="138-CMS Shoe",
target="Finished Goods - _TC",
company = "_Test Company",
qty=1,
basic_rate=500
)
si = frappe.copy_doc(test_records[0])
si.update_stock = 1
si.set_warehouse = "Finished Goods - _TC"
si.set_target_warehouse = "Stores - _TC"
si.get("items")[0].warehouse = "Finished Goods - _TC"
si.get("items")[0].target_warehouse = "Stores - _TC"
si.insert()
si.submit()
sles = frappe.get_all("Stock Ledger Entry", filters={"voucher_no": si.name},
fields=["name", "actual_qty"])
# check if only one SLE for outward entry is created
self.assertEqual(len(sles), 1)
self.assertEqual(sles[0].actual_qty, -1)
# tear down
si.cancel()
se.cancel()
def test_internal_transfer_gl_entry(self):
## Create internal transfer account
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
account = create_account(account_name="Unrealized Profit",
parent_account="Current Liabilities - TCP1", company="_Test Company with perpetual inventory")
@@ -2071,6 +2108,50 @@ class TestSalesInvoice(unittest.TestCase):
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1))
enable_discount_accounting(enable=0)
def test_sales_invoice_against_supplier(self):
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import make_customer
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
# create a customer
customer = make_customer(customer="_Test Common Supplier")
# create a supplier
supplier = create_supplier(supplier_name="_Test Common Supplier").name
# create a party link between customer & supplier
# set primary role as supplier
party_link = frappe.new_doc("Party Link")
party_link.primary_role = "Supplier"
party_link.primary_party = supplier
party_link.secondary_role = "Customer"
party_link.secondary_party = customer
party_link.save()
# enable common party accounting
frappe.db.set_value('Accounts Settings', None, 'enable_common_party_accounting', 1)
# create a sales invoice
si = create_sales_invoice(customer=customer, parent_cost_center="_Test Cost Center - _TC")
# check outstanding of sales invoice
si.reload()
self.assertEqual(si.status, 'Paid')
self.assertEqual(flt(si.outstanding_amount), 0.0)
# check creation of journal entry
jv = frappe.get_all('Journal Entry Account', {
'account': si.debit_to,
'party_type': 'Customer',
'party': si.customer,
'reference_type': si.doctype,
'reference_name': si.name
}, pluck='credit_in_account_currency')
self.assertTrue(jv)
self.assertEqual(jv[0], si.grand_total)
party_link.delete()
frappe.db.set_value('Accounts Settings', None, 'enable_common_party_accounting', 0)
def get_sales_invoice_for_e_invoice():
si = make_sales_invoice_for_ewaybill()
si.naming_series = 'INV-2020-.#####'
@@ -2283,7 +2364,8 @@ def create_sales_invoice(**args):
"discount_amount": args.discount_amount or 0,
"cost_center": args.cost_center or "_Test Cost Center - _TC",
"serial_no": args.serial_no,
"conversion_factor": 1
"conversion_factor": 1,
"incoming_rate": args.incoming_rate or 0
})
if not args.do_not_save:
@@ -2380,29 +2462,6 @@ def get_taxes_and_charges():
"row_id": 1
}]
def create_internal_customer(customer_name, represents_company, allowed_to_interact_with):
if not frappe.db.exists("Customer", customer_name):
customer = frappe.get_doc({
"customer_group": "_Test Customer Group",
"customer_name": customer_name,
"customer_type": "Individual",
"doctype": "Customer",
"territory": "_Test Territory",
"is_internal_customer": 1,
"represents_company": represents_company
})
customer.append("companies", {
"company": allowed_to_interact_with
})
customer.insert()
customer_name = customer.name
else:
customer_name = frappe.db.get_value("Customer", customer_name)
return customer_name
def create_internal_supplier(supplier_name, represents_company, allowed_to_interact_with):
if not frappe.db.exists("Supplier", supplier_name):
supplier = frappe.get_doc({

View File

@@ -53,7 +53,6 @@
"column_break_24",
"base_net_rate",
"base_net_amount",
"incoming_rate",
"drop_ship",
"delivered_by_supplier",
"accounting",
@@ -81,6 +80,7 @@
"target_warehouse",
"quality_inspection",
"batch_no",
"incoming_rate",
"col_break5",
"allow_zero_valuation_rate",
"serial_no",
@@ -808,12 +808,12 @@
"read_only": 1
},
{
"depends_on": "eval:parent.is_return && parent.update_stock && !parent.return_against",
"fieldname": "incoming_rate",
"fieldtype": "Currency",
"label": "Incoming Rate",
"label": "Incoming Rate (Costing)",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
"print_hide": 1
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
@@ -834,7 +834,7 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2021-08-12 20:15:42.668399",
"modified": "2021-08-19 13:41:53.435827",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
@@ -842,4 +842,4 @@
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}
}

View File

@@ -240,14 +240,15 @@ def get_deducted_tax(taxable_vouchers, fiscal_year, tax_details):
def get_tds_amount(ldc, parties, inv, tax_details, fiscal_year_details, tax_deducted, vouchers):
tds_amount = 0
invoice_filters = {
'name': ('in', vouchers),
'docstatus': 1
'name': ('in', vouchers),
'docstatus': 1,
'apply_tds': 1
}
field = 'sum(net_total)'
if not cint(tax_details.consider_party_ledger_amount):
invoice_filters.update({'apply_tds': 1})
if cint(tax_details.consider_party_ledger_amount):
invoice_filters.pop('apply_tds', None)
field = 'sum(grand_total)'
supp_credit_amt = frappe.db.get_value('Purchase Invoice', invoice_filters, field) or 0.0

View File

@@ -145,6 +145,36 @@ class TestTaxWithholdingCategory(unittest.TestCase):
for d in invoices:
d.cancel()
def test_tds_calculation_on_net_total(self):
frappe.db.set_value("Supplier", "Test TDS Supplier4", "tax_withholding_category", "Cumulative Threshold TDS")
invoices = []
pi = create_purchase_invoice(supplier = "Test TDS Supplier4", rate = 20000, do_not_save=True)
pi.append('taxes', {
"category": "Total",
"charge_type": "Actual",
"account_head": '_Test Account VAT - _TC',
"cost_center": 'Main - _TC',
"tax_amount": 1000,
"description": "Test",
"add_deduct_tax": "Add"
})
pi.save()
pi.submit()
invoices.append(pi)
# Second Invoice will apply TDS checked
pi1 = create_purchase_invoice(supplier = "Test TDS Supplier4", rate = 20000)
pi1.submit()
invoices.append(pi1)
self.assertEqual(pi1.taxes[0].tax_amount, 4000)
#delete invoices to avoid clashing
for d in invoices:
d.cancel()
def cancel_invoices():
purchase_invoices = frappe.get_all("Purchase Invoice", {
'supplier': ['in', ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2']],
@@ -220,7 +250,7 @@ def create_sales_invoice(**args):
def create_records():
# create a new suppliers
for name in ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2', 'Test TDS Supplier3']:
for name in ['Test TDS Supplier', 'Test TDS Supplier1', 'Test TDS Supplier2', 'Test TDS Supplier3', 'Test TDS Supplier4']:
if frappe.db.exists('Supplier', name):
continue

View File

@@ -59,7 +59,7 @@ def make_depreciation_entry(asset_name, date=None):
"credit_in_account_currency": d.depreciation_amount,
"reference_type": "Asset",
"reference_name": asset.name,
"cost_center": ""
"cost_center": depreciation_cost_center
}
debit_entry = {

View File

@@ -14,7 +14,7 @@ from erpnext.accounts.utils import get_fiscal_years, validate_fiscal_year, get_a
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.buying.utils import update_last_purchase_rate
from erpnext.controllers.sales_and_purchase_return import validate_return
from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled
from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled, get_party_account
from erpnext.accounts.doctype.pricing_rule.utils import (apply_pricing_rule_on_transaction,
apply_pricing_rule_for_free_items, get_applied_pricing_rules)
from erpnext.exceptions import InvalidCurrency
@@ -1368,6 +1368,67 @@ class AccountsController(TransactionBase):
return False
def process_common_party_accounting(self):
is_invoice = self.doctype in ['Sales Invoice', 'Purchase Invoice']
if not is_invoice:
return
if frappe.db.get_single_value('Accounts Settings', 'enable_common_party_accounting'):
party_link = self.get_common_party_link()
if party_link and self.outstanding_amount:
self.create_advance_and_reconcile(party_link)
def get_common_party_link(self):
party_type, party = self.get_party()
return frappe.db.get_value(
doctype='Party Link',
filters={'secondary_role': party_type, 'secondary_party': party},
fieldname=['primary_role', 'primary_party'],
as_dict=True
)
def create_advance_and_reconcile(self, party_link):
secondary_party_type, secondary_party = self.get_party()
primary_party_type, primary_party = party_link.primary_role, party_link.primary_party
primary_account = get_party_account(primary_party_type, primary_party, self.company)
secondary_account = get_party_account(secondary_party_type, secondary_party, self.company)
jv = frappe.new_doc('Journal Entry')
jv.voucher_type = 'Journal Entry'
jv.posting_date = self.posting_date
jv.company = self.company
jv.remark = 'Adjustment for {} {}'.format(self.doctype, self.name)
reconcilation_entry = frappe._dict()
advance_entry = frappe._dict()
reconcilation_entry.account = secondary_account
reconcilation_entry.party_type = secondary_party_type
reconcilation_entry.party = secondary_party
reconcilation_entry.reference_type = self.doctype
reconcilation_entry.reference_name = self.name
reconcilation_entry.cost_center = self.cost_center
advance_entry.account = primary_account
advance_entry.party_type = primary_party_type
advance_entry.party = primary_party
advance_entry.cost_center = self.cost_center
advance_entry.is_advance = 'Yes'
if self.doctype == 'Sales Invoice':
reconcilation_entry.credit_in_account_currency = self.outstanding_amount
advance_entry.debit_in_account_currency = self.outstanding_amount
else:
advance_entry.credit_in_account_currency = self.outstanding_amount
reconcilation_entry.debit_in_account_currency = self.outstanding_amount
jv.append('accounts', reconcilation_entry)
jv.append('accounts', advance_entry)
jv.save()
jv.submit()
@frappe.whitelist()
def get_tax_rate(account_head):
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)

View File

@@ -394,19 +394,6 @@ def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None
if not return_against:
return_against = frappe.get_cached_value(voucher_type, voucher_no, "return_against")
if not return_against and voucher_type == 'Sales Invoice' and sle:
return get_incoming_rate({
"item_code": sle.item_code,
"warehouse": sle.warehouse,
"posting_date": sle.get('posting_date'),
"posting_time": sle.get('posting_time'),
"qty": sle.actual_qty,
"serial_no": sle.get('serial_no'),
"company": sle.company,
"voucher_type": sle.voucher_type,
"voucher_no": sle.voucher_no
}, raise_error_if_no_rate=False)
return_against_item_field = get_return_against_item_fields(voucher_type)
filters = get_filters(voucher_type, voucher_no, voucher_detail_no,
@@ -417,7 +404,24 @@ def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None
else:
select_field = "abs(stock_value_difference / actual_qty)"
return flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field))
rate = flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field))
if not (rate and return_against) and voucher_type in ['Sales Invoice', 'Delivery Note']:
rate = frappe.db.get_value(f'{voucher_type} Item', voucher_detail_no, 'incoming_rate')
if not rate and sle:
rate = get_incoming_rate({
"item_code": sle.item_code,
"warehouse": sle.warehouse,
"posting_date": sle.get('posting_date'),
"posting_time": sle.get('posting_time'),
"qty": sle.actual_qty,
"serial_no": sle.get('serial_no'),
"company": sle.company,
"voucher_type": sle.voucher_type,
"voucher_no": sle.voucher_no
}, raise_error_if_no_rate=False)
return rate
def get_return_against_item_fields(voucher_type):
return_against_item_fields = {

View File

@@ -362,7 +362,7 @@ class SellingController(StockController):
sales_order.update_reserved_qty(so_item_rows)
def set_incoming_rate(self):
if self.doctype not in ("Delivery Note", "Sales Invoice", "Sales Order"):
if self.doctype not in ("Delivery Note", "Sales Invoice"):
return
items = self.get("items") + (self.get("packed_items") or [])
@@ -371,18 +371,19 @@ class SellingController(StockController):
# Get incoming rate based on original item cost based on valuation method
qty = flt(d.get('stock_qty') or d.get('actual_qty'))
d.incoming_rate = get_incoming_rate({
"item_code": d.item_code,
"warehouse": d.warehouse,
"posting_date": self.get('posting_date') or self.get('transaction_date'),
"posting_time": self.get('posting_time') or nowtime(),
"qty": qty if cint(self.get("is_return")) else (-1 * qty),
"serial_no": d.get('serial_no'),
"company": self.company,
"voucher_type": self.doctype,
"voucher_no": self.name,
"allow_zero_valuation": d.get("allow_zero_valuation")
}, raise_error_if_no_rate=False)
if not d.incoming_rate:
d.incoming_rate = get_incoming_rate({
"item_code": d.item_code,
"warehouse": d.warehouse,
"posting_date": self.get('posting_date') or self.get('transaction_date'),
"posting_time": self.get('posting_time') or nowtime(),
"qty": qty if cint(self.get("is_return")) else (-1 * qty),
"serial_no": d.get('serial_no'),
"company": self.company,
"voucher_type": self.doctype,
"voucher_no": self.name,
"allow_zero_valuation": d.get("allow_zero_valuation")
}, raise_error_if_no_rate=False)
# For internal transfers use incoming rate as the valuation rate
if self.is_internal_transfer():
@@ -422,7 +423,7 @@ class SellingController(StockController):
or (cint(self.is_return) and self.docstatus==2)):
sl_entries.append(self.get_sle_for_source_warehouse(d))
if d.target_warehouse:
if d.target_warehouse and self.get("is_internal_customer"):
sl_entries.append(self.get_sle_for_target_warehouse(d))
if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)

View File

@@ -86,7 +86,8 @@ status_map = {
],
"Bank Transaction": [
["Unreconciled", "eval:self.docstatus == 1 and self.unallocated_amount>0"],
["Reconciled", "eval:self.docstatus == 1 and self.unallocated_amount<=0"]
["Reconciled", "eval:self.docstatus == 1 and self.unallocated_amount<=0"],
["Cancelled", "eval:self.docstatus == 2"]
],
"POS Opening Entry": [
["Draft", None],

View File

@@ -95,9 +95,17 @@ frappe.ui.form.on("Opportunity", {
}, __('Create'));
}
frm.add_custom_button(__('Quotation'),
cur_frm.cscript.create_quotation, __('Create'));
if (frm.doc.opportunity_from != "Customer") {
frm.add_custom_button(__('Customer'),
function() {
frm.trigger("make_customer")
}, __('Create'));
}
frm.add_custom_button(__('Quotation'),
function() {
frm.trigger("create_quotation")
}, __('Create'));
}
if(!frm.doc.__islocal && frm.perm[0].write && frm.doc.docstatus==0) {
@@ -194,6 +202,13 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation",
frm: cur_frm
})
},
make_customer: function() {
frappe.model.open_mapped_doc({
method: "erpnext.crm.doctype.opportunity.opportunity.make_customer",
frm: cur_frm
})
}
});

View File

@@ -287,6 +287,24 @@ def make_request_for_quotation(source_name, target_doc=None):
return doclist
@frappe.whitelist()
def make_customer(source_name, target_doc=None):
def set_missing_values(source, target):
if source.opportunity_from == "Lead":
target.lead_name = source.party_name
doclist = get_mapped_doc("Opportunity", source_name, {
"Opportunity": {
"doctype": "Customer",
"field_map": {
"currency": "default_currency",
"customer_name": "customer_name"
}
}
}, target_doc, set_missing_values)
return doclist
@frappe.whitelist()
def make_supplier_quotation(source_name, target_doc=None):
doclist = get_mapped_doc("Opportunity", source_name, {

View File

@@ -4,8 +4,8 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import comma_and
from frappe import _, msgprint
from frappe.utils import flt, comma_and
from frappe.model.document import Document
from frappe.utils import unique
from erpnext.e_commerce.redisearch import create_website_items_index, ALLOWED_INDEXABLE_FIELDS_SET, is_search_module_loaded
@@ -25,7 +25,7 @@ class ECommerceSettings(Document):
self.validate_search_index_fields()
if self.enabled:
self.validate_exchange_rates_exist()
self.validate_price_list_exchange_rate()
frappe.clear_document_cache("E Commerce Settings", "E Commerce Settings")
@@ -75,44 +75,33 @@ class ECommerceSettings(Document):
if self.show_brand_line and not ("brand" in self.search_index_fields):
self.search_index_fields += ",brand"
def validate_exchange_rates_exist(self):
"""check if exchange rates exist for all Price List currencies (to company's currency)"""
company_currency = frappe.get_cached_value('Company', self.company, "default_currency")
def validate_price_list_exchange_rate(self):
"Check if exchange rate exists for Price List currency (to Company's currency)."
from erpnext.setup.utils import get_exchange_rate
if not self.enabled or not self.company or not self.price_list:
return # this function is also called from hooks, check values again
company_currency = frappe.get_cached_value("Company", self.company, "default_currency")
price_list_currency = frappe.db.get_value("Price List", self.price_list, "currency")
if not company_currency:
msgprint(_("Please specify currency in Company") + ": " + self.company,
raise_exception=ShoppingCartSetupError)
msg = f"Please specify currency in Company {self.company}"
frappe.throw(_(msg), title=_("Missing Currency"), exc=ShoppingCartSetupError)
price_list_currency_map = frappe.db.get_values("Price List",
[self.price_list], "currency")
if not price_list_currency:
msg = f"Please specify currency in Price List {frappe.bold(self.price_list)}"
frappe.throw(_(msg), title=_("Missing Currency"), exc=ShoppingCartSetupError)
price_list_currency_map = dict(price_list_currency_map)
if price_list_currency != company_currency:
from_currency, to_currency = price_list_currency, company_currency
# check if all price lists have a currency
for price_list, currency in price_list_currency_map.items():
if not currency:
frappe.throw(_("Currency is required for Price List {0}").format(price_list))
# Get exchange rate checks Currency Exchange Records too
exchange_rate = get_exchange_rate(from_currency, to_currency, args="for_selling")
expected_to_exist = [currency + "-" + company_currency
for currency in price_list_currency_map.values()
if currency != company_currency]
# manqala 20/09/2016: set up selection parameters for query from tabCurrency Exchange
from_currency = [currency for currency in price_list_currency_map.values() if currency != company_currency]
to_currency = company_currency
# manqala end
if expected_to_exist:
# manqala 20/09/2016: modify query so that it uses date in the selection from Currency Exchange.
# exchange rates defined with date less than the date on which this document is being saved will be selected
exists = frappe.db.sql_list("""select CONCAT(from_currency,'-',to_currency) from `tabCurrency Exchange`
where from_currency in (%s) and to_currency = "%s" and date <= curdate()""" % (", ".join(["%s"]*len(from_currency)), to_currency), tuple(from_currency))
# manqala end
missing = list(set(expected_to_exist).difference(exists))
if missing:
msgprint(_("Missing Currency Exchange Rates for {0}").format(comma_and(missing)),
raise_exception=ShoppingCartSetupError)
if not flt(exchange_rate):
msg = f"Missing Currency Exchange Rates for {from_currency}-{to_currency}"
frappe.throw(_(msg), title=_("Missing"), exc=ShoppingCartSetupError)
def validate_tax_rule(self):
if not frappe.db.get_value("Tax Rule", {"use_for_shopping_cart" : 1}, "name"):

View File

@@ -15,17 +15,25 @@ class TestECommerceSettings(unittest.TestCase):
return frappe.get_doc({"doctype": "E Commerce Settings",
"company": "_Test Company"})
def test_exchange_rate_exists(self):
frappe.db.sql("""delete from `tabCurrency Exchange`""")
# NOTE: Exchangrate API has all enabled currencies that ERPNext supports.
# We aren't checking just currency exchange record anymore
# while validating price list currency exchange rate to that of company.
# The API is being used to fetch the rate which again almost always
# gives back a valid value (for valid currencies).
# This makes the test obsolete.
# Commenting because im not sure if there's a better test we can write
cart_settings = self.get_cart_settings()
cart_settings.price_list = "_Test Price List Rest of the World"
self.assertRaises(ShoppingCartSetupError, cart_settings.validate_exchange_rates_exist)
# def test_exchange_rate_exists(self):
# frappe.db.sql("""delete from `tabCurrency Exchange`""")
from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
currency_exchange_records
frappe.get_doc(currency_exchange_records[0]).insert()
cart_settings.validate_exchange_rates_exist()
# cart_settings = self.get_cart_settings()
# cart_settings.price_list = "_Test Price List Rest of the World"
# self.assertRaises(ShoppingCartSetupError, cart_settings.validate_price_list_exchange_rate)
# from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \
# currency_exchange_records
# frappe.get_doc(currency_exchange_records[0]).insert()
# cart_settings.validate_price_list_exchange_rate()
def test_tax_rule_validation(self):
frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0")

View File

@@ -46,13 +46,13 @@
{
"fieldname": "visited",
"fieldtype": "Int",
"label": "Visited yet",
"label": "Visits Completed",
"read_only": 1
},
{
"fieldname": "valid_till",
"fieldtype": "Date",
"label": "Valid till",
"label": "Valid Till",
"read_only": 1
},
{
@@ -106,7 +106,7 @@
],
"in_create": 1,
"links": [],
"modified": "2020-03-17 20:25:06.487418",
"modified": "2021-08-26 10:51:05.609349",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Fee Validity",

View File

@@ -11,7 +11,6 @@ import datetime
class FeeValidity(Document):
def validate(self):
self.update_status()
self.set_start_date()
def update_status(self):
if self.visited >= self.max_visits:
@@ -19,13 +18,6 @@ class FeeValidity(Document):
else:
self.status = 'Pending'
def set_start_date(self):
self.start_date = getdate()
for appointment in self.ref_appointments:
appointment_date = frappe.db.get_value('Patient Appointment', appointment.appointment, 'appointment_date')
if getdate(appointment_date) < self.start_date:
self.start_date = getdate(appointment_date)
def create_fee_validity(appointment):
if not check_is_new_patient(appointment):
@@ -36,11 +28,9 @@ def create_fee_validity(appointment):
fee_validity.patient = appointment.patient
fee_validity.max_visits = frappe.db.get_single_value('Healthcare Settings', 'max_visits') or 1
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days') or 1
fee_validity.visited = 1
fee_validity.visited = 0
fee_validity.start_date = getdate(appointment.appointment_date)
fee_validity.valid_till = getdate(appointment.appointment_date) + datetime.timedelta(days=int(valid_days))
fee_validity.append('ref_appointments', {
'appointment': appointment.name
})
fee_validity.save(ignore_permissions=True)
return fee_validity

View File

@@ -22,17 +22,17 @@ class TestFeeValidity(unittest.TestCase):
item = create_healthcare_service_items()
healthcare_settings = frappe.get_single("Healthcare Settings")
healthcare_settings.enable_free_follow_ups = 1
healthcare_settings.max_visits = 2
healthcare_settings.max_visits = 1
healthcare_settings.valid_days = 7
healthcare_settings.automate_appointment_invoicing = 1
healthcare_settings.op_consulting_charge_item = item
healthcare_settings.save(ignore_permissions=True)
patient, practitioner = create_healthcare_docs()
# appointment should not be invoiced. Check Fee Validity created for new patient
# For first appointment, invoice is generated. First appointment not considered in fee validity
appointment = create_appointment(patient, practitioner, nowdate())
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
self.assertEqual(invoiced, 0)
self.assertEqual(invoiced, 1)
# appointment should not be invoiced as it is within fee validity
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4))

View File

@@ -282,7 +282,7 @@
],
"image_field": "image",
"links": [],
"modified": "2021-01-22 10:14:43.187675",
"modified": "2021-08-24 10:42:08.513054",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Practitioner",
@@ -295,6 +295,7 @@
"read": 1,
"report": 1,
"role": "Laboratory User",
"select": 1,
"share": 1,
"write": 1
},
@@ -307,6 +308,7 @@
"read": 1,
"report": 1,
"role": "Physician",
"select": 1,
"share": 1,
"write": 1
},
@@ -319,6 +321,7 @@
"read": 1,
"report": 1,
"role": "Nursing User",
"select": 1,
"share": 1,
"write": 1
}

View File

@@ -241,6 +241,13 @@ frappe.ui.form.on('Patient Appointment', {
frm.toggle_reqd('mode_of_payment', 0);
frm.toggle_reqd('paid_amount', 0);
frm.toggle_reqd('billing_item', 0);
} else if (data.message) {
frm.toggle_display('mode_of_payment', 1);
frm.toggle_display('paid_amount', 1);
frm.toggle_display('billing_item', 1);
frm.toggle_reqd('mode_of_payment', 1);
frm.toggle_reqd('paid_amount', 1);
frm.toggle_reqd('billing_item', 1);
} else {
// if automated appointment invoicing is disabled, hide fields
frm.toggle_display('mode_of_payment', data.message ? 1 : 0);

View File

@@ -134,6 +134,7 @@
"read_only": 1
},
{
"depends_on": "eval:doc.practitioner;",
"fieldname": "section_break_12",
"fieldtype": "Section Break",
"label": "Appointment Details"
@@ -141,7 +142,6 @@
{
"fieldname": "practitioner",
"fieldtype": "Link",
"ignore_user_permissions": 1,
"in_standard_filter": 1,
"label": "Healthcare Practitioner",
"options": "Healthcare Practitioner",
@@ -400,4 +400,4 @@
"title_field": "title",
"track_changes": 1,
"track_seen": 1
}
}

View File

@@ -137,9 +137,13 @@ class PatientAppointment(Document):
frappe.db.set_value('Patient Appointment', self.name, 'notes', comments)
def update_fee_validity(self):
if not frappe.db.get_single_value('Healthcare Settings', 'enable_free_follow_ups'):
return
fee_validity = manage_fee_validity(self)
if fee_validity:
frappe.msgprint(_('{0} has fee validity till {1}').format(self.patient, fee_validity.valid_till))
frappe.msgprint(_('{0}: {1} has fee validity till {2}').format(self.patient,
frappe.bold(self.patient_name), fee_validity.valid_till))
@frappe.whitelist()
def get_therapy_types(self):
@@ -163,8 +167,6 @@ def check_payment_fields_reqd(patient):
fee_validity = frappe.db.exists('Fee Validity', {'patient': patient, 'status': 'Pending'})
if fee_validity:
return {'fee_validity': fee_validity}
if check_is_new_patient(patient):
return False
return True
return False
@@ -179,8 +181,6 @@ def invoice_appointment(appointment_doc):
elif not fee_validity:
if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
return
if check_is_new_patient(appointment_doc.patient, appointment_doc.name):
return
else:
fee_validity = None
@@ -224,9 +224,7 @@ def check_is_new_patient(patient, name=None):
filters['name'] = ('!=', name)
has_previous_appointment = frappe.db.exists('Patient Appointment', filters)
if has_previous_appointment:
return False
return True
return not has_previous_appointment
def get_appointment_item(appointment_doc, item):

View File

@@ -4,11 +4,12 @@
from __future__ import unicode_literals
import unittest
import frappe
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import update_status, make_encounter
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import update_status, make_encounter, check_payment_fields_reqd, check_is_new_patient
from frappe.utils import nowdate, add_days, now_datetime
from frappe.utils.make_random import get_random
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
class TestPatientAppointment(unittest.TestCase):
def setUp(self):
frappe.db.sql("""delete from `tabPatient Appointment`""")
@@ -109,18 +110,21 @@ class TestPatientAppointment(unittest.TestCase):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 1)
appointment = create_appointment(patient, practitioner, nowdate())
fee_validity = frappe.db.get_value('Fee Validity Reference', {'appointment': appointment.name}, 'parent')
fee_validity = frappe.db.get_value('Fee Validity', {'patient': patient, 'practitioner': practitioner})
# fee validity created
self.assertTrue(fee_validity)
visited = frappe.db.get_value('Fee Validity', fee_validity, 'visited')
# first follow up appointment
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 1))
self.assertEqual(frappe.db.get_value('Fee Validity', fee_validity, 'visited'), 1)
update_status(appointment.name, 'Cancelled')
# check fee validity updated
self.assertEqual(frappe.db.get_value('Fee Validity', fee_validity, 'visited'), visited - 1)
self.assertEqual(frappe.db.get_value('Fee Validity', fee_validity, 'visited'), 0)
frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 0)
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
appointment = create_appointment(patient, practitioner, nowdate(), invoice=1)
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 1), invoice=1)
update_status(appointment.name, 'Cancelled')
# check invoice cancelled
sales_invoice_name = frappe.db.get_value('Sales Invoice Item', {'reference_dn': appointment.name}, 'parent')
@@ -179,6 +183,28 @@ class TestPatientAppointment(unittest.TestCase):
mark_invoiced_inpatient_occupancy(ip_record1)
discharge_patient(ip_record1, now_datetime())
def test_payment_should_be_mandatory_for_new_patient_appointment(self):
frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 1)
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
frappe.db.set_value('Healthcare Settings', None, 'max_visits', 3)
frappe.db.set_value('Healthcare Settings', None, 'valid_days', 30)
patient = create_patient()
assert check_is_new_patient(patient)
payment_required = check_payment_fields_reqd(patient)
assert payment_required is True
def test_sales_invoice_should_be_generated_for_new_patient_appointment(self):
patient, practitioner = create_healthcare_docs()
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
invoice_count = frappe.db.count('Sales Invoice')
assert check_is_new_patient(patient)
create_appointment(patient, practitioner, nowdate())
new_invoice_count = frappe.db.count('Sales Invoice')
assert new_invoice_count == invoice_count + 1
def test_overlap_appointment(self):
from erpnext.healthcare.doctype.patient_appointment.patient_appointment import OverlapError
patient, practitioner = create_healthcare_docs(id=1)
@@ -228,6 +254,27 @@ class TestPatientAppointment(unittest.TestCase):
appointment = create_appointment(patient, practitioner, nowdate(), service_unit=overlap_service_unit, save=0)
self.assertRaises(MaximumCapacityError, appointment.save)
def test_patient_appointment_should_consider_permissions_while_fetching_appointments(self):
patient, practitioner = create_healthcare_docs()
create_appointment(patient, practitioner, nowdate())
patient, new_practitioner = create_healthcare_docs(id=2)
create_appointment(patient, new_practitioner, nowdate())
roles = [{"doctype": "Has Role", "role": "Physician"}]
user = create_user(roles=roles)
new_practitioner = frappe.get_doc('Healthcare Practitioner', new_practitioner)
new_practitioner.user_id = user.email
new_practitioner.save()
frappe.set_user(user.name)
appointments = frappe.get_list('Patient Appointment')
assert len(appointments) == 1
frappe.set_user("Administrator")
appointments = frappe.get_list('Patient Appointment')
assert len(appointments) == 2
def create_healthcare_docs(id=0):
patient = create_patient(id)
@@ -275,7 +322,6 @@ def create_practitioner(id=0, medical_department=None):
return practitioner.name
def create_encounter(appointment):
if appointment:
encounter = frappe.new_doc('Patient Encounter')
@@ -290,7 +336,6 @@ def create_encounter(appointment):
return encounter
def create_appointment(patient, practitioner, appointment_date, invoice=0, procedure_template=0,
service_unit=None, appointment_type=None, save=1, department=None):
item = create_healthcare_service_items()
@@ -400,3 +445,17 @@ def create_service_unit(id=0, service_unit_type=None, service_unit_capacity=0):
service_unit.save(ignore_permissions=True)
return service_unit.name
def create_user(email=None, roles=None):
if not email:
email = '{}@frappe.com'.format(frappe.utils.random_string(10))
user = frappe.db.exists('User', email)
if not user:
user = frappe.get_doc({
"doctype": "User",
"email": email,
"first_name": "test_user",
"password": "password",
"roles": roles,
}).insert()
return user

View File

@@ -243,7 +243,7 @@ doc_events = {
"on_update": ["erpnext.hr.doctype.employee.employee.update_user_permissions",
"erpnext.portal.utils.set_default_role"]
},
("Sales Taxes and Charges Template", 'Price List'): {
"Sales Taxes and Charges Template": {
"on_update": "erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings.validate_cart_settings"
},
"Tax Category": {
@@ -441,6 +441,7 @@ regional_overrides = {
'erpnext.controllers.taxes_and_totals.get_regional_round_off_accounts': 'erpnext.regional.india.utils.get_regional_round_off_accounts',
'erpnext.hr.utils.calculate_annual_eligible_hra_exemption': 'erpnext.regional.india.utils.calculate_annual_eligible_hra_exemption',
'erpnext.hr.utils.calculate_hra_exemption_for_period': 'erpnext.regional.india.utils.calculate_hra_exemption_for_period',
'erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_regional_gl_entries': 'erpnext.regional.india.utils.make_regional_gl_entries',
'erpnext.controllers.accounts_controller.validate_einvoice_fields': 'erpnext.regional.india.e_invoice.utils.validate_einvoice_fields',
'erpnext.assets.doctype.asset.asset.get_depreciation_amount': 'erpnext.regional.india.utils.get_depreciation_amount',
'erpnext.stock.doctype.item.item.set_item_tax_from_hsn_code': 'erpnext.regional.india.utils.set_item_tax_from_hsn_code'

View File

@@ -446,6 +446,11 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) {
},
callback: function(r) {
d = locals[cdt][cdn];
if (d.is_process_loss) {
r.message.rate = 0;
r.message.base_rate = 0;
}
$.extend(d, r.message);
refresh_field("items");
refresh_field("scrap_items");
@@ -655,3 +660,35 @@ frappe.ui.form.on("BOM", "with_operations", function(frm) {
frm.set_value("operations", []);
}
});
frappe.ui.form.on("BOM Scrap Item", {
item_code(frm, cdt, cdn) {
const { item_code } = locals[cdt][cdn];
if (item_code === frm.doc.item) {
locals[cdt][cdn].is_process_loss = 1;
trigger_process_loss_qty_prompt(frm, cdt, cdn, item_code);
}
},
});
function trigger_process_loss_qty_prompt(frm, cdt, cdn, item_code) {
frappe.prompt(
{
fieldname: "percent",
fieldtype: "Percent",
label: __("% Finished Item Quantity"),
description:
__("Set quantity of process loss item:") +
` ${item_code} ` +
__("as a percentage of finished item quantity"),
},
(data) => {
const row = locals[cdt][cdn];
row.stock_qty = (frm.doc.quantity * data.percent) / 100;
row.qty = row.stock_qty / (row.conversion_factor || 1);
refresh_field("scrap_items");
},
__("Set Process Loss Item Quantity"),
__("Set Quantity")
);
}

View File

@@ -154,9 +154,11 @@ class BOM(WebsiteGenerator):
self.validate_operations()
self.calculate_cost()
self.update_stock_qty()
self.validate_scrap_items()
self.update_cost(update_parent=False, from_child_bom=True, update_hour_rate = False, save=False)
self.set_bom_level()
def get_context(self, context):
context.parents = [{'name': 'boms', 'title': _('All BOMs') }]
@@ -230,7 +232,7 @@ class BOM(WebsiteGenerator):
}
ret = self.get_bom_material_detail(args)
for key, value in ret.items():
if not item.get(key):
if item.get(key) is None:
item.set(key, value)
@frappe.whitelist()
@@ -687,6 +689,33 @@ class BOM(WebsiteGenerator):
if not d.batch_size or d.batch_size <= 0:
d.batch_size = 1
def validate_scrap_items(self):
for item in self.scrap_items:
msg = ""
if item.item_code == self.item and not item.is_process_loss:
msg = _('Scrap/Loss Item: {0} should have Is Process Loss checked as it is the same as the item to be manufactured or repacked.') \
.format(frappe.bold(item.item_code))
elif item.item_code != self.item and item.is_process_loss:
msg = _('Scrap/Loss Item: {0} should not have Is Process Loss checked as it is different from the item to be manufactured or repacked') \
.format(frappe.bold(item.item_code))
must_be_whole_number = frappe.get_value("UOM", item.stock_uom, "must_be_whole_number")
if item.is_process_loss and must_be_whole_number:
msg = _("Item: {0} with Stock UOM: {1} cannot be a Scrap/Loss Item as {1} is a whole UOM.") \
.format(frappe.bold(item.item_code), frappe.bold(item.stock_uom))
if item.is_process_loss and (item.stock_qty >= self.quantity):
msg = _("Scrap/Loss Item: {0} should have Qty less than finished goods Quantity.") \
.format(frappe.bold(item.item_code))
if item.is_process_loss and (item.rate > 0):
msg = _("Scrap/Loss Item: {0} should have Rate set to 0 because Is Process Loss is checked.") \
.format(frappe.bold(item.item_code))
if msg:
frappe.throw(msg, title=_("Note"))
def get_tree_representation(self) -> BOMTree:
"""Get a complete tree representation preserving order of child items."""
return BOMTree(self.name)
@@ -822,8 +851,11 @@ def get_bom_items_as_dict(bom, company, qty=1, fetch_exploded=1, fetch_scrap_ite
items = frappe.db.sql(query, { "parent": bom, "qty": qty, "bom": bom, "company": company }, as_dict=True)
elif fetch_scrap_items:
query = query.format(table="BOM Scrap Item", where_conditions="",
select_columns=", bom_item.idx, item.description", is_stock_item=is_stock_item, qty_field="stock_qty")
query = query.format(
table="BOM Scrap Item", where_conditions="",
select_columns=", bom_item.idx, item.description, is_process_loss",
is_stock_item=is_stock_item, qty_field="stock_qty"
)
items = frappe.db.sql(query, { "qty": qty, "bom": bom, "company": company }, as_dict=True)
else:

View File

@@ -226,6 +226,40 @@ class TestBOM(unittest.TestCase):
supplied_items = sorted([d.rm_item_code for d in po.supplied_items])
self.assertEqual(bom_items, supplied_items)
def test_bom_with_process_loss_item(self):
fg_item_non_whole, fg_item_whole, bom_item = create_process_loss_bom_items()
if not frappe.db.exists("BOM", f"BOM-{fg_item_non_whole.item_code}-001"):
bom_doc = create_bom_with_process_loss_item(
fg_item_non_whole, bom_item, scrap_qty=0.25, scrap_rate=0, fg_qty=1
)
bom_doc.submit()
bom_doc = create_bom_with_process_loss_item(
fg_item_non_whole, bom_item, scrap_qty=2, scrap_rate=0
)
# PL Item qty can't be >= FG Item qty
self.assertRaises(frappe.ValidationError, bom_doc.submit)
bom_doc = create_bom_with_process_loss_item(
fg_item_non_whole, bom_item, scrap_qty=1, scrap_rate=100
)
# PL Item rate has to be 0
self.assertRaises(frappe.ValidationError, bom_doc.submit)
bom_doc = create_bom_with_process_loss_item(
fg_item_whole, bom_item, scrap_qty=0.25, scrap_rate=0
)
# Items with whole UOMs can't be PL Items
self.assertRaises(frappe.ValidationError, bom_doc.submit)
bom_doc = create_bom_with_process_loss_item(
fg_item_non_whole, bom_item, scrap_qty=0.25, scrap_rate=0, is_process_loss=0
)
# FG Items in Scrap/Loss Table should have Is Process Loss set
self.assertRaises(frappe.ValidationError, bom_doc.submit)
def test_bom_tree_representation(self):
bom_tree = {
"Assembly": {
@@ -248,13 +282,9 @@ class TestBOM(unittest.TestCase):
for reqd_item, created_item in zip(reqd_order, created_order):
self.assertEqual(reqd_item, created_item.item_code)
def get_default_bom(item_code="_Test FG Item 2"):
return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1})
def level_order_traversal(node):
traversal = []
q = deque()
@@ -300,6 +330,7 @@ def create_nested_bom(tree, prefix="_Test bom "):
bom = frappe.get_doc(doctype="BOM", item=bom_item_code)
for child_item in child_items.keys():
bom.append("items", {"item_code": prefix + child_item})
bom.currency = "INR"
bom.insert()
bom.submit()
@@ -321,3 +352,45 @@ def reset_item_valuation_rate(item_code, warehouse_list=None, qty=None, rate=Non
for warehouse in warehouse_list:
create_stock_reconciliation(item_code=item_code, warehouse=warehouse, qty=qty, rate=rate)
def create_bom_with_process_loss_item(
fg_item, bom_item, scrap_qty, scrap_rate, fg_qty=2, is_process_loss=1):
bom_doc = frappe.new_doc("BOM")
bom_doc.item = fg_item.item_code
bom_doc.quantity = fg_qty
bom_doc.append("items", {
"item_code": bom_item.item_code,
"qty": 1,
"uom": bom_item.stock_uom,
"stock_uom": bom_item.stock_uom,
"rate": 100.0
})
bom_doc.append("scrap_items", {
"item_code": fg_item.item_code,
"qty": scrap_qty,
"stock_qty": scrap_qty,
"uom": fg_item.stock_uom,
"stock_uom": fg_item.stock_uom,
"rate": scrap_rate,
"is_process_loss": is_process_loss
})
bom_doc.currency = "INR"
return bom_doc
def create_process_loss_bom_items():
item_list = [
("_Test Item - Non Whole UOM", "Kg"),
("_Test Item - Whole UOM", "Unit"),
("_Test PL BOM Item", "Unit")
]
return [create_process_loss_bom_item(it) for it in item_list]
def create_process_loss_bom_item(item_tuple):
item_code, stock_uom = item_tuple
if frappe.db.exists("Item", item_code) is None:
return make_item(
item_code,
{'stock_uom':stock_uom, 'valuation_rate':100}
)
else:
return frappe.get_doc("Item", item_code)

View File

@@ -1,345 +1,112 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2016-09-26 02:19:21.642081",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"actions": [],
"creation": "2016-09-26 02:19:21.642081",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"item_code",
"column_break_2",
"item_name",
"is_process_loss",
"quantity_and_rate",
"stock_qty",
"rate",
"amount",
"column_break_6",
"stock_uom",
"base_rate",
"base_amount"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "item_code",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Item Code",
"length": 0,
"no_copy": 0,
"options": "Item",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "item_code",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Item Code",
"options": "Item",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "item_name",
"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": "Item 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": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "item_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Item Name"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"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": "Quantity and Rate",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "stock_qty",
"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": "Qty",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "stock_qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Qty",
"reqd": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "rate",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Rate",
"length": 0,
"no_copy": 0,
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Rate",
"options": "currency"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "amount",
"fieldtype": "Currency",
"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": "Amount",
"length": 0,
"no_copy": 0,
"options": "currency",
"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,
"unique": 0
},
"fieldname": "amount",
"fieldtype": "Currency",
"label": "Amount",
"options": "currency",
"read_only": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "column_break_6",
"fieldtype": "Column Break",
"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,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
"fieldname": "column_break_6",
"fieldtype": "Column Break"
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "stock_uom",
"fieldtype": "Link",
"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": "Stock UOM",
"length": 0,
"no_copy": 0,
"options": "UOM",
"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,
"unique": 0
},
"fieldname": "stock_uom",
"fieldtype": "Link",
"label": "Stock UOM",
"options": "UOM",
"read_only": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "base_rate",
"fieldtype": "Currency",
"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": "Basic Rate (Company Currency)",
"length": 0,
"no_copy": 0,
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"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,
"unique": 0
},
"fieldname": "base_rate",
"fieldtype": "Currency",
"label": "Basic Rate (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "base_amount",
"fieldtype": "Currency",
"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": "Basic Amount (Company Currency)",
"length": 0,
"no_copy": 0,
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"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,
"unique": 0
"fieldname": "base_amount",
"fieldtype": "Currency",
"label": "Basic Amount (Company Currency)",
"options": "Company:company:default_currency",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_2",
"fieldtype": "Column Break"
},
{
"default": "0",
"fieldname": "is_process_loss",
"fieldtype": "Check",
"label": "Is Process Loss"
}
],
"has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-07-04 16:04:32.442287",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM Scrap Item",
"name_case": "",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1,
"track_seen": 0
],
"istable": 1,
"links": [],
"modified": "2021-06-22 16:46:12.153311",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM Scrap Item",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@@ -26,17 +26,17 @@ class JobCard(Document):
self.set_status()
self.validate_operation_id()
self.validate_sequence_id()
self.get_sub_operations()
self.set_sub_operations()
self.update_sub_operation_status()
def get_sub_operations(self):
def set_sub_operations(self):
if self.operation:
self.sub_operations = []
for row in frappe.get_all("Sub Operation",
filters = {"parent": self.operation}, fields=["operation", "idx"]):
row.status = "Pending"
for row in frappe.get_all('Sub Operation',
filters = {'parent': self.operation}, fields=['operation', 'idx'], order_by='idx'):
row.status = 'Pending'
row.sub_operation = row.operation
self.append("sub_operations", row)
self.append('sub_operations', row)
def validate_time_logs(self):
self.total_time_in_mins = 0.0
@@ -690,7 +690,7 @@ def make_corrective_job_card(source_name, operation=None, for_operation=None, ta
target.set('time_logs', [])
target.set('employee', [])
target.set('items', [])
target.get_sub_operations()
target.set_sub_operations()
target.get_required_items()
target.validate_time_logs()

View File

@@ -690,6 +690,71 @@ class TestWorkOrder(unittest.TestCase):
self.assertRaises(frappe.ValidationError, make_stock_entry, wo.name, 'Material Transfer for Manufacture')
def test_wo_completion_with_pl_bom(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_process_loss_bom_items
from erpnext.manufacturing.doctype.bom.test_bom import create_bom_with_process_loss_item
qty = 4
scrap_qty = 0.25 # bom item qty = 1, consider as 25% of FG
source_warehouse = "Stores - _TC"
wip_warehouse = "_Test Warehouse - _TC"
fg_item_non_whole, _, bom_item = create_process_loss_bom_items()
test_stock_entry.make_stock_entry(item_code=bom_item.item_code,
target=source_warehouse, qty=4, basic_rate=100)
bom_no = f"BOM-{fg_item_non_whole.item_code}-001"
if not frappe.db.exists("BOM", bom_no):
bom_doc = create_bom_with_process_loss_item(
fg_item_non_whole, bom_item, scrap_qty=scrap_qty,
scrap_rate=0, fg_qty=1, is_process_loss=1
)
bom_doc.submit()
wo = make_wo_order_test_record(
production_item=fg_item_non_whole.item_code,
bom_no=bom_no,
wip_warehouse=wip_warehouse,
qty=qty,
skip_transfer=1,
stock_uom=fg_item_non_whole.stock_uom,
)
se = frappe.get_doc(
make_stock_entry(wo.name, "Material Transfer for Manufacture", qty)
)
se.get("items")[0].s_warehouse = "Stores - _TC"
se.insert()
se.submit()
se = frappe.get_doc(
make_stock_entry(wo.name, "Manufacture", qty)
)
se.insert()
se.submit()
# Testing stock entry values
items = se.get("items")
self.assertEqual(len(items), 3, "There should be 3 items including process loss.")
source_item, fg_item, pl_item = items
total_pl_qty = qty * scrap_qty
actual_fg_qty = qty - total_pl_qty
self.assertEqual(pl_item.qty, total_pl_qty)
self.assertEqual(fg_item.qty, actual_fg_qty)
# Testing Work Order values
self.assertEqual(
frappe.db.get_value("Work Order", wo.name, "produced_qty"),
qty
)
self.assertEqual(
frappe.db.get_value("Work Order", wo.name, "process_loss_qty"),
total_pl_qty
)
def get_scrap_item_details(bom_no):
scrap_items = {}
for item in frappe.db.sql("""select item_code, stock_qty from `tabBOM Scrap Item`

View File

@@ -19,6 +19,7 @@
"qty",
"material_transferred_for_manufacturing",
"produced_qty",
"process_loss_qty",
"sales_order",
"project",
"serial_no_and_batch_for_finished_good_section",
@@ -64,16 +65,12 @@
"description",
"stock_uom",
"column_break2",
"references_section",
"material_request",
"material_request_item",
"sales_order_item",
"column_break_61",
"production_plan",
"production_plan_item",
"production_plan_sub_assembly_item",
"parent_work_order",
"bom_level",
"product_bundle_item",
"amended_from"
],
@@ -553,20 +550,29 @@
"read_only": 1
},
{
"fieldname": "production_plan_sub_assembly_item",
"fieldtype": "Data",
"label": "Production Plan Sub-assembly Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
}
"fieldname": "production_plan_sub_assembly_item",
"fieldtype": "Data",
"label": "Production Plan Sub-assembly Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
},
{
"depends_on": "eval: doc.process_loss_qty",
"fieldname": "process_loss_qty",
"fieldtype": "Float",
"label": "Process Loss Qty",
"no_copy": 1,
"non_negative": 1,
"read_only": 1
}
],
"icon": "fa fa-cogs",
"idx": 1,
"image_field": "image",
"is_submittable": 1,
"links": [],
"modified": "2021-06-28 16:19:14.902699",
"modified": "2021-08-24 15:14:03.844937",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Work Order",

View File

@@ -214,6 +214,7 @@ class WorkOrder(Document):
self.meta.get_label(fieldname), qty, completed_qty, self.name), StockOverProductionError)
self.db_set(fieldname, qty)
self.set_process_loss_qty()
from erpnext.selling.doctype.sales_order.sales_order import update_produced_qty_in_so_item
@@ -223,6 +224,22 @@ class WorkOrder(Document):
if self.production_plan:
self.update_production_plan_status()
def set_process_loss_qty(self):
process_loss_qty = flt(frappe.db.sql("""
SELECT sum(qty) FROM `tabStock Entry Detail`
WHERE
is_process_loss=1
AND parent IN (
SELECT name FROM `tabStock Entry`
WHERE
work_order=%s
AND purpose='Manufacture'
AND docstatus=1
)
""", (self.name, ))[0][0])
if process_loss_qty is not None:
self.db_set('process_loss_qty', process_loss_qty)
def update_production_plan_status(self):
production_plan = frappe.get_doc('Production Plan', self.production_plan)
produced_qty = 0

View File

@@ -33,6 +33,14 @@ def get_datev_csv(data, filters, csv_class):
if csv_class.DATA_CATEGORY == DataCategory.TRANSACTIONS:
result['Belegdatum'] = pd.to_datetime(result['Belegdatum'])
result['Beleginfo - Inhalt 6'] = pd.to_datetime(result['Beleginfo - Inhalt 6'])
result['Beleginfo - Inhalt 6'] = result['Beleginfo - Inhalt 6'].dt.strftime('%d%m%Y')
result['Fälligkeit'] = pd.to_datetime(result['Fälligkeit'])
result['Fälligkeit'] = result['Fälligkeit'].dt.strftime('%d%m%y')
result.sort_values(by='Belegdatum', inplace=True, kind='stable', ignore_index=True)
if csv_class.DATA_CATEGORY == DataCategory.ACCOUNT_NAMES:
result['Sprach-ID'] = 'de-DE'

View File

@@ -43,6 +43,12 @@ COLUMNS = [
"fieldtype": "Data",
"width": 100
},
{
"label": "BU-Schlüssel",
"fieldname": "BU-Schlüssel",
"fieldtype": "Data",
"width": 100
},
{
"label": "Belegdatum",
"fieldname": "Belegdatum",
@@ -114,6 +120,36 @@ COLUMNS = [
"fieldname": "Beleginfo - Inhalt 4",
"fieldtype": "Data",
"width": 150
},
{
"label": "Beleginfo - Art 5",
"fieldname": "Beleginfo - Art 5",
"fieldtype": "Data",
"width": 150
},
{
"label": "Beleginfo - Inhalt 5",
"fieldname": "Beleginfo - Inhalt 5",
"fieldtype": "Data",
"width": 100
},
{
"label": "Beleginfo - Art 6",
"fieldname": "Beleginfo - Art 6",
"fieldtype": "Data",
"width": 150
},
{
"label": "Beleginfo - Inhalt 6",
"fieldname": "Beleginfo - Inhalt 6",
"fieldtype": "Date",
"width": 100
},
{
"label": "Fälligkeit",
"fieldname": "Fälligkeit",
"fieldtype": "Date",
"width": 100
}
]
@@ -161,6 +197,125 @@ def validate_fiscal_year(from_date, to_date, company):
def get_transactions(filters, as_dict=1):
def run(params_method, filters):
extra_fields, extra_joins, extra_filters = params_method(filters)
return run_query(filters, extra_fields, extra_joins, extra_filters, as_dict=as_dict)
def sort_by(row):
# "Belegdatum" is in the fifth column when list format is used
return row["Belegdatum" if as_dict else 5]
type_map = {
# specific query methods for some voucher types
"Payment Entry": get_payment_entry_params,
"Sales Invoice": get_sales_invoice_params,
"Purchase Invoice": get_purchase_invoice_params
}
only_voucher_type = filters.get("voucher_type")
transactions = []
for voucher_type, get_voucher_params in type_map.items():
if only_voucher_type and only_voucher_type != voucher_type:
continue
transactions.extend(run(params_method=get_voucher_params, filters=filters))
if not only_voucher_type or only_voucher_type not in type_map:
# generic query method for all other voucher types
filters["exclude_voucher_types"] = type_map.keys()
transactions.extend(run(params_method=get_generic_params, filters=filters))
return sorted(transactions, key=sort_by)
def get_payment_entry_params(filters):
extra_fields = """
, 'Zahlungsreferenz' as 'Beleginfo - Art 5'
, pe.reference_no as 'Beleginfo - Inhalt 5'
, 'Buchungstag' as 'Beleginfo - Art 6'
, pe.reference_date as 'Beleginfo - Inhalt 6'
, '' as 'Fälligkeit'
"""
extra_joins = """
LEFT JOIN `tabPayment Entry` pe
ON gl.voucher_no = pe.name
"""
extra_filters = """
AND gl.voucher_type = 'Payment Entry'
"""
return extra_fields, extra_joins, extra_filters
def get_sales_invoice_params(filters):
extra_fields = """
, '' as 'Beleginfo - Art 5'
, '' as 'Beleginfo - Inhalt 5'
, '' as 'Beleginfo - Art 6'
, '' as 'Beleginfo - Inhalt 6'
, si.due_date as 'Fälligkeit'
"""
extra_joins = """
LEFT JOIN `tabSales Invoice` si
ON gl.voucher_no = si.name
"""
extra_filters = """
AND gl.voucher_type = 'Sales Invoice'
"""
return extra_fields, extra_joins, extra_filters
def get_purchase_invoice_params(filters):
extra_fields = """
, 'Lieferanten-Rechnungsnummer' as 'Beleginfo - Art 5'
, pi.bill_no as 'Beleginfo - Inhalt 5'
, 'Lieferanten-Rechnungsdatum' as 'Beleginfo - Art 6'
, pi.bill_date as 'Beleginfo - Inhalt 6'
, pi.due_date as 'Fälligkeit'
"""
extra_joins = """
LEFT JOIN `tabPurchase Invoice` pi
ON gl.voucher_no = pi.name
"""
extra_filters = """
AND gl.voucher_type = 'Purchase Invoice'
"""
return extra_fields, extra_joins, extra_filters
def get_generic_params(filters):
# produce empty fields so all rows will have the same length
extra_fields = """
, '' as 'Beleginfo - Art 5'
, '' as 'Beleginfo - Inhalt 5'
, '' as 'Beleginfo - Art 6'
, '' as 'Beleginfo - Inhalt 6'
, '' as 'Fälligkeit'
"""
extra_joins = ""
if filters.get("exclude_voucher_types"):
# exclude voucher types that are queried by a dedicated method
exclude = "({})".format(', '.join("'{}'".format(key) for key in filters.get("exclude_voucher_types")))
extra_filters = "AND gl.voucher_type NOT IN {}".format(exclude)
# if voucher type filter is set, allow only this type
if filters.get("voucher_type"):
extra_filters += " AND gl.voucher_type = %(voucher_type)s"
return extra_fields, extra_joins, extra_filters
def run_query(filters, extra_fields, extra_joins, extra_filters, as_dict=1):
"""
Get a list of accounting entries.
@@ -171,8 +326,7 @@ def get_transactions(filters, as_dict=1):
filters -- dict of filters to be passed to the sql query
as_dict -- return as list of dicts [0,1]
"""
filter_by_voucher = 'AND gl.voucher_type = %(voucher_type)s' if filters.get('voucher_type') else ''
gl_entries = frappe.db.sql("""
query = """
SELECT
/* either debit or credit amount; always positive */
@@ -187,6 +341,9 @@ def get_transactions(filters, as_dict=1):
/* against number or, if empty, party against number */
%(temporary_against_account_number)s as 'Gegenkonto (ohne BU-Schlüssel)',
/* disable automatic VAT deduction */
'40' as 'BU-Schlüssel',
gl.posting_date as 'Belegdatum',
gl.voucher_no as 'Belegfeld 1',
LEFT(gl.remarks, 60) as 'Buchungstext',
@@ -199,30 +356,34 @@ def get_transactions(filters, as_dict=1):
case gl.party_type when 'Customer' then 'Debitorennummer' when 'Supplier' then 'Kreditorennummer' else NULL end as 'Beleginfo - Art 4',
par.debtor_creditor_number as 'Beleginfo - Inhalt 4'
{extra_fields}
FROM `tabGL Entry` gl
/* Kontonummer */
left join `tabAccount` acc
on gl.account = acc.name
LEFT JOIN `tabAccount` acc
ON gl.account = acc.name
left join `tabCustomer` cus
on gl.party_type = 'Customer'
and gl.party = cus.name
LEFT JOIN `tabParty Account` par
ON par.parent = gl.party
AND par.parenttype = gl.party_type
AND par.company = %(company)s
left join `tabSupplier` sup
on gl.party_type = 'Supplier'
and gl.party = sup.name
left join `tabParty Account` par
on par.parent = gl.party
and par.parenttype = gl.party_type
and par.company = %(company)s
{extra_joins}
WHERE gl.company = %(company)s
AND DATE(gl.posting_date) >= %(from_date)s
AND DATE(gl.posting_date) <= %(to_date)s
{}
ORDER BY 'Belegdatum', gl.voucher_no""".format(filter_by_voucher), filters, as_dict=as_dict)
{extra_filters}
ORDER BY 'Belegdatum', gl.voucher_no""".format(
extra_fields=extra_fields,
extra_joins=extra_joins,
extra_filters=extra_filters
)
gl_entries = frappe.db.sql(query, filters, as_dict=as_dict)
return gl_entries

View File

@@ -0,0 +1,193 @@
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from unittest import TestCase
from frappe.utils import today
from erpnext.accounts.doctype.account.test_account import create_account
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.regional.report.vat_audit_report.vat_audit_report import execute
class TestVATAuditReport(TestCase):
def setUp(self):
frappe.set_user("Administrator")
make_company("_Test Company SA VAT", "_TCSV")
create_account(account_name="VAT - 0%", account_type="Tax",
parent_account="Duties and Taxes - _TCSV", company="_Test Company SA VAT")
create_account(account_name="VAT - 15%", account_type="Tax",
parent_account="Duties and Taxes - _TCSV", company="_Test Company SA VAT")
set_sa_vat_accounts()
make_item("_Test SA VAT Item")
make_item("_Test SA VAT Zero Rated Item", properties = {"is_zero_rated": 1})
make_customer()
make_supplier()
make_sales_invoices()
create_purchase_invoices()
def tearDown(self):
frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company SA VAT'")
frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company SA VAT'")
def test_vat_audit_report(self):
filters = {
"company": "_Test Company SA VAT",
"from_date": today(),
"to_date": today()
}
columns, data = execute(filters)
total_tax_amount = 0
total_row_tax = 0
for row in data:
keys = row.keys()
# skips total row tax_amount in if.. and skips section header in elif..
if 'voucher_no' in keys:
total_tax_amount = total_tax_amount + row['tax_amount']
elif 'tax_amount' in keys:
total_row_tax = total_row_tax + row['tax_amount']
self.assertEqual(total_tax_amount, total_row_tax)
def make_company(company_name, abbr):
if not frappe.db.exists("Company", company_name):
company = frappe.get_doc({
"doctype": "Company",
"company_name": company_name,
"abbr": abbr,
"default_currency": "ZAR",
"country": "South Africa",
"create_chart_of_accounts_based_on": "Standard Template"
})
company.insert()
else:
company = frappe.get_doc("Company", company_name)
company.create_default_warehouses()
if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": company.name}):
company.create_default_cost_center()
company.save()
return company
def set_sa_vat_accounts():
if not frappe.db.exists("South Africa VAT Settings", "_Test Company SA VAT"):
vat_accounts = frappe.get_all(
"Account",
fields=["name"],
filters = {
"company": "_Test Company SA VAT",
"is_group": 0,
"account_type": "Tax"
}
)
sa_vat_accounts = []
for account in vat_accounts:
sa_vat_accounts.append({
"doctype": "South Africa VAT Account",
"account": account.name
})
frappe.get_doc({
"company": "_Test Company SA VAT",
"vat_accounts": sa_vat_accounts,
"doctype": "South Africa VAT Settings",
}).insert()
def make_customer():
if not frappe.db.exists("Customer", "_Test SA Customer"):
frappe.get_doc({
"doctype": "Customer",
"customer_name": "_Test SA Customer",
"customer_type": "Company",
}).insert()
def make_supplier():
if not frappe.db.exists("Supplier", "_Test SA Supplier"):
frappe.get_doc({
"doctype": "Supplier",
"supplier_name": "_Test SA Supplier",
"supplier_type": "Company",
"supplier_group":"All Supplier Groups"
}).insert()
def make_item(item_code, properties=None):
if not frappe.db.exists("Item", item_code):
item = frappe.get_doc({
"doctype": "Item",
"item_code": item_code,
"item_name": item_code,
"description": item_code,
"item_group": "Products"
})
if properties:
item.update(properties)
item.insert()
def make_sales_invoices():
def make_sales_invoices_wrapper(item, rate, tax_account, tax_rate, tax=True):
si = create_sales_invoice(
company="_Test Company SA VAT",
customer = "_Test SA Customer",
currency = "ZAR",
item=item,
rate=rate,
warehouse = "Finished Goods - _TCSV",
debit_to = "Debtors - _TCSV",
income_account = "Sales - _TCSV",
expense_account = "Cost of Goods Sold - _TCSV",
cost_center = "Main - _TCSV",
do_not_save=1
)
if tax:
si.append("taxes", {
"charge_type": "On Net Total",
"account_head": tax_account,
"cost_center": "Main - _TCSV",
"description": "VAT 15% @ 15.0",
"rate": tax_rate
})
si.submit()
test_item = "_Test SA VAT Item"
test_zero_rated_item = "_Test SA VAT Zero Rated Item"
make_sales_invoices_wrapper(test_item, 100.0, "VAT - 15% - _TCSV", 15.0)
make_sales_invoices_wrapper(test_zero_rated_item, 100.0, "VAT - 0% - _TCSV", 0.0)
def create_purchase_invoices():
pi = make_purchase_invoice(
company = "_Test Company SA VAT",
supplier = "_Test SA Supplier",
supplier_warehouse = "Finished Goods - _TCSV",
warehouse = "Finished Goods - _TCSV",
currency = "ZAR",
cost_center = "Main - _TCSV",
expense_account = "Cost of Goods Sold - _TCSV",
item = "_Test SA VAT Item",
qty = 1,
rate = 100,
uom = "Nos",
do_not_save = 1
)
pi.append("taxes", {
"charge_type": "On Net Total",
"account_head": "VAT - 15% - _TCSV",
"cost_center": "Main - _TCSV",
"description": "VAT 15% @ 15.0",
"rate": 15.0
})
pi.submit()

View File

@@ -1,11 +1,11 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
import json
from frappe import _
from frappe.utils import formatdate
from frappe.utils import formatdate, get_link_to_form
def execute(filters=None):
return VATAuditReport(filters).run()
@@ -42,7 +42,8 @@ class VATAuditReport(object):
self.sa_vat_accounts = frappe.get_list("South Africa VAT Account",
filters = {"parent": self.filters.company}, pluck="account")
if not self.sa_vat_accounts and not frappe.flags.in_test and not frappe.flags.in_migrate:
frappe.throw(_("Please set VAT Accounts in South Africa VAT Settings"))
link_to_settings = get_link_to_form("South Africa VAT Settings", "", label="South Africa VAT Settings")
frappe.throw(_("Please set VAT Accounts in {0}").format(link_to_settings))
def get_invoice_data(self, doctype):
conditions = self.get_conditions()
@@ -69,7 +70,7 @@ class VATAuditReport(object):
items = frappe.db.sql("""
SELECT
item_code, parent, taxable_value, base_net_amount, is_zero_rated
item_code, parent, base_net_amount, is_zero_rated
FROM
`tab%s Item`
WHERE
@@ -79,7 +80,7 @@ class VATAuditReport(object):
if d.item_code not in self.invoice_items.get(d.parent, {}):
self.invoice_items.setdefault(d.parent, {}).setdefault(d.item_code, {
'net_amount': 0.0})
self.invoice_items[d.parent][d.item_code]['net_amount'] += d.get('taxable_value', 0) or d.get('base_net_amount', 0)
self.invoice_items[d.parent][d.item_code]['net_amount'] += d.get('base_net_amount', 0)
self.invoice_items[d.parent][d.item_code]['is_zero_rated'] = d.is_zero_rated
def get_items_based_on_tax_rate(self, doctype):

View File

@@ -111,7 +111,6 @@ frappe.ui.form.on("Customer", {
}
frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'}
frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
if(!frm.doc.__islocal) {
frappe.contacts.render_address_and_contact(frm);

View File

@@ -20,6 +20,7 @@
"tax_withholding_category",
"default_bank_account",
"lead_name",
"opportunity_name",
"image",
"column_break0",
"account_manager",
@@ -267,6 +268,7 @@
"options": "fa fa-map-marker"
},
{
"depends_on": "eval: !doc.__islocal",
"fieldname": "address_html",
"fieldtype": "HTML",
"label": "Address HTML",
@@ -283,6 +285,7 @@
"width": "50%"
},
{
"depends_on": "eval: !doc.__islocal",
"fieldname": "contact_html",
"fieldtype": "HTML",
"label": "Contact HTML",
@@ -493,6 +496,14 @@
"fieldtype": "Link",
"label": "Tax Withholding Category",
"options": "Tax Withholding Category"
},
{
"fieldname": "opportunity_name",
"fieldtype": "Link",
"label": "From Opportunity",
"no_copy": 1,
"options": "Opportunity",
"print_hide": 1
}
],
"icon": "fa fa-user",
@@ -500,7 +511,7 @@
"image_field": "image",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-01-28 12:54:57.258959",
"modified": "2021-08-25 18:56:09.929905",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",

View File

@@ -352,3 +352,26 @@ def set_credit_limit(customer, company, credit_limit):
'credit_limit': credit_limit
})
customer.credit_limits[-1].db_insert()
def create_internal_customer(customer_name, represents_company, allowed_to_interact_with):
if not frappe.db.exists("Customer", customer_name):
customer = frappe.get_doc({
"doctype": "Customer",
"customer_group": "_Test Customer Group",
"customer_name": customer_name,
"customer_type": "Individual",
"territory": "_Test Territory",
"is_internal_customer": 1,
"represents_company": represents_company
})
customer.append("companies", {
"company": allowed_to_interact_with
})
customer.insert()
customer_name = customer.name
else:
customer_name = frappe.db.get_value("Customer", customer_name)
return customer_name

View File

@@ -63,11 +63,11 @@ class TestCurrencyExchange(unittest.TestCase):
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_selling")
self.assertEqual(exchange_rate, 62.9)
# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
# Exchange rate as on 15th Dec, 2015
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15", "for_selling")
self.assertFalse(exchange_rate == 60)
self.assertEqual(flt(exchange_rate, 3), 66.894)
self.assertEqual(flt(exchange_rate, 3), 66.999)
def test_exchange_rate_strict(self):
# strict currency settings
@@ -77,28 +77,17 @@ class TestCurrencyExchange(unittest.TestCase):
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying")
self.assertEqual(exchange_rate, 60.0)
# Will fetch from fixer.io
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 67.79)
self.assertEqual(flt(exchange_rate, 3), 67.235)
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_selling")
self.assertEqual(exchange_rate, 62.9)
# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
# Exchange rate as on 15th Dec, 2015
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 66.894)
exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-10", "for_selling")
self.assertEqual(exchange_rate, 65.1)
# NGN is not available on fixer.io so these should return 0
exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-09", "for_selling")
self.assertEqual(exchange_rate, 0)
exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-11", "for_selling")
self.assertEqual(exchange_rate, 0)
self.assertEqual(flt(exchange_rate, 3), 66.999)
def test_exchange_rate_strict_switched(self):
# Start with allow_stale is True
@@ -111,4 +100,4 @@ class TestCurrencyExchange(unittest.TestCase):
# Will fetch from fixer.io
self.clear_cache()
exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying")
self.assertEqual(flt(exchange_rate, 3), 67.79)
self.assertEqual(flt(exchange_rate, 3), 67.235)

View File

@@ -93,21 +93,21 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No
try:
cache = frappe.cache()
key = "currency_exchange_rate_{0}:{1}:{2}".format(transaction_date,from_currency, to_currency)
key = "currency_exchange_rate_{0}:{1}:{2}".format(transaction_date, from_currency, to_currency)
value = cache.get(key)
if not value:
import requests
api_url = "https://frankfurter.app/{0}".format(transaction_date)
api_url = "https://api.exchangerate.host/convert"
response = requests.get(api_url, params={
"base": from_currency,
"symbols": to_currency
"date": transaction_date,
"from": from_currency,
"to": to_currency
})
# expire in 6 hours
response.raise_for_status()
value = response.json()["rates"][to_currency]
cache.set_value(key, value, expires_in_sec=6 * 60 * 60)
value = response.json()["result"]
cache.setex(name=key, time=21600, value=flt(value))
return flt(value)
except:
frappe.log_error(title="Get Exchange Rate")

View File

@@ -356,3 +356,23 @@ erpnext.stock.delivery_note.set_print_hide = function(doc, cdt, cdn){
dn_fields['taxes'].print_hide = 0;
}
}
frappe.tour['Delivery Note'] = [
{
fieldname: "customer",
title: __("Customer"),
description: __("This field is used to set the 'Customer'.")
},
{
fieldname: "items",
title: __("Items"),
description: __("This table is used to set details about the 'Item', 'Qty', 'Basic Rate', etc.") + " " +
__("Different 'Source Warehouse' and 'Target Warehouse' can be set for each row.")
},
{
fieldname: "set_posting_time",
title: __("Edit Posting Date and Time"),
description: __("This option can be checked to edit the 'Posting Date' and 'Posting Time' fields.")
}
]

View File

@@ -430,12 +430,19 @@ class TestDeliveryNote(unittest.TestCase):
})
def test_delivery_of_bundled_items_to_target_warehouse(self):
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')
customer_name = create_internal_customer(
customer_name="_Test Internal Customer 2",
represents_company="_Test Company with perpetual inventory",
allowed_to_interact_with="_Test Company with perpetual inventory"
)
set_valuation_method("_Test Item", "FIFO")
set_valuation_method("_Test Item Home Desktop 100", "FIFO")
target_warehouse=get_warehouse(company=company, abbr="TCP1",
target_warehouse = get_warehouse(company=company, abbr="TCP1",
warehouse_name="_Test Customer Warehouse").name
for warehouse in ("Stores - TCP1", target_warehouse):
@@ -444,10 +451,16 @@ class TestDeliveryNote(unittest.TestCase):
create_stock_reconciliation(item_code="_Test Item Home Desktop 100", company = company,
expense_account = "Stock Adjustment - TCP1", warehouse=warehouse, qty=500, rate=100)
dn = create_delivery_note(item_code="_Test Product Bundle Item",
company='_Test Company with perpetual inventory', cost_center = 'Main - TCP1',
expense_account = "Cost of Goods Sold - TCP1", do_not_submit=True, qty=5, rate=500,
warehouse="Stores - TCP1", target_warehouse=target_warehouse)
dn = create_delivery_note(
item_code="_Test Product Bundle Item",
company="_Test Company with perpetual inventory",
customer=customer_name,
cost_center = 'Main - TCP1',
expense_account = "Cost of Goods Sold - TCP1",
do_not_submit=True,
qty=5, rate=500,
warehouse="Stores - TCP1",
target_warehouse=target_warehouse)
dn.submit()
@@ -487,6 +500,9 @@ class TestDeliveryNote(unittest.TestCase):
for i, gle in enumerate(gl_entries):
self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))
# tear down
frappe.db.rollback()
def test_closed_delivery_note(self):
from erpnext.stock.doctype.delivery_note.delivery_note import update_delivery_note_status

View File

@@ -798,4 +798,4 @@ frappe.ui.form.on("UOM Conversion Detail", {
});
}
}
})
});

View File

@@ -13,6 +13,9 @@ class PriceList(Document):
if not cint(self.buying) and not cint(self.selling):
throw(_("Price List must be applicable for Buying or Selling"))
if not self.is_new():
self.check_impact_on_shopping_cart()
def on_update(self):
self.set_default_if_missing()
self.update_item_price()
@@ -32,6 +35,17 @@ class PriceList(Document):
buying=%s, selling=%s, modified=NOW() where price_list=%s""",
(self.currency, cint(self.buying), cint(self.selling), self.name))
def check_impact_on_shopping_cart(self):
"Check if Price List currency change impacts Shopping Cart."
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import validate_cart_settings
doc_before_save = self.get_doc_before_save()
currency_changed = self.currency != doc_before_save.currency
affects_cart = self.name == frappe.get_cached_value("Shopping Cart Settings", None, "price_list")
if currency_changed and affects_cart:
validate_cart_settings()
def on_trash(self):
self.delete_price_list_details_key()

View File

@@ -1101,3 +1101,4 @@ function check_should_not_attach_bom_items(bom_no) {
}
$.extend(cur_frm.cscript, new erpnext.stock.StockEntry({frm: cur_frm}));

View File

@@ -272,7 +272,7 @@ class StockEntry(StockController):
item_wise_qty = {}
if self.purpose == "Manufacture" and self.work_order:
for d in self.items:
if d.is_finished_item:
if d.is_finished_item or d.is_process_loss:
item_wise_qty.setdefault(d.item_code, []).append(d.qty)
for item_code, qty_list in iteritems(item_wise_qty):
@@ -333,7 +333,7 @@ class StockEntry(StockController):
if self.purpose == "Manufacture":
if validate_for_manufacture:
if d.is_finished_item or d.is_scrap_item:
if d.is_finished_item or d.is_scrap_item or d.is_process_loss:
d.s_warehouse = None
if not d.t_warehouse:
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
@@ -465,7 +465,7 @@ class StockEntry(StockController):
"""
# Set rate for outgoing items
outgoing_items_cost = self.set_rate_for_outgoing_items(reset_outgoing_rate, raise_error_if_no_rate)
finished_item_qty = sum(d.transfer_qty for d in self.items if d.is_finished_item)
finished_item_qty = sum(d.transfer_qty for d in self.items if d.is_finished_item or d.is_process_loss)
# Set basic rate for incoming items
for d in self.get('items'):
@@ -486,6 +486,8 @@ class StockEntry(StockController):
raise_error_if_no_rate=raise_error_if_no_rate)
d.basic_rate = flt(d.basic_rate, d.precision("basic_rate"))
if d.is_process_loss:
d.basic_rate = flt(0.)
d.basic_amount = flt(flt(d.transfer_qty) * flt(d.basic_rate), d.precision("basic_amount"))
def set_rate_for_outgoing_items(self, reset_outgoing_rate=True, raise_error_if_no_rate=True):
@@ -1043,6 +1045,7 @@ class StockEntry(StockController):
self.set_scrap_items()
self.set_actual_qty()
self.update_items_for_process_loss()
self.validate_customer_provided_item()
self.calculate_rate_and_amount()
@@ -1400,6 +1403,7 @@ class StockEntry(StockController):
get_default_cost_center(item_dict[d], company = self.company))
se_child.is_finished_item = item_dict[d].get("is_finished_item", 0)
se_child.is_scrap_item = item_dict[d].get("is_scrap_item", 0)
se_child.is_process_loss = item_dict[d].get("is_process_loss", 0)
for field in ["idx", "po_detail", "original_item",
"expense_account", "description", "item_name", "serial_no", "batch_no"]:
@@ -1578,6 +1582,30 @@ class StockEntry(StockController):
if material_request and material_request not in material_requests:
material_requests.append(material_request)
frappe.db.set_value('Material Request', material_request, 'transfer_status', status)
def update_items_for_process_loss(self):
process_loss_dict = {}
for d in self.get("items"):
if not d.is_process_loss:
continue
scrap_warehouse = frappe.db.get_single_value("Manufacturing Settings", "default_scrap_warehouse")
if scrap_warehouse is not None:
d.t_warehouse = scrap_warehouse
d.is_scrap_item = 0
if d.item_code not in process_loss_dict:
process_loss_dict[d.item_code] = [flt(0), flt(0)]
process_loss_dict[d.item_code][0] += flt(d.transfer_qty)
process_loss_dict[d.item_code][1] += flt(d.qty)
for d in self.get("items"):
if not d.is_finished_item or d.item_code not in process_loss_dict:
continue
# Assumption: 1 finished item has 1 row.
d.transfer_qty -= process_loss_dict[d.item_code][0]
d.qty -= process_loss_dict[d.item_code][1]
def set_serial_no_batch_for_finished_good(self):
args = {}

View File

@@ -0,0 +1,27 @@
QUnit.module('Stock');
QUnit.test("test manufacture from bom", function(assert) {
assert.expect(2);
let done = assert.async();
frappe.run_serially([
() => {
return frappe.tests.make("Stock Entry", [
{ purpose: "Manufacture" },
{ from_bom: 1 },
{ bom_no: "BOM-_Test Item - Non Whole UOM-001" },
{ fg_completed_qty: 2 }
]);
},
() => cur_frm.save(),
() => frappe.click_button("Update Rate and Availability"),
() => {
assert.ok(cur_frm.doc.items[1] === 0.75, " Finished Item Qty correct");
assert.ok(cur_frm.doc.items[2] === 0.25, " Process Loss Item Qty correct");
},
() => frappe.tests.click_button('Submit'),
() => frappe.tests.click_button('Yes'),
() => frappe.timeout(0.3),
() => done()
]);
});

View File

@@ -18,6 +18,7 @@
"col_break2",
"is_finished_item",
"is_scrap_item",
"is_process_loss",
"quality_inspection",
"subcontracted_item",
"section_break_8",
@@ -543,13 +544,19 @@
"no_copy": 1,
"print_hide": 1,
"read_only": 1
},
{
"default": "0",
"fieldname": "is_process_loss",
"fieldtype": "Check",
"label": "Is Process Loss"
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-06-21 16:03:18.834880",
"modified": "2021-06-22 16:47:11.268975",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry Detail",

View File

@@ -288,3 +288,4 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({
});
cur_frm.cscript = new erpnext.stock.StockReconciliation({frm: cur_frm});

View File

@@ -16,36 +16,3 @@ frappe.ui.form.on('Stock Settings', {
}
});
frappe.tour['Stock Settings'] = [
{
fieldname: "item_naming_by",
title: __("Item Naming By"),
description: __("By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a ") + "<a href='https://docs.erpnext.com/docs/user/manual/en/setting-up/settings/naming-series' target='_blank'>Naming Series</a>" + __(" choose the 'Naming Series' option."),
},
{
fieldname: "default_warehouse",
title: __("Default Warehouse"),
description: __("Set a Default Warehouse for Inventory Transactions. This will be fetched into the Default Warehouse in the Item master.")
},
{
fieldname: "allow_negative_stock",
title: __("Allow Negative Stock"),
description: __("This will allow stock items to be displayed in negative values. Using this option depends on your use case. With this option unchecked, the system warns before obstructing a transaction that is causing negative stock.")
},
{
fieldname: "valuation_method",
title: __("Valuation Method"),
description: __("Choose between FIFO and Moving Average Valuation Methods. Click ") + "<a href='https://docs.erpnext.com/docs/user/manual/en/stock/articles/item-valuation-fifo-and-moving-average' target='_blank'>here</a>" + __(" to know more about them.")
},
{
fieldname: "show_barcode_field",
title: __("Show Barcode Field"),
description: __("Show 'Scan Barcode' field above every child table to insert Items with ease.")
},
{
fieldname: "automatically_set_serial_nos_based_on_fifo",
title: __("Automatically Set Serial Nos based on FIFO"),
description: __("Serial numbers for stock will be set automatically based on the Items entered based on first in first out in transactions like Purchase/Sales Invoices, Delivery Notes, etc.")
}
];

View File

@@ -86,3 +86,4 @@ function convert_to_group_or_ledger(frm){
})
}

View File

@@ -0,0 +1,56 @@
{
"creation": "2021-08-24 14:44:22.292652",
"docstatus": 0,
"doctype": "Form Tour",
"idx": 0,
"is_standard": 1,
"modified": "2021-08-25 16:31:31.441194",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Entry",
"owner": "Administrator",
"reference_doctype": "Stock Entry",
"save_on_complete": 1,
"steps": [
{
"description": "Select the type of Stock Entry to be made. For now, to receive stock into a warehouses select <a href=\"https://docs.erpnext.com/docs/v13/user/manual/en/stock/articles/stock-entry-purpose#2purpose-material-receipt\" target=\"_blank\">Material Receipt.</a>",
"field": "",
"fieldname": "stock_entry_type",
"fieldtype": "Link",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Stock Entry Type",
"next_step_condition": "eval: doc.stock_entry_type === \"Material Receipt\"",
"parent_field": "",
"position": "Top",
"title": "Stock Entry Type"
},
{
"description": "Select a target warehouse where the stock will be received.",
"field": "",
"fieldname": "to_warehouse",
"fieldtype": "Link",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Default Target Warehouse",
"next_step_condition": "eval: doc.to_warehouse",
"parent_field": "",
"position": "Top",
"title": "Default Target Warehouse"
},
{
"description": "Select an item and entry quantity to be delivered.",
"field": "",
"fieldname": "items",
"fieldtype": "Table",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Items",
"next_step_condition": "eval: doc.items[0]?.item_code",
"parent_field": "",
"position": "Top",
"title": "Items"
}
],
"title": "Stock Entry"
}

View File

@@ -0,0 +1,55 @@
{
"creation": "2021-08-24 14:44:46.770952",
"docstatus": 0,
"doctype": "Form Tour",
"idx": 0,
"is_standard": 1,
"modified": "2021-08-25 16:26:11.718664",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Reconciliation",
"owner": "Administrator",
"reference_doctype": "Stock Reconciliation",
"save_on_complete": 1,
"steps": [
{
"description": "Set Purpose to Opening Stock to set the stock opening balance.",
"field": "",
"fieldname": "purpose",
"fieldtype": "Select",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Purpose",
"next_step_condition": "eval: doc.purpose === \"Opening Stock\"",
"parent_field": "",
"position": "Top",
"title": "Purpose"
},
{
"description": "Select the items for which the opening stock has to be set.",
"field": "",
"fieldname": "items",
"fieldtype": "Table",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Items",
"next_step_condition": "eval: doc.items[0]?.item_code",
"parent_field": "",
"position": "Top",
"title": "Items"
},
{
"description": "Edit the Posting Date by clicking on the Edit Posting Date and Time checkbox below.",
"field": "",
"fieldname": "posting_date",
"fieldtype": "Date",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Posting Date",
"parent_field": "",
"position": "Bottom",
"title": "Posting Date"
}
],
"title": "Stock Reconciliation"
}

View File

@@ -0,0 +1,89 @@
{
"creation": "2021-08-20 15:20:59.336585",
"docstatus": 0,
"doctype": "Form Tour",
"idx": 0,
"is_standard": 1,
"modified": "2021-08-25 16:19:37.699528",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Settings",
"owner": "Administrator",
"reference_doctype": "Stock Settings",
"save_on_complete": 1,
"steps": [
{
"description": "By default, the Item Name is set as per the Item Code entered. If you want Items to be named by a Naming Series choose the 'Naming Series' option.",
"field": "",
"fieldname": "item_naming_by",
"fieldtype": "Select",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Item Naming By",
"parent_field": "",
"position": "Bottom",
"title": "Item Naming By"
},
{
"description": "Set a Default Warehouse for Inventory Transactions. This will be fetched into the Default Warehouse in the Item master.",
"field": "",
"fieldname": "default_warehouse",
"fieldtype": "Link",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Default Warehouse",
"parent_field": "",
"position": "Bottom",
"title": "Default Warehouse"
},
{
"description": "Quality inspection is performed on the inward and outward movement of goods. Receipt and delivery transactions will be stopped or the user will be warned if the quality inspection is not performed.",
"field": "",
"fieldname": "action_if_quality_inspection_is_not_submitted",
"fieldtype": "Select",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Action If Quality Inspection Is Not Submitted",
"parent_field": "",
"position": "Bottom",
"title": "Action if Quality Inspection Is Not Submitted"
},
{
"description": "Serial numbers for stock will be set automatically based on the Items entered based on first in first out in transactions like Purchase/Sales Invoices, Delivery Notes, etc.",
"field": "",
"fieldname": "automatically_set_serial_nos_based_on_fifo",
"fieldtype": "Check",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Automatically Set Serial Nos Based on FIFO",
"parent_field": "",
"position": "Bottom",
"title": "Automatically Set Serial Nos based on FIFO"
},
{
"description": "Show 'Scan Barcode' field above every child table to insert Items with ease.",
"field": "",
"fieldname": "show_barcode_field",
"fieldtype": "Check",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Show Barcode Field in Stock Transactions",
"parent_field": "",
"position": "Bottom",
"title": "Show Barcode Field"
},
{
"description": "Choose between FIFO and Moving Average Valuation Methods. Click <a href=\"https://docs.erpnext.com/docs/user/manual/en/stock/articles/item-valuation-fifo-and-moving-average\" target=\"_blank\">here</a> to know more about them.",
"field": "",
"fieldname": "valuation_method",
"fieldtype": "Select",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Default Valuation Method",
"parent_field": "",
"position": "Bottom",
"title": "Default Valuation Method"
}
],
"title": "Stock Settings"
}

View File

@@ -0,0 +1,54 @@
{
"creation": "2021-08-24 14:43:44.465237",
"docstatus": 0,
"doctype": "Form Tour",
"idx": 0,
"is_standard": 1,
"modified": "2021-08-24 14:50:31.988256",
"modified_by": "Administrator",
"module": "Stock",
"name": "Warehouse",
"owner": "Administrator",
"reference_doctype": "Warehouse",
"save_on_complete": 1,
"steps": [
{
"description": "Select a name for the warehouse. This should reflect its location or purpose.",
"field": "",
"fieldname": "warehouse_name",
"fieldtype": "Data",
"has_next_condition": 1,
"is_table_field": 0,
"label": "Warehouse Name",
"next_step_condition": "eval: doc.warehouse_name",
"parent_field": "",
"position": "Bottom",
"title": "Warehouse Name"
},
{
"description": "Select a warehouse type to categorize the warehouse into a sub-group.",
"field": "",
"fieldname": "warehouse_type",
"fieldtype": "Link",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Warehouse Type",
"parent_field": "",
"position": "Top",
"title": "Warehouse Type"
},
{
"description": "Select an account to set a default account for all transactions with this warehouse.",
"field": "",
"fieldname": "account",
"fieldtype": "Link",
"has_next_condition": 0,
"is_table_field": 0,
"label": "Account",
"parent_field": "",
"position": "Top",
"title": "Account"
}
],
"title": "Warehouse"
}

View File

@@ -19,32 +19,26 @@
"documentation_url": "https://docs.erpnext.com/docs/user/manual/en/stock",
"idx": 0,
"is_complete": 0,
"modified": "2020-10-14 14:54:42.741971",
"modified": "2021-08-20 14:38:55.570067",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock",
"owner": "Administrator",
"steps": [
{
"step": "Setup your Warehouse"
"step": "Stock Settings"
},
{
"step": "Create a Product"
},
{
"step": "Create a Supplier"
},
{
"step": "Introduction to Stock Entry"
"step": "Create a Warehouse"
},
{
"step": "Create a Stock Entry"
},
{
"step": "Create a Purchase Receipt"
"step": "Stock Opening Balance"
},
{
"step": "Stock Settings"
"step": "View Stock Projected Qty"
}
],
"subtitle": "Inventory, Warehouses, Analysis, and more.",

View File

@@ -1,19 +0,0 @@
{
"action": "Create Entry",
"creation": "2020-05-19 18:59:13.266713",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-10-14 14:53:25.618434",
"modified_by": "Administrator",
"name": "Create a Purchase Receipt",
"owner": "Administrator",
"reference_document": "Purchase Receipt",
"show_full_form": 1,
"title": "Create a Purchase Receipt",
"validate_action": 1
}

View File

@@ -1,19 +1,21 @@
{
"action": "Create Entry",
"action_label": "Create a Material Transfer Entry",
"creation": "2020-05-15 03:20:16.277043",
"description": "# Manage Stock Movements\nStock entry allows you to register the movement of stock for various purposes like transfer, received, issues, repacked, etc. To address issues related to theft and pilferages, you can always ensure that the movement of goods happens against a document reference Stock Entry in ERPNext.\n\nLet\u2019s get a quick walk-through on the various scenarios covered in Stock Entry by watching [*this video*](https://www.youtube.com/watch?v=Njt107hlY3I).",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-10-14 14:53:00.105905",
"modified": "2021-06-18 13:57:11.434063",
"modified_by": "Administrator",
"name": "Create a Stock Entry",
"owner": "Administrator",
"reference_document": "Stock Entry",
"show_form_tour": 1,
"show_full_form": 1,
"title": "Create a Stock Entry",
"title": "Manage Stock Movements",
"validate_action": 1
}

View File

@@ -1,18 +1,19 @@
{
"action": "Create Entry",
"action": "Show Form Tour",
"creation": "2020-05-14 22:09:10.043554",
"description": "# Create a Supplier\nIn this step we will create a **Supplier**. If you have already created a **Supplier** you can skip this step.",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-10-14 14:53:00.120455",
"modified": "2021-05-17 16:37:37.697077",
"modified_by": "Administrator",
"name": "Create a Supplier",
"owner": "Administrator",
"reference_document": "Supplier",
"show_form_tour": 0,
"show_full_form": 0,
"title": "Create a Supplier",
"validate_action": 1

View File

@@ -0,0 +1,21 @@
{
"action": "Create Entry",
"action_label": "Let\u2019s create your first warehouse ",
"creation": "2021-05-17 16:13:19.297789",
"description": "# Setup a Warehouse\nThe warehouse can be your location/godown/store where you maintain the item's inventory, and receive/deliver them to various parties.\n\nIn ERPNext, you can maintain a Warehouse in the tree structure, so that location and sub-location of an item can be tracked. Also, you can link a Warehouse to a specific Accounting ledger, where the real-time stock value of that warehouse\u2019s item will be reflected.",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2021-08-18 12:23:36.675572",
"modified_by": "Administrator",
"name": "Create a Warehouse",
"owner": "Administrator",
"reference_document": "Warehouse",
"show_form_tour": 1,
"show_full_form": 1,
"title": "Setup a Warehouse",
"validate_action": 1
}

View File

@@ -0,0 +1,22 @@
{
"action": "Create Entry",
"action_label": "",
"creation": "2021-05-17 13:47:18.515052",
"description": "# Create an Item\nThe Stock module deals with the movement of items.\n\nIn this step we will create an [**Item**](https://docs.erpnext.com/docs/user/manual/en/stock/item).",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"intro_video_url": "",
"is_complete": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2021-05-18 16:15:20.695028",
"modified_by": "Administrator",
"name": "Create an Item",
"owner": "Administrator",
"reference_document": "Item",
"show_form_tour": 1,
"show_full_form": 1,
"title": "Create an Item",
"validate_action": 1
}

View File

@@ -1,17 +1,18 @@
{
"action": "Watch Video",
"creation": "2020-05-15 02:47:17.958806",
"description": "# Introduction to Stock Entry\nThis video will give a quick introduction to [**Stock Entry**](https://docs.erpnext.com/docs/user/manual/en/stock/stock-entry).",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-10-14 14:53:00.075177",
"modified": "2021-05-18 15:13:43.306064",
"modified_by": "Administrator",
"name": "Introduction to Stock Entry",
"owner": "Administrator",
"show_form_tour": 0,
"show_full_form": 0,
"title": "Introduction to Stock Entry",
"validate_action": 1,

View File

@@ -5,15 +5,15 @@
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-10-14 14:53:25.538900",
"modified": "2021-05-17 13:53:06.936579",
"modified_by": "Administrator",
"name": "Setup your Warehouse",
"owner": "Administrator",
"path": "Tree/Warehouse",
"reference_document": "Warehouse",
"show_form_tour": 0,
"show_full_form": 0,
"title": "Set up your Warehouse",
"validate_action": 1

View File

@@ -0,0 +1,22 @@
{
"action": "Create Entry",
"action_label": "Let\u2019s create a stock opening entry",
"creation": "2021-05-17 16:13:47.511883",
"description": "# Update Stock Opening Balance\nIt\u2019s an entry to update the stock balance of an item, in a warehouse, on a date and time you are going live on ERPNext.\n\nOnce opening stocks are updated, you can create transactions like manufacturing and stock deliveries, where this opening stock will be consumed.",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2021-06-18 13:59:36.021097",
"modified_by": "Administrator",
"name": "Stock Opening Balance",
"owner": "Administrator",
"reference_document": "Stock Reconciliation",
"show_form_tour": 1,
"show_full_form": 1,
"title": "Update Stock Opening Balance",
"validate_action": 1,
"video_url": "https://www.youtube.com/watch?v=nlHX0ZZ84Lw"
}

View File

@@ -1,19 +1,21 @@
{
"action": "Show Form Tour",
"action_label": "Take a walk through Stock Settings",
"creation": "2020-05-15 02:53:57.209967",
"description": "# Review Stock Settings\n\nIn ERPNext, the Stock module\u2019s features are configurable as per your business needs. Stock Settings is the place where you can set your preferences for:\n- Default values for Item and Pricing\n- Default valuation method for inventory valuation\n- Set preference for serialization and batching of item\n- Set tolerance for over-receipt and delivery of items",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 0,
"is_single": 1,
"is_skipped": 0,
"modified": "2020-10-14 14:53:00.092504",
"modified": "2021-08-18 12:06:51.139387",
"modified_by": "Administrator",
"name": "Stock Settings",
"owner": "Administrator",
"reference_document": "Stock Settings",
"show_form_tour": 0,
"show_full_form": 0,
"title": "Explore Stock Settings",
"title": "Review Stock Settings",
"validate_action": 1
}

View File

@@ -0,0 +1,24 @@
{
"action": "View Report",
"action_label": "Check Stock Projected Qty",
"creation": "2021-08-20 14:38:41.649103",
"description": "# Check Stock Reports\nBased on the various stock transactions, you can get a host of one-click Stock Reports in ERPNext like Stock Ledger, Stock Balance, Projected Quantity, and Ageing analysis.",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2021-08-20 14:38:41.649103",
"modified_by": "Administrator",
"name": "View Stock Projected Qty",
"owner": "Administrator",
"reference_report": "Stock Projected Qty",
"report_description": "You can set the filters to narrow the results, then click on Generate New Report to see the updated report.",
"report_reference_doctype": "Item",
"report_type": "Script Report",
"show_form_tour": 0,
"show_full_form": 0,
"title": "Check Stock Projected Qty",
"validate_action": 1
}

View File

@@ -0,0 +1,20 @@
{
"action": "Go to Page",
"creation": "2021-05-17 16:12:43.427579",
"description": "# View Warehouse\nIn ERPNext the term 'warehouse' can be thought of as a storage location.\n\nWarehouses are arranged in ERPNext in a tree like structure, where multiple sub-warehouses can be grouped under a single warehouse.\n\nIn this step we will view the [**Warehouse Tree**](https://docs.erpnext.com/docs/user/manual/en/stock/warehouse#21-tree-view) to view the [**Warehouses**](https://docs.erpnext.com/docs/user/manual/en/stock/warehouse) that are set by default.",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_single": 0,
"is_skipped": 0,
"modified": "2021-05-18 15:04:41.198413",
"modified_by": "Administrator",
"name": "View Warehouses",
"owner": "Administrator",
"path": "Tree/Warehouse",
"show_form_tour": 0,
"show_full_form": 0,
"title": "View Warehouses",
"validate_action": 1
}

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */
frappe.query_reports["Process Loss Report"] = {
filters: [
{
label: __("Company"),
fieldname: "company",
fieldtype: "Link",
options: "Company",
mandatory: true,
default: frappe.defaults.get_user_default("Company"),
},
{
label: __("Item"),
fieldname: "item",
fieldtype: "Link",
options: "Item",
mandatory: false,
},
{
label: __("Work Order"),
fieldname: "work_order",
fieldtype: "Link",
options: "Work Order",
mandatory: false,
},
{
label: __("From Date"),
fieldname: "from_date",
fieldtype: "Date",
mandatory: true,
default: frappe.datetime.year_start(),
},
{
label: __("To Date"),
fieldname: "to_date",
fieldtype: "Date",
mandatory: true,
default: frappe.datetime.get_today(),
},
]
};

View File

@@ -0,0 +1,29 @@
{
"add_total_row": 0,
"columns": [],
"creation": "2021-08-24 16:38:15.233395",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"filters": [],
"idx": 0,
"is_standard": "Yes",
"modified": "2021-08-24 16:38:15.233395",
"modified_by": "Administrator",
"module": "Stock",
"name": "Process Loss Report",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Work Order",
"report_name": "Process Loss Report",
"report_type": "Script Report",
"roles": [
{
"role": "Manufacturing User"
},
{
"role": "Stock User"
}
]
}

View File

@@ -0,0 +1,132 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import frappe
from typing import Dict, List, Tuple
Filters = frappe._dict
Row = frappe._dict
Data = List[Row]
Columns = List[Dict[str, str]]
QueryArgs = Dict[str, str]
def execute(filters: Filters) -> Tuple[Columns, Data]:
columns = get_columns()
data = get_data(filters)
return columns, data
def get_data(filters: Filters) -> Data:
query_args = get_query_args(filters)
data = run_query(query_args)
update_data_with_total_pl_value(data)
return data
def get_columns() -> Columns:
return [
{
'label': 'Work Order',
'fieldname': 'name',
'fieldtype': 'Link',
'options': 'Work Order',
'width': '200'
},
{
'label': 'Item',
'fieldname': 'production_item',
'fieldtype': 'Link',
'options': 'Item',
'width': '100'
},
{
'label': 'Status',
'fieldname': 'status',
'fieldtype': 'Data',
'width': '100'
},
{
'label': 'Manufactured Qty',
'fieldname': 'produced_qty',
'fieldtype': 'Float',
'width': '150'
},
{
'label': 'Loss Qty',
'fieldname': 'process_loss_qty',
'fieldtype': 'Float',
'width': '150'
},
{
'label': 'Actual Manufactured Qty',
'fieldname': 'actual_produced_qty',
'fieldtype': 'Float',
'width': '150'
},
{
'label': 'Loss Value',
'fieldname': 'total_pl_value',
'fieldtype': 'Float',
'width': '150'
},
{
'label': 'FG Value',
'fieldname': 'total_fg_value',
'fieldtype': 'Float',
'width': '150'
},
{
'label': 'Raw Material Value',
'fieldname': 'total_rm_value',
'fieldtype': 'Float',
'width': '150'
}
]
def get_query_args(filters: Filters) -> QueryArgs:
query_args = {}
query_args.update(filters)
query_args.update(
get_filter_conditions(filters)
)
return query_args
def run_query(query_args: QueryArgs) -> Data:
return frappe.db.sql("""
SELECT
wo.name, wo.status, wo.production_item, wo.qty,
wo.produced_qty, wo.process_loss_qty,
(wo.produced_qty - wo.process_loss_qty) as actual_produced_qty,
sum(se.total_incoming_value) as total_fg_value,
sum(se.total_outgoing_value) as total_rm_value
FROM
`tabWork Order` wo INNER JOIN `tabStock Entry` se
ON wo.name=se.work_order
WHERE
process_loss_qty > 0
AND wo.company = %(company)s
AND se.docstatus = 1
AND se.posting_date BETWEEN %(from_date)s AND %(to_date)s
{item_filter}
{work_order_filter}
GROUP BY
se.work_order
""".format(**query_args), query_args, as_dict=1, debug=1)
def update_data_with_total_pl_value(data: Data) -> None:
for row in data:
value_per_unit_fg = row['total_fg_value'] / row['actual_produced_qty']
row['total_pl_value'] = row['process_loss_qty'] * value_per_unit_fg
def get_filter_conditions(filters: Filters) -> QueryArgs:
filter_conditions = dict(item_filter="", work_order_filter="")
if "item" in filters:
production_item = filters.get("item")
filter_conditions.update(
{"item_filter": f"AND wo.production_item='{production_item}'"}
)
if "work_order" in filters:
work_order_name = filters.get("work_order")
filter_conditions.update(
{"work_order_filter": f"AND wo.name='{work_order_name}'"}
)
return filter_conditions

View File

@@ -324,6 +324,7 @@ class update_entries_after(object):
where
item_code = %(item_code)s
and warehouse = %(warehouse)s
and is_cancelled = 0
and timestamp(posting_date, time_format(posting_time, %(time_format)s)) = timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s))
order by