Merge branch 'develop' into exotel-fixes

This commit is contained in:
Suraj Shetty 2022-04-03 21:17:29 +05:30 committed by GitHub
commit 6644ebd52d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 1090 additions and 627 deletions

View File

@ -31,6 +31,7 @@ ignore =
E124, # closing bracket, irritating while writing QB code
E131, # continuation line unaligned for hanging indent
E123, # closing bracket does not match indentation of opening bracket's line
E101, # ensured by use of black
max-line-length = 200
exclude=.github/helper/semgrep_rules

View File

@ -1,117 +0,0 @@
name: UI
on:
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
concurrency:
group: ui-develop-${{ github.event.number }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: false
name: UI Tests (Cypress)
services:
mysql:
image: mariadb:10.3
env:
MYSQL_ALLOW_EMPTY_PASSWORD: YES
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- name: Clone
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions/setup-node@v2
with:
node-version: 14
check-latest: true
- name: Add to Hosts
run: |
echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Cache cypress binary
uses: actions/cache@v2
with:
path: ~/.cache
key: ${{ runner.os }}-cypress-
restore-keys: |
${{ runner.os }}-cypress-
${{ runner.os }}-
- name: Install
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
env:
DB: mariadb
TYPE: ui
- name: Site Setup
run: cd ~/frappe-bench/ && bench --site test_site execute erpnext.setup.utils.before_tests
- name: cypress pre-requisites
run: cd ~/frappe-bench/apps/frappe && yarn add cypress-file-upload@^5 @testing-library/cypress@^8 --no-lockfile
- name: Build Assets
run: cd ~/frappe-bench/ && bench build
env:
CI: Yes
- name: UI Tests
run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless
env:
CYPRESS_RECORD_KEY: 60a8e3bf-08f5-45b1-9269-2b207d7d30cd
- name: Show bench console if tests failed
if: ${{ failure() }}
run: cat ~/frappe-bench/bench_run_logs.txt

View File

@ -30,9 +30,7 @@ repos:
rev: 9cb0a69f4d0030cdf687eddf314468b39ed54119
hooks:
- id: black
additional_dependencies: [
'click==8.0.4'
]
additional_dependencies: ['click==8.0.4']
- repo: https://github.com/timothycrosley/isort
rev: 5.9.1

View File

@ -204,7 +204,9 @@ class Account(NestedSet):
if not self.account_currency:
self.account_currency = frappe.get_cached_value("Company", self.company, "default_currency")
elif self.account_currency != frappe.db.get_value("Account", self.name, "account_currency"):
gl_currency = frappe.db.get_value("GL Entry", {"account": self.name}, "account_currency")
if gl_currency and self.account_currency != gl_currency:
if frappe.db.get_value("GL Entry", {"account": self.name}):
frappe.throw(_("Currency can not be changed after making entries using some other currency"))

View File

@ -241,6 +241,28 @@ class TestAccount(unittest.TestCase):
for doc in to_delete:
frappe.delete_doc("Account", doc)
def test_validate_account_currency(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry
if not frappe.db.get_value("Account", "Test Currency Account - _TC"):
acc = frappe.new_doc("Account")
acc.account_name = "Test Currency Account"
acc.parent_account = "Tax Assets - _TC"
acc.company = "_Test Company"
acc.insert()
else:
acc = frappe.get_doc("Account", "Test Currency Account - _TC")
self.assertEqual(acc.account_currency, "INR")
# Make a JV against this account
make_journal_entry(
"Test Currency Account - _TC", "Miscellaneous Expenses - _TC", 100, submit=True
)
acc.account_currency = "USD"
self.assertRaises(frappe.ValidationError, acc.save)
def _make_test_records(verbose=None):
from frappe.test_runner import make_test_objects

View File

@ -532,7 +532,8 @@ frappe.ui.form.on('Payment Entry', {
to_currency: to_currency
},
callback: function(r, rt) {
frm.set_value(exchange_rate_field, r.message);
const ex_rate = flt(r.message, frm.get_field(exchange_rate_field).get_precision());
frm.set_value(exchange_rate_field, ex_rate);
}
})
},

View File

@ -12,7 +12,6 @@ frappe.ui.form.on('Payment Order', {
});
frm.set_df_property('references', 'cannot_add_rows', true);
frm.set_df_property('references', 'cannot_delete_rows', true);
},
refresh: function(frm) {
if (frm.doc.docstatus == 0) {

View File

@ -375,12 +375,12 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
def update_args_for_pricing_rule(args):
if not (args.item_group and args.brand):
try:
args.item_group, args.brand = frappe.get_cached_value(
"Item", args.item_code, ["item_group", "brand"]
)
except frappe.DoesNotExistError:
item = frappe.get_cached_value("Item", args.item_code, ("item_group", "brand"))
if not item:
return
args.item_group, args.brand = item
if not args.item_group:
frappe.throw(_("Item Group not mentioned in item master for item {0}").format(args.item_code))

View File

@ -276,6 +276,8 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
if(this.frm.updating_party_details || this.frm.doc.inter_company_invoice_reference)
return;
if (this.frm.doc.__onload && this.frm.doc.__onload.load_after_mapping) return;
erpnext.utils.get_party_details(this.frm, "erpnext.accounts.party.get_party_details",
{
posting_date: this.frm.doc.posting_date,

View File

@ -249,8 +249,9 @@ class PurchaseInvoice(BuyingController):
def validate_warehouse(self, for_validate=True):
if self.update_stock and for_validate:
stock_items = self.get_stock_items()
for d in self.get("items"):
if not d.warehouse:
if not d.warehouse and d.item_code in stock_items:
frappe.throw(
_(
"Row No {0}: Warehouse is required. Please set a Default Warehouse for Item {1} and Company {2}"

View File

@ -280,6 +280,9 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
}
var me = this;
if(this.frm.updating_party_details) return;
if (this.frm.doc.__onload && this.frm.doc.__onload.load_after_mapping) return;
erpnext.utils.get_party_details(this.frm,
"erpnext.accounts.party.get_party_details", {
posting_date: this.frm.doc.posting_date,

View File

@ -945,12 +945,55 @@ class TestSalesInvoice(unittest.TestCase):
)
pos.append("payments", {"mode_of_payment": "Cash", "account": "Cash - TCP1", "amount": 60})
pos.change_amount = 5.0
pos.write_off_outstanding_amount_automatically = 1
pos.insert()
pos.submit()
self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.write_off_amount, -5)
self.assertEqual(pos.write_off_amount, 0)
def test_auto_write_off_amount(self):
make_pos_profile(
company="_Test Company with perpetual inventory",
income_account="Sales - TCP1",
expense_account="Cost of Goods Sold - TCP1",
warehouse="Stores - TCP1",
cost_center="Main - TCP1",
write_off_account="_Test Write Off - TCP1",
)
make_purchase_receipt(
company="_Test Company with perpetual inventory",
item_code="_Test FG Item",
warehouse="Stores - TCP1",
cost_center="Main - TCP1",
)
pos = create_sales_invoice(
company="_Test Company with perpetual inventory",
debit_to="Debtors - TCP1",
item_code="_Test FG Item",
warehouse="Stores - TCP1",
income_account="Sales - TCP1",
expense_account="Cost of Goods Sold - TCP1",
cost_center="Main - TCP1",
do_not_save=True,
)
pos.is_pos = 1
pos.update_stock = 1
pos.append(
"payments", {"mode_of_payment": "Bank Draft", "account": "_Test Bank - TCP1", "amount": 50}
)
pos.append("payments", {"mode_of_payment": "Cash", "account": "Cash - TCP1", "amount": 40})
pos.write_off_outstanding_amount_automatically = 1
pos.insert()
pos.submit()
self.assertEqual(pos.grand_total, 100.0)
self.assertEqual(pos.write_off_amount, 10)
def test_pos_with_no_gl_entry_for_change_amount(self):
frappe.db.set_value("Accounts Settings", None, "post_change_gl_entries", 0)

View File

@ -253,7 +253,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
if not from_repost:
validate_cwip_accounts(gl_map)
round_off_debit_credit(gl_map)
process_debit_credit_difference(gl_map)
if gl_map:
check_freezing_date(gl_map[0]["posting_date"], adv_adj)
@ -302,12 +302,29 @@ def validate_cwip_accounts(gl_map):
)
def round_off_debit_credit(gl_map):
def process_debit_credit_difference(gl_map):
precision = get_field_precision(
frappe.get_meta("GL Entry").get_field("debit"),
currency=frappe.get_cached_value("Company", gl_map[0].company, "default_currency"),
)
voucher_type = gl_map[0].voucher_type
voucher_no = gl_map[0].voucher_no
allowance = get_debit_credit_allowance(voucher_type, precision)
debit_credit_diff = get_debit_credit_difference(gl_map, precision)
if abs(debit_credit_diff) > allowance:
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
elif abs(debit_credit_diff) >= (1.0 / (10**precision)):
make_round_off_gle(gl_map, debit_credit_diff, precision)
debit_credit_diff = get_debit_credit_difference(gl_map, precision)
if abs(debit_credit_diff) > allowance:
raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no)
def get_debit_credit_difference(gl_map, precision):
debit_credit_diff = 0.0
for entry in gl_map:
entry.debit = flt(entry.debit, precision)
@ -316,20 +333,24 @@ def round_off_debit_credit(gl_map):
debit_credit_diff = flt(debit_credit_diff, precision)
if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"):
return debit_credit_diff
def get_debit_credit_allowance(voucher_type, precision):
if voucher_type in ("Journal Entry", "Payment Entry"):
allowance = 5.0 / (10**precision)
else:
allowance = 0.5
if abs(debit_credit_diff) > allowance:
frappe.throw(
_("Debit and Credit not equal for {0} #{1}. Difference is {2}.").format(
gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff
)
)
return allowance
elif abs(debit_credit_diff) >= (1.0 / (10**precision)):
make_round_off_gle(gl_map, debit_credit_diff, precision)
def raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no):
frappe.throw(
_("Debit and Credit not equal for {0} #{1}. Difference is {2}.").format(
voucher_type, voucher_no, debit_credit_diff
)
)
def make_round_off_gle(gl_map, debit_credit_diff, precision):

View File

@ -53,6 +53,22 @@ frappe.query_reports["Accounts Payable"] = {
}
}
},
{
"fieldname": "party_account",
"label": __("Payable Account"),
"fieldtype": "Link",
"options": "Account",
get_query: () => {
var company = frappe.query_report.get_filter_value('company');
return {
filters: {
'company': company,
'account_type': 'Payable',
'is_group': 0
}
};
}
},
{
"fieldname": "ageing_based_on",
"label": __("Ageing Based On"),

View File

@ -66,6 +66,22 @@ frappe.query_reports["Accounts Receivable"] = {
}
}
},
{
"fieldname": "party_account",
"label": __("Receivable Account"),
"fieldtype": "Link",
"options": "Account",
get_query: () => {
var company = frappe.query_report.get_filter_value('company');
return {
filters: {
'company': company,
'account_type': 'Receivable',
'is_group': 0
}
};
}
},
{
"fieldname": "ageing_based_on",
"label": __("Ageing Based On"),

View File

@ -111,6 +111,7 @@ class ReceivablePayableReport(object):
voucher_type=gle.voucher_type,
voucher_no=gle.voucher_no,
party=gle.party,
party_account=gle.account,
posting_date=gle.posting_date,
account_currency=gle.account_currency,
remarks=gle.remarks if self.filters.get("show_remarks") else None,
@ -777,18 +778,22 @@ class ReceivablePayableReport(object):
conditions.append("party=%s")
values.append(self.filters.get(party_type_field))
# get GL with "receivable" or "payable" account_type
account_type = "Receivable" if self.party_type == "Customer" else "Payable"
accounts = [
d.name
for d in frappe.get_all(
"Account", filters={"account_type": account_type, "company": self.filters.company}
)
]
if self.filters.party_account:
conditions.append("account =%s")
values.append(self.filters.party_account)
else:
# get GL with "receivable" or "payable" account_type
account_type = "Receivable" if self.party_type == "Customer" else "Payable"
accounts = [
d.name
for d in frappe.get_all(
"Account", filters={"account_type": account_type, "company": self.filters.company}
)
]
if accounts:
conditions.append("account in (%s)" % ",".join(["%s"] * len(accounts)))
values += accounts
if accounts:
conditions.append("account in (%s)" % ",".join(["%s"] * len(accounts)))
values += accounts
def add_customer_filters(self, conditions, values):
if self.filters.get("customer_group"):
@ -888,6 +893,13 @@ class ReceivablePayableReport(object):
options=self.party_type,
width=180,
)
self.add_column(
label="Receivable Account" if self.party_type == "Customer" else "Payable Account",
fieldname="party_account",
fieldtype="Link",
options="Account",
width=180,
)
if self.party_naming_by == "Naming Series":
self.add_column(

View File

@ -50,12 +50,19 @@ class TestAccountsReceivable(unittest.TestCase):
make_credit_note(name)
report = execute(filters)
expected_data_after_credit_note = [100, 0, 0, 40, -40]
expected_data_after_credit_note = [100, 0, 0, 40, -40, "Debtors - _TC2"]
row = report[1][0]
self.assertEqual(
expected_data_after_credit_note,
[row.invoice_grand_total, row.invoiced, row.paid, row.credit_note, row.outstanding],
[
row.invoice_grand_total,
row.invoiced,
row.paid,
row.credit_note,
row.outstanding,
row.party_account,
],
)

View File

@ -68,7 +68,7 @@ class TestAsset(AssetSetup):
def test_item_exists(self):
asset = create_asset(item_code="MacBook", do_not_save=1)
self.assertRaises(frappe.DoesNotExistError, asset.save)
self.assertRaises(frappe.ValidationError, asset.save)
def test_validate_item(self):
asset = create_asset(item_code="MacBook Pro", do_not_save=1)

View File

@ -3,19 +3,19 @@
import json
from typing import Dict
import frappe
from frappe import _
from frappe.utils import cint, cstr, flt
from frappe.utils import cint, cstr, flt, getdate
from erpnext.stock.doctype.item.item import get_last_purchase_details, validate_end_of_life
def update_last_purchase_rate(doc, is_submit):
def update_last_purchase_rate(doc, is_submit) -> None:
"""updates last_purchase_rate in item table for each item"""
import frappe.utils
this_purchase_date = frappe.utils.getdate(doc.get("posting_date") or doc.get("transaction_date"))
this_purchase_date = getdate(doc.get("posting_date") or doc.get("transaction_date"))
for d in doc.get("items"):
# get last purchase details
@ -41,7 +41,7 @@ def update_last_purchase_rate(doc, is_submit):
frappe.db.set_value("Item", d.item_code, "last_purchase_rate", flt(last_purchase_rate))
def validate_for_items(doc):
def validate_for_items(doc) -> None:
items = []
for d in doc.get("items"):
if not d.qty:
@ -49,40 +49,11 @@ def validate_for_items(doc):
continue
frappe.throw(_("Please enter quantity for Item {0}").format(d.item_code))
# update with latest quantities
bin = frappe.db.sql(
"""select projected_qty from `tabBin` where
item_code = %s and warehouse = %s""",
(d.item_code, d.warehouse),
as_dict=1,
)
f_lst = {
"projected_qty": bin and flt(bin[0]["projected_qty"]) or 0,
"ordered_qty": 0,
"received_qty": 0,
}
if d.doctype in ("Purchase Receipt Item", "Purchase Invoice Item"):
f_lst.pop("received_qty")
for x in f_lst:
if d.meta.get_field(x):
d.set(x, f_lst[x])
item = frappe.db.sql(
"""select is_stock_item,
is_sub_contracted_item, end_of_life, disabled from `tabItem` where name=%s""",
d.item_code,
as_dict=1,
)[0]
set_stock_levels(row=d) # update with latest quantities
item = validate_item_and_get_basic_data(row=d)
validate_stock_item_warehouse(row=d, item=item)
validate_end_of_life(d.item_code, item.end_of_life, item.disabled)
# validate stock item
if item.is_stock_item == 1 and d.qty and not d.warehouse and not d.get("delivered_by_supplier"):
frappe.throw(
_("Warehouse is mandatory for stock Item {0} in row {1}").format(d.item_code, d.idx)
)
items.append(cstr(d.item_code))
if (
@ -93,7 +64,57 @@ def validate_for_items(doc):
frappe.throw(_("Same item cannot be entered multiple times."))
def check_on_hold_or_closed_status(doctype, docname):
def set_stock_levels(row) -> None:
projected_qty = frappe.db.get_value(
"Bin",
{
"item_code": row.item_code,
"warehouse": row.warehouse,
},
"projected_qty",
)
qty_data = {
"projected_qty": flt(projected_qty),
"ordered_qty": 0,
"received_qty": 0,
}
if row.doctype in ("Purchase Receipt Item", "Purchase Invoice Item"):
qty_data.pop("received_qty")
for field in qty_data:
if row.meta.get_field(field):
row.set(field, qty_data[field])
def validate_item_and_get_basic_data(row) -> Dict:
item = frappe.db.get_values(
"Item",
filters={"name": row.item_code},
fieldname=["is_stock_item", "is_sub_contracted_item", "end_of_life", "disabled"],
as_dict=1,
)
if not item:
frappe.throw(_("Row #{0}: Item {1} does not exist").format(row.idx, frappe.bold(row.item_code)))
return item[0]
def validate_stock_item_warehouse(row, item) -> None:
if (
item.is_stock_item == 1
and row.qty
and not row.warehouse
and not row.get("delivered_by_supplier")
):
frappe.throw(
_("Row #{1}: Warehouse is mandatory for stock Item {0}").format(
frappe.bold(row.item_code), row.idx
)
)
def check_on_hold_or_closed_status(doctype, docname) -> None:
status = frappe.db.get_value(doctype, docname, "status")
if status in ("Closed", "On Hold"):

View File

@ -1267,17 +1267,9 @@ class AccountsController(TransactionBase):
stock_items = []
item_codes = list(set(item.item_code for item in self.get("items")))
if item_codes:
stock_items = [
r[0]
for r in frappe.db.sql(
"""
select name from `tabItem`
where name in (%s) and is_stock_item=1
"""
% (", ".join(["%s"] * len(item_codes)),),
item_codes,
)
]
stock_items = frappe.db.get_values(
"Item", {"name": ["in", item_codes], "is_stock_item": 1}, pluck="name", cache=True
)
return stock_items

View File

@ -679,7 +679,11 @@ class calculate_taxes_and_totals(object):
)
if self.doc.docstatus == 0:
if self.doc.get("write_off_outstanding_amount_automatically"):
self.doc.write_off_amount = 0
self.calculate_outstanding_amount()
self.calculate_write_off_amount()
def is_internal_invoice(self):
"""
@ -731,7 +735,6 @@ class calculate_taxes_and_totals(object):
change_amount = 0
if self.doc.doctype == "Sales Invoice" and not self.doc.get("is_return"):
self.calculate_write_off_amount()
self.calculate_change_amount()
change_amount = (
self.doc.change_amount
@ -791,28 +794,26 @@ class calculate_taxes_and_totals(object):
and not self.doc.is_return
and any(d.type == "Cash" for d in self.doc.payments)
):
self.doc.change_amount = flt(
self.doc.paid_amount - grand_total + self.doc.write_off_amount,
self.doc.precision("change_amount"),
self.doc.paid_amount - grand_total, self.doc.precision("change_amount")
)
self.doc.base_change_amount = flt(
self.doc.base_paid_amount - base_grand_total + self.doc.base_write_off_amount,
self.doc.precision("base_change_amount"),
self.doc.base_paid_amount - base_grand_total, self.doc.precision("base_change_amount")
)
def calculate_write_off_amount(self):
if flt(self.doc.change_amount) > 0:
if self.doc.get("write_off_outstanding_amount_automatically"):
self.doc.write_off_amount = flt(
self.doc.grand_total - self.doc.paid_amount + self.doc.change_amount,
self.doc.precision("write_off_amount"),
self.doc.outstanding_amount, self.doc.precision("write_off_amount")
)
self.doc.base_write_off_amount = flt(
self.doc.write_off_amount * self.doc.conversion_rate,
self.doc.precision("base_write_off_amount"),
)
self.calculate_outstanding_amount()
def calculate_margin(self, item):
rate_with_margin = 0.0
base_rate_with_margin = 0.0

View File

@ -146,12 +146,7 @@ def validate_cart_settings(doc=None, method=None):
def get_shopping_cart_settings():
if not getattr(frappe.local, "shopping_cart_settings", None):
frappe.local.shopping_cart_settings = frappe.get_doc(
"E Commerce Settings", "E Commerce Settings"
)
return frappe.local.shopping_cart_settings
return frappe.get_cached_doc("E Commerce Settings")
@frappe.whitelist(allow_guest=True)

View File

@ -41,4 +41,4 @@ class EducationSettings(Document):
def update_website_context(context):
context["lms_enabled"] = frappe.get_doc("Education Settings").enable_lms
context["lms_enabled"] = frappe.get_cached_doc("Education Settings").enable_lms

View File

@ -1,6 +1,6 @@
<div class="web-list-item transaction-list-item">
{% set today = frappe.utils.getdate(frappe.utils.nowdate()) %}
<a href = "{{ doc.route }}/" class="no-underline">
<a href = "{{ doc.route }}" class="no-underline">
<div class="row">
<div class="col-sm-4 bold">
<span class="indicator

View File

@ -469,7 +469,7 @@ scheduler_events = {
],
"daily_long": [
"erpnext.setup.doctype.email_digest.email_digest.send",
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_latest_price_in_all_boms",
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.auto_update_latest_price_in_all_boms",
"erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry.process_expired_allocation",
"erpnext.hr.utils.generate_leave_encashment",
"erpnext.hr.utils.allocate_earned_leaves",

View File

@ -735,9 +735,9 @@ def get_number_of_leave_days(
(Based on the include_holiday setting in Leave Type)"""
number_of_days = 0
if cint(half_day) == 1:
if from_date == to_date:
if getdate(from_date) == getdate(to_date):
number_of_days = 0.5
elif half_day_date and half_day_date <= to_date:
elif half_day_date and getdate(from_date) <= getdate(half_day_date) <= getdate(to_date):
number_of_days = date_diff(to_date, from_date) + 0.5
else:
number_of_days = date_diff(to_date, from_date) + 1

View File

@ -205,7 +205,12 @@ class TestLeaveApplication(unittest.TestCase):
# creates separate leave ledger entries
frappe.delete_doc_if_exists("Leave Type", "Test Leave Validation", force=1)
leave_type = frappe.get_doc(
dict(leave_type_name="Test Leave Validation", doctype="Leave Type", allow_negative=True)
dict(
leave_type_name="Test Leave Validation",
doctype="Leave Type",
allow_negative=True,
include_holiday=True,
)
).insert()
employee = get_employee()
@ -217,8 +222,14 @@ class TestLeaveApplication(unittest.TestCase):
# application across allocations
# CASE 1: from date has no allocation, to date has an allocation / both dates have allocation
start_date = add_days(year_start, -10)
application = make_leave_application(
employee.name, add_days(year_start, -10), add_days(year_start, 3), leave_type.name
employee.name,
start_date,
add_days(year_start, 3),
leave_type.name,
half_day=1,
half_day_date=start_date,
)
# 2 separate leave ledger entries
@ -828,6 +839,7 @@ class TestLeaveApplication(unittest.TestCase):
leave_type_name="_Test_CF_leave_expiry",
is_carry_forward=1,
expire_carry_forwarded_leaves_after_days=90,
include_holiday=True,
)
leave_type.submit()
@ -840,6 +852,8 @@ class TestLeaveApplication(unittest.TestCase):
leave_type=leave_type.name,
from_date=add_days(nowdate(), -3),
to_date=add_days(nowdate(), 7),
half_day=1,
half_day_date=add_days(nowdate(), -3),
description="_Test Reason",
company="_Test Company",
docstatus=1,
@ -855,7 +869,7 @@ class TestLeaveApplication(unittest.TestCase):
self.assertEqual(len(leave_ledger_entry), 2)
self.assertEqual(leave_ledger_entry[0].employee, leave_application.employee)
self.assertEqual(leave_ledger_entry[0].leave_type, leave_application.leave_type)
self.assertEqual(leave_ledger_entry[0].leaves, -9)
self.assertEqual(leave_ledger_entry[0].leaves, -8.5)
self.assertEqual(leave_ledger_entry[1].leaves, -2)
def test_leave_application_creation_after_expiry(self):

View File

@ -745,6 +745,8 @@ def calculate_amounts(against_loan, posting_date, payment_type=""):
if payment_type == "Loan Closure":
amounts["payable_principal_amount"] = amounts["pending_principal_amount"]
amounts["interest_amount"] += amounts["unaccrued_interest"]
amounts["payable_amount"] = amounts["payable_principal_amount"] + amounts["interest_amount"]
amounts["payable_amount"] = (
amounts["payable_principal_amount"] + amounts["interest_amount"] + amounts["penalty_amount"]
)
return amounts

View File

@ -697,15 +697,6 @@ class BOM(WebsiteGenerator):
self.scrap_material_cost = total_sm_cost
self.base_scrap_material_cost = base_total_sm_cost
def update_new_bom(self, old_bom, new_bom, rate):
for d in self.get("items"):
if d.bom_no != old_bom:
continue
d.bom_no = new_bom
d.rate = rate
d.amount = (d.stock_qty or d.qty) * rate
def update_exploded_items(self, save=True):
"""Update Flat BOM, following will be correct data"""
self.get_exploded_items()
@ -1025,7 +1016,7 @@ def get_bom_items_as_dict(
query = query.format(
table="BOM Scrap Item",
where_conditions="",
select_columns=", bom_item.idx, item.description, is_process_loss",
select_columns=", item.description, is_process_loss",
is_stock_item=is_stock_item,
qty_field="stock_qty",
)
@ -1038,7 +1029,7 @@ def get_bom_items_as_dict(
is_stock_item=is_stock_item,
qty_field="stock_qty" if fetch_qty_in_stock_uom else "qty",
select_columns=""", bom_item.uom, bom_item.conversion_factor, bom_item.source_warehouse,
bom_item.idx, bom_item.operation, bom_item.include_item_in_manufacturing, bom_item.sourced_by_supplier,
bom_item.operation, bom_item.include_item_in_manufacturing, bom_item.sourced_by_supplier,
bom_item.description, bom_item.base_rate as rate """,
)
items = frappe.db.sql(query, {"qty": qty, "bom": bom, "company": company}, as_dict=True)

View File

@ -0,0 +1,8 @@
// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.ui.form.on('BOM Update Log', {
// refresh: function(frm) {
// }
});

View File

@ -0,0 +1,109 @@
{
"actions": [],
"autoname": "BOM-UPDT-LOG-.#####",
"creation": "2022-03-16 14:23:35.210155",
"description": "BOM Update Tool Log with job status maintained",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"current_bom",
"new_bom",
"column_break_3",
"update_type",
"status",
"error_log",
"amended_from"
],
"fields": [
{
"fieldname": "current_bom",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Current BOM",
"options": "BOM"
},
{
"fieldname": "new_bom",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "New BOM",
"options": "BOM"
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "update_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Update Type",
"options": "Replace BOM\nUpdate Cost"
},
{
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "Queued\nIn Progress\nCompleted\nFailed"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "BOM Update Log",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "error_log",
"fieldtype": "Link",
"label": "Error Log",
"options": "Error Log"
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-03-31 12:51:44.885102",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM Update Log",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"submit": 1,
"write": 1
},
{
"create": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Manufacturing Manager",
"share": 1,
"submit": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@ -0,0 +1,164 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from typing import Dict, List, Literal, Optional
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cstr, flt
from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import update_cost
class BOMMissingError(frappe.ValidationError):
pass
class BOMUpdateLog(Document):
def validate(self):
if self.update_type == "Replace BOM":
self.validate_boms_are_specified()
self.validate_same_bom()
self.validate_bom_items()
self.status = "Queued"
def validate_boms_are_specified(self):
if self.update_type == "Replace BOM" and not (self.current_bom and self.new_bom):
frappe.throw(
msg=_("Please mention the Current and New BOM for replacement."),
title=_("Mandatory"),
exc=BOMMissingError,
)
def validate_same_bom(self):
if cstr(self.current_bom) == cstr(self.new_bom):
frappe.throw(_("Current BOM and New BOM can not be same"))
def validate_bom_items(self):
current_bom_item = frappe.db.get_value("BOM", self.current_bom, "item")
new_bom_item = frappe.db.get_value("BOM", self.new_bom, "item")
if current_bom_item != new_bom_item:
frappe.throw(_("The selected BOMs are not for the same item"))
def on_submit(self):
if frappe.flags.in_test:
return
if self.update_type == "Replace BOM":
boms = {"current_bom": self.current_bom, "new_bom": self.new_bom}
frappe.enqueue(
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.run_bom_job",
doc=self,
boms=boms,
timeout=40000,
)
else:
frappe.enqueue(
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.run_bom_job",
doc=self,
update_type="Update Cost",
timeout=40000,
)
def replace_bom(boms: Dict) -> None:
"""Replace current BOM with new BOM in parent BOMs."""
current_bom = boms.get("current_bom")
new_bom = boms.get("new_bom")
unit_cost = get_new_bom_unit_cost(new_bom)
update_new_bom_in_bom_items(unit_cost, current_bom, new_bom)
frappe.cache().delete_key("bom_children")
parent_boms = get_parent_boms(new_bom)
for bom in parent_boms:
bom_obj = frappe.get_doc("BOM", bom)
# this is only used for versioning and we do not want
# to make separate db calls by using load_doc_before_save
# which proves to be expensive while doing bulk replace
bom_obj._doc_before_save = bom_obj
bom_obj.update_exploded_items()
bom_obj.calculate_cost()
bom_obj.update_parent_cost()
bom_obj.db_update()
if bom_obj.meta.get("track_changes") and not bom_obj.flags.ignore_version:
bom_obj.save_version()
def update_new_bom_in_bom_items(unit_cost: float, current_bom: str, new_bom: str) -> None:
bom_item = frappe.qb.DocType("BOM Item")
(
frappe.qb.update(bom_item)
.set(bom_item.bom_no, new_bom)
.set(bom_item.rate, unit_cost)
.set(bom_item.amount, (bom_item.stock_qty * unit_cost))
.where(
(bom_item.bom_no == current_bom) & (bom_item.docstatus < 2) & (bom_item.parenttype == "BOM")
)
).run()
def get_parent_boms(new_bom: str, bom_list: Optional[List] = None) -> List:
bom_list = bom_list or []
bom_item = frappe.qb.DocType("BOM Item")
parents = (
frappe.qb.from_(bom_item)
.select(bom_item.parent)
.where((bom_item.bom_no == new_bom) & (bom_item.docstatus < 2) & (bom_item.parenttype == "BOM"))
.run(as_dict=True)
)
for d in parents:
if new_bom == d.parent:
frappe.throw(_("BOM recursion: {0} cannot be child of {1}").format(new_bom, d.parent))
bom_list.append(d.parent)
get_parent_boms(d.parent, bom_list)
return list(set(bom_list))
def get_new_bom_unit_cost(new_bom: str) -> float:
bom = frappe.qb.DocType("BOM")
new_bom_unitcost = (
frappe.qb.from_(bom).select(bom.total_cost / bom.quantity).where(bom.name == new_bom).run()
)
return flt(new_bom_unitcost[0][0])
def run_bom_job(
doc: "BOMUpdateLog",
boms: Optional[Dict[str, str]] = None,
update_type: Literal["Replace BOM", "Update Cost"] = "Replace BOM",
) -> None:
try:
doc.db_set("status", "In Progress")
if not frappe.flags.in_test:
frappe.db.commit()
frappe.db.auto_commit_on_many_writes = 1
boms = frappe._dict(boms or {})
if update_type == "Replace BOM":
replace_bom(boms)
else:
update_cost()
doc.db_set("status", "Completed")
except Exception:
frappe.db.rollback()
error_log = frappe.log_error(message=frappe.get_traceback(), title=_("BOM Update Tool Error"))
doc.db_set("status", "Failed")
doc.db_set("error_log", error_log.name)
finally:
frappe.db.auto_commit_on_many_writes = 0
frappe.db.commit() # nosemgrep

View File

@ -0,0 +1,13 @@
frappe.listview_settings['BOM Update Log'] = {
add_fields: ["status"],
get_indicator: function(doc) {
let status_map = {
"Queued": "orange",
"In Progress": "blue",
"Completed": "green",
"Failed": "red"
};
return [__(doc.status), status_map[doc.status], "status,=," + doc.status];
}
};

View File

@ -0,0 +1,96 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
import frappe
from frappe.tests.utils import FrappeTestCase
from erpnext.manufacturing.doctype.bom_update_log.bom_update_log import (
BOMMissingError,
run_bom_job,
)
from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import enqueue_replace_bom
test_records = frappe.get_test_records("BOM")
class TestBOMUpdateLog(FrappeTestCase):
"Test BOM Update Tool Operations via BOM Update Log."
def setUp(self):
bom_doc = frappe.copy_doc(test_records[0])
bom_doc.items[1].item_code = "_Test Item"
bom_doc.insert()
self.boms = frappe._dict(
current_bom="BOM-_Test Item Home Desktop Manufactured-001",
new_bom=bom_doc.name,
)
self.new_bom_doc = bom_doc
def tearDown(self):
frappe.db.rollback()
if self._testMethodName == "test_bom_update_log_completion":
# clear logs and delete BOM created via setUp
frappe.db.delete("BOM Update Log")
self.new_bom_doc.cancel()
self.new_bom_doc.delete()
# explicitly commit and restore to original state
frappe.db.commit() # nosemgrep
def test_bom_update_log_validate(self):
"Test if BOM presence is validated."
with self.assertRaises(BOMMissingError):
enqueue_replace_bom(boms={})
with self.assertRaises(frappe.ValidationError):
enqueue_replace_bom(boms=frappe._dict(current_bom=self.boms.new_bom, new_bom=self.boms.new_bom))
with self.assertRaises(frappe.ValidationError):
enqueue_replace_bom(boms=frappe._dict(current_bom=self.boms.new_bom, new_bom="Dummy BOM"))
def test_bom_update_log_queueing(self):
"Test if BOM Update Log is created and queued."
log = enqueue_replace_bom(
boms=self.boms,
)
self.assertEqual(log.docstatus, 1)
self.assertEqual(log.status, "Queued")
def test_bom_update_log_completion(self):
"Test if BOM Update Log handles job completion correctly."
log = enqueue_replace_bom(
boms=self.boms,
)
# Explicitly commits log, new bom (setUp) and replacement impact.
# Is run via background jobs IRL
run_bom_job(
doc=log,
boms=self.boms,
update_type="Replace BOM",
)
log.reload()
self.assertEqual(log.status, "Completed")
# teardown (undo replace impact) due to commit
boms = frappe._dict(
current_bom=self.boms.new_bom,
new_bom=self.boms.current_bom,
)
log2 = enqueue_replace_bom(
boms=self.boms,
)
run_bom_job( # Explicitly commits
doc=log2,
boms=boms,
update_type="Replace BOM",
)
self.assertEqual(log2.status, "Completed")

View File

@ -20,30 +20,67 @@ frappe.ui.form.on('BOM Update Tool', {
refresh: function(frm) {
frm.disable_save();
frm.events.disable_button(frm, "replace");
frm.add_custom_button(__("View BOM Update Log"), () => {
frappe.set_route("List", "BOM Update Log");
});
},
replace: function(frm) {
disable_button: (frm, field, disable=true) => {
frm.get_field(field).input.disabled = disable;
},
current_bom: (frm) => {
if (frm.doc.current_bom && frm.doc.new_bom) {
frm.events.disable_button(frm, "replace", false);
}
},
new_bom: (frm) => {
if (frm.doc.current_bom && frm.doc.new_bom) {
frm.events.disable_button(frm, "replace", false);
}
},
replace: (frm) => {
if (frm.doc.current_bom && frm.doc.new_bom) {
frappe.call({
method: "erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.enqueue_replace_bom",
freeze: true,
args: {
args: {
boms: {
"current_bom": frm.doc.current_bom,
"new_bom": frm.doc.new_bom
}
},
callback: result => {
if (result && result.message && !result.exc) {
frm.events.confirm_job_start(frm, result.message);
}
}
});
}
},
update_latest_price_in_all_boms: function() {
update_latest_price_in_all_boms: (frm) => {
frappe.call({
method: "erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.enqueue_update_cost",
freeze: true,
callback: function() {
frappe.msgprint(__("Latest price updated in all BOMs"));
callback: result => {
if (result && result.message && !result.exc) {
frm.events.confirm_job_start(frm, result.message);
}
}
});
},
confirm_job_start: (frm, log_data) => {
let log_link = frappe.utils.get_form_link("BOM Update Log", log_data.name, true);
frappe.msgprint({
"message": __("BOM Updation is queued and may take a few minutes. Check {0} for progress.", [log_link]),
"title": __("BOM Update Initiated"),
"indicator": "blue"
});
}
});

View File

@ -1,136 +1,69 @@
# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
import json
from typing import TYPE_CHECKING, Dict, Literal, Optional, Union
if TYPE_CHECKING:
from erpnext.manufacturing.doctype.bom_update_log.bom_update_log import BOMUpdateLog
import click
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import cstr, flt
from erpnext.manufacturing.doctype.bom.bom import get_boms_in_bottom_up_order
class BOMUpdateTool(Document):
def replace_bom(self):
self.validate_bom()
unit_cost = get_new_bom_unit_cost(self.new_bom)
self.update_new_bom(unit_cost)
frappe.cache().delete_key("bom_children")
bom_list = self.get_parent_boms(self.new_bom)
with click.progressbar(bom_list) as bom_list:
pass
for bom in bom_list:
try:
bom_obj = frappe.get_cached_doc("BOM", bom)
# this is only used for versioning and we do not want
# to make separate db calls by using load_doc_before_save
# which proves to be expensive while doing bulk replace
bom_obj._doc_before_save = bom_obj
bom_obj.update_new_bom(self.current_bom, self.new_bom, unit_cost)
bom_obj.update_exploded_items()
bom_obj.calculate_cost()
bom_obj.update_parent_cost()
bom_obj.db_update()
if bom_obj.meta.get("track_changes") and not bom_obj.flags.ignore_version:
bom_obj.save_version()
except Exception:
frappe.log_error(frappe.get_traceback())
def validate_bom(self):
if cstr(self.current_bom) == cstr(self.new_bom):
frappe.throw(_("Current BOM and New BOM can not be same"))
if frappe.db.get_value("BOM", self.current_bom, "item") != frappe.db.get_value(
"BOM", self.new_bom, "item"
):
frappe.throw(_("The selected BOMs are not for the same item"))
def update_new_bom(self, unit_cost):
frappe.db.sql(
"""update `tabBOM Item` set bom_no=%s,
rate=%s, amount=stock_qty*%s where bom_no = %s and docstatus < 2 and parenttype='BOM'""",
(self.new_bom, unit_cost, unit_cost, self.current_bom),
)
def get_parent_boms(self, bom, bom_list=None):
if bom_list is None:
bom_list = []
data = frappe.db.sql(
"""SELECT DISTINCT parent FROM `tabBOM Item`
WHERE bom_no = %s AND docstatus < 2 AND parenttype='BOM'""",
bom,
)
for d in data:
if self.new_bom == d[0]:
frappe.throw(_("BOM recursion: {0} cannot be child of {1}").format(bom, self.new_bom))
bom_list.append(d[0])
self.get_parent_boms(d[0], bom_list)
return list(set(bom_list))
def get_new_bom_unit_cost(bom):
new_bom_unitcost = frappe.db.sql(
"""SELECT `total_cost`/`quantity`
FROM `tabBOM` WHERE name = %s""",
bom,
)
return flt(new_bom_unitcost[0][0]) if new_bom_unitcost else 0
pass
@frappe.whitelist()
def enqueue_replace_bom(args):
if isinstance(args, str):
args = json.loads(args)
def enqueue_replace_bom(
boms: Optional[Union[Dict, str]] = None, args: Optional[Union[Dict, str]] = None
) -> "BOMUpdateLog":
"""Returns a BOM Update Log (that queues a job) for BOM Replacement."""
boms = boms or args
if isinstance(boms, str):
boms = json.loads(boms)
frappe.enqueue(
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.replace_bom",
args=args,
timeout=40000,
)
frappe.msgprint(_("Queued for replacing the BOM. It may take a few minutes."))
update_log = create_bom_update_log(boms=boms)
return update_log
@frappe.whitelist()
def enqueue_update_cost():
frappe.enqueue(
"erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool.update_cost", timeout=40000
)
frappe.msgprint(
_("Queued for updating latest price in all Bill of Materials. It may take a few minutes.")
)
def enqueue_update_cost() -> "BOMUpdateLog":
"""Returns a BOM Update Log (that queues a job) for BOM Cost Updation."""
update_log = create_bom_update_log(update_type="Update Cost")
return update_log
def update_latest_price_in_all_boms():
def auto_update_latest_price_in_all_boms() -> None:
"""Called via hooks.py."""
if frappe.db.get_single_value("Manufacturing Settings", "update_bom_costs_automatically"):
update_cost()
def replace_bom(args):
frappe.db.auto_commit_on_many_writes = 1
args = frappe._dict(args)
doc = frappe.get_doc("BOM Update Tool")
doc.current_bom = args.current_bom
doc.new_bom = args.new_bom
doc.replace_bom()
frappe.db.auto_commit_on_many_writes = 0
def update_cost():
frappe.db.auto_commit_on_many_writes = 1
def update_cost() -> None:
"""Updates Cost for all BOMs from bottom to top."""
bom_list = get_boms_in_bottom_up_order()
for bom in bom_list:
frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True)
frappe.db.auto_commit_on_many_writes = 0
def create_bom_update_log(
boms: Optional[Dict[str, str]] = None,
update_type: Literal["Replace BOM", "Update Cost"] = "Replace BOM",
) -> "BOMUpdateLog":
"""Creates a BOM Update Log that handles the background job."""
boms = boms or {}
current_bom = boms.get("current_bom")
new_bom = boms.get("new_bom")
return frappe.get_doc(
{
"doctype": "BOM Update Log",
"current_bom": current_bom,
"new_bom": new_bom,
"update_type": update_type,
}
).submit()

View File

@ -4,6 +4,7 @@
import frappe
from frappe.tests.utils import FrappeTestCase
from erpnext.manufacturing.doctype.bom_update_log.bom_update_log import replace_bom
from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import update_cost
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
from erpnext.stock.doctype.item.test_item import create_item
@ -12,6 +13,8 @@ test_records = frappe.get_test_records("BOM")
class TestBOMUpdateTool(FrappeTestCase):
"Test major functions run via BOM Update Tool."
def test_replace_bom(self):
current_bom = "BOM-_Test Item Home Desktop Manufactured-001"
@ -19,18 +22,16 @@ class TestBOMUpdateTool(FrappeTestCase):
bom_doc.items[1].item_code = "_Test Item"
bom_doc.insert()
update_tool = frappe.get_doc("BOM Update Tool")
update_tool.current_bom = current_bom
update_tool.new_bom = bom_doc.name
update_tool.replace_bom()
boms = frappe._dict(current_bom=current_bom, new_bom=bom_doc.name)
replace_bom(boms)
self.assertFalse(frappe.db.sql("select name from `tabBOM Item` where bom_no=%s", current_bom))
self.assertTrue(frappe.db.sql("select name from `tabBOM Item` where bom_no=%s", bom_doc.name))
# reverse, as it affects other testcases
update_tool.current_bom = bom_doc.name
update_tool.new_bom = current_bom
update_tool.replace_bom()
boms.current_bom = bom_doc.name
boms.new_bom = current_bom
replace_bom(boms)
def test_bom_cost(self):
for item in ["BOM Cost Test Item 1", "BOM Cost Test Item 2", "BOM Cost Test Item 3"]:

View File

@ -1114,6 +1114,36 @@ class TestWorkOrder(FrappeTestCase):
except frappe.MandatoryError:
self.fail("Batch generation causing failing in Work Order")
@change_settings(
"Manufacturing Settings",
{"backflush_raw_materials_based_on": "Material Transferred for Manufacture"},
)
def test_manufacture_entry_mapped_idx_with_exploded_bom(self):
"""Test if WO containing BOM with partial exploded items and scrap items, maps idx correctly."""
test_stock_entry.make_stock_entry(
item_code="_Test Item",
target="_Test Warehouse - _TC",
basic_rate=5000.0,
qty=2,
)
test_stock_entry.make_stock_entry(
item_code="_Test Item Home Desktop 100",
target="_Test Warehouse - _TC",
basic_rate=1000.0,
qty=2,
)
wo_order = make_wo_order_test_record(
qty=1,
use_multi_level_bom=1,
skip_transfer=1,
)
ste_manu = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 1))
for index, row in enumerate(ste_manu.get("items"), start=1):
self.assertEqual(index, row.idx)
def update_job_card(job_card, jc_qty=None):
employee = frappe.db.get_value("Employee", {"status": "Active"}, "name")

View File

@ -1327,7 +1327,7 @@ def get_serial_nos_for_job_card(row, wo_doc):
used_serial_nos.extend(get_serial_nos(d.serial_no))
serial_nos = sorted(list(set(serial_nos) - set(used_serial_nos)))
row.serial_no = "\n".join(serial_nos[0 : row.job_card_qty])
row.serial_no = "\n".join(serial_nos[0 : cint(row.job_card_qty)])
def validate_operation_data(row):

View File

@ -147,6 +147,8 @@ class AdditionalSalary(Document):
@frappe.whitelist()
def get_additional_salaries(employee, start_date, end_date, component_type):
from frappe.query_builder import Criterion
comp_type = "Earning" if component_type == "earnings" else "Deduction"
additional_sal = frappe.qb.DocType("Additional Salary")
@ -170,8 +172,23 @@ def get_additional_salaries(employee, start_date, end_date, component_type):
& (additional_sal.type == comp_type)
)
.where(
additional_sal.payroll_date[start_date:end_date]
| ((additional_sal.from_date <= end_date) & (additional_sal.to_date >= end_date))
Criterion.any(
[
Criterion.all(
[ # is recurring and additional salary dates fall within the payroll period
additional_sal.is_recurring == 1,
additional_sal.from_date <= end_date,
additional_sal.to_date >= end_date,
]
),
Criterion.all(
[ # is not recurring and additional salary's payroll date falls within the payroll period
additional_sal.is_recurring == 0,
additional_sal.payroll_date[start_date:end_date],
]
),
]
)
)
.run(as_dict=True)
)

View File

@ -4,7 +4,8 @@
import unittest
import frappe
from frappe.utils import add_days, nowdate
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, add_months, nowdate
import erpnext
from erpnext.hr.doctype.employee.test_employee import make_employee
@ -16,19 +17,10 @@ from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
class TestAdditionalSalary(unittest.TestCase):
class TestAdditionalSalary(FrappeTestCase):
def setUp(self):
setup_test()
def tearDown(self):
for dt in [
"Salary Slip",
"Additional Salary",
"Salary Structure Assignment",
"Salary Structure",
]:
frappe.db.sql("delete from `tab%s`" % dt)
def test_recurring_additional_salary(self):
amount = 0
salary_component = None
@ -46,19 +38,66 @@ class TestAdditionalSalary(unittest.TestCase):
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertEqual(amount, add_sal.amount)
self.assertEqual(salary_component, add_sal.salary_component)
def test_non_recurring_additional_salary(self):
amount = 0
salary_component = None
date = nowdate()
def get_additional_salary(emp_id):
emp_id = make_employee("test_additional@salary.com")
frappe.db.set_value("Employee", emp_id, "relieving_date", add_days(date, 1800))
salary_structure = make_salary_structure(
"Test Salary Structure Additional Salary", "Monthly", employee=emp_id
)
add_sal = get_additional_salary(emp_id, recurring=False, payroll_date=date)
ss = make_employee_salary_slip(
"test_additional@salary.com", "Monthly", salary_structure=salary_structure.name
)
amount, salary_component = None, None
for earning in ss.earnings:
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertEqual(amount, add_sal.amount)
self.assertEqual(salary_component, add_sal.salary_component)
# should not show up in next months
ss.posting_date = add_months(date, 1)
ss.start_date = ss.end_date = None
ss.earnings = []
ss.deductions = []
ss.save()
amount, salary_component = None, None
for earning in ss.earnings:
if earning.salary_component == "Recurring Salary Component":
amount = earning.amount
salary_component = earning.salary_component
break
self.assertIsNone(amount)
self.assertIsNone(salary_component)
def get_additional_salary(emp_id, recurring=True, payroll_date=None):
create_salary_component("Recurring Salary Component")
add_sal = frappe.new_doc("Additional Salary")
add_sal.employee = emp_id
add_sal.salary_component = "Recurring Salary Component"
add_sal.is_recurring = 1
add_sal.is_recurring = 1 if recurring else 0
add_sal.from_date = add_days(nowdate(), -50)
add_sal.to_date = add_days(nowdate(), 180)
add_sal.payroll_date = payroll_date
add_sal.amount = 5000
add_sal.currency = erpnext.get_default_currency()
add_sal.save()

View File

@ -1290,7 +1290,16 @@ def create_additional_salary(employee, payroll_period, amount):
return salary_date
def make_leave_application(employee, from_date, to_date, leave_type, company=None, submit=True):
def make_leave_application(
employee,
from_date,
to_date,
leave_type,
company=None,
half_day=False,
half_day_date=None,
submit=True,
):
leave_application = frappe.get_doc(
dict(
doctype="Leave Application",
@ -1298,6 +1307,8 @@ def make_leave_application(employee, from_date, to_date, leave_type, company=Non
leave_type=leave_type,
from_date=from_date,
to_date=to_date,
half_day=half_day,
half_day_date=half_day_date,
company=company or erpnext.get_default_company() or "_Test Company",
status="Approved",
leave_approver="test@example.com",

View File

@ -689,7 +689,12 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
}));
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
if (this.frm.doc.write_off_outstanding_amount_automatically) {
this.frm.doc.write_off_amount = 0;
}
this.calculate_outstanding_amount(update_paid_amount);
this.calculate_write_off_amount();
}
is_internal_invoice() {
@ -825,26 +830,23 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
var base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total;
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total +
this.frm.doc.write_off_amount, precision("change_amount"));
this.frm.doc.change_amount = flt(this.frm.doc.paid_amount - grand_total,
precision("change_amount"));
this.frm.doc.base_change_amount = flt(this.frm.doc.base_paid_amount -
base_grand_total + this.frm.doc.base_write_off_amount,
precision("base_change_amount"));
base_grand_total, precision("base_change_amount"));
}
}
}
calculate_write_off_amount(){
if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
this.frm.doc.write_off_amount = flt(this.frm.doc.grand_total - this.frm.doc.paid_amount
+ this.frm.doc.change_amount, precision("write_off_amount"));
calculate_write_off_amount() {
if(this.frm.doc.write_off_outstanding_amount_automatically) {
this.frm.doc.write_off_amount = flt(this.frm.doc.outstanding_amount, precision("write_off_amount"));
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
precision("base_write_off_amount"));
}else{
this.frm.doc.paid_amount = 0.0;
this.calculate_outstanding_amount(false);
}
this.calculate_outstanding_amount(false);
}
};

View File

@ -403,17 +403,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
var sms_man = new erpnext.SMSManager(this.frm.doc);
}
barcode(doc, cdt, cdn) {
const d = locals[cdt][cdn];
if (!d.barcode) {
// barcode cleared, remove item
d.item_code = "";
}
// flag required for circular triggers
d._triggerd_from_barcode = true;
this.item_code(doc, cdt, cdn);
}
item_code(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
@ -431,9 +420,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
this.frm.doc.doctype === 'Delivery Note') {
show_batch_dialog = 1;
}
if (!item._triggerd_from_barcode) {
item.barcode = null;
}
item.barcode = null;
if(item.item_code || item.barcode || item.serial_no) {
@ -539,6 +526,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
if(!d[k]) d[k] = v;
});
if (d.__disable_batch_serial_selector) {
// reset for future use.
d.__disable_batch_serial_selector = false;
return;
}
if (d.has_batch_no && d.has_serial_no) {
d.batch_no = undefined;
}

View File

@ -21,9 +21,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
// batch_no: "LOT12", // present if batch was scanned
// serial_no: "987XYZ", // present if serial no was scanned
// }
this.scan_api =
opts.scan_api ||
"erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number";
this.scan_api = opts.scan_api || "erpnext.stock.utils.scan_barcode";
}
process_scan() {
@ -52,14 +50,16 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
return;
}
me.update_table(data.item_code, data.barcode, data.batch_no, data.serial_no);
me.update_table(data);
});
}
update_table(item_code, barcode, batch_no, serial_no) {
update_table(data) {
let cur_grid = this.frm.fields_dict[this.items_table_name].grid;
let row = null;
const {item_code, barcode, batch_no, serial_no} = data;
// Check if batch is scanned and table has batch no field
let batch_no_scan =
Boolean(batch_no) && frappe.meta.has_field(cur_grid.doctype, this.batch_no_field);
@ -84,6 +84,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
}
this.show_scan_message(row.idx, row.item_code);
this.set_selector_trigger_flag(row, data);
this.set_item(row, item_code);
this.set_serial_no(row, serial_no);
this.set_batch_no(row, batch_no);
@ -91,6 +92,19 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
this.clean_up();
}
// batch and serial selector is reduandant when all info can be added by scan
// this flag on item row is used by transaction.js to avoid triggering selector
set_selector_trigger_flag(row, data) {
const {batch_no, serial_no, has_batch_no, has_serial_no} = data;
const require_selecting_batch = has_batch_no && !batch_no;
const require_selecting_serial = has_serial_no && !serial_no;
if (!(require_selecting_batch || require_selecting_serial)) {
row.__disable_batch_serial_selector = true;
}
}
set_item(row, item_code) {
const item_data = { item_code: item_code };
item_data[this.qty_field] = (row[this.qty_field] || 0) + 1;

View File

@ -268,6 +268,7 @@ def get_regional_address_details(party_details, doctype, company):
if tax_template_by_category:
party_details["taxes_and_charges"] = tax_template_by_category
party_details["taxes"] = get_taxes_and_charges(master_doctype, tax_template_by_category)
return party_details
if not party_details.place_of_supply:
@ -292,7 +293,7 @@ def get_regional_address_details(party_details, doctype, company):
return party_details
party_details["taxes_and_charges"] = default_tax
party_details.taxes = get_taxes_and_charges(master_doctype, default_tax)
party_details["taxes"] = get_taxes_and_charges(master_doctype, default_tax)
return party_details

View File

@ -3,12 +3,14 @@
import json
from typing import Dict, Optional
import frappe
from frappe.utils.nestedset import get_root_of
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability
from erpnext.accounts.doctype.pos_profile.pos_profile import get_child_nodes, get_item_groups
from erpnext.stock.utils import scan_barcode
def search_by_term(search_term, warehouse, price_list):
@ -150,29 +152,8 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
@frappe.whitelist()
def search_for_serial_or_batch_or_barcode_number(search_value):
# search barcode no
barcode_data = frappe.db.get_value(
"Item Barcode", {"barcode": search_value}, ["barcode", "parent as item_code"], as_dict=True
)
if barcode_data:
return barcode_data
# search serial no
serial_no_data = frappe.db.get_value(
"Serial No", search_value, ["name as serial_no", "item_code"], as_dict=True
)
if serial_no_data:
return serial_no_data
# search batch no
batch_no_data = frappe.db.get_value(
"Batch", search_value, ["name as batch_no", "item as item_code"], as_dict=True
)
if batch_no_data:
return batch_no_data
return {}
def search_for_serial_or_batch_or_barcode_number(search_value: str) -> Dict[str, Optional[str]]:
return scan_barcode(search_value)
def get_conditions(search_term):

View File

@ -177,11 +177,11 @@ def get_customer_details():
def get_item_details():
details = frappe.db.get_all("Item", fields=["item_code", "item_name", "item_group"])
details = frappe.db.get_all("Item", fields=["name", "item_name", "item_group"])
item_details = {}
for d in details:
item_details.setdefault(
d.item_code, frappe._dict({"item_name": d.item_name, "item_group": d.item_group})
d.name, frappe._dict({"item_name": d.item_name, "item_group": d.item_group})
)
return item_details

View File

@ -14,7 +14,7 @@ def get_data():
"goal_doctype_link": "company",
"goal_field": "base_grand_total",
"date_field": "posting_date",
"filter_str": "docstatus = 1 and is_opening != 'Yes'",
"filters": {"docstatus": 1, "is_opening": ("!=", "Yes")},
"aggregation": "sum",
},
"fieldname": "company",

View File

@ -1,4 +1,4 @@
<div>
<div class="stock-levels">
<div class="result">
</div>
<div class="more hidden" style="padding: 15px;">

View File

@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "MAT-BIN-.YYYY.-.#####",
"autoname": "hash",
"creation": "2013-01-10 16:34:25",
"doctype": "DocType",
"engine": "InnoDB",
@ -171,11 +171,11 @@
"idx": 1,
"in_create": 1,
"links": [],
"modified": "2022-01-30 17:04:54.715288",
"modified": "2022-03-30 07:22:23.868602",
"modified_by": "Administrator",
"module": "Stock",
"name": "Bin",
"naming_rule": "Expression (old style)",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [
{

View File

@ -280,8 +280,11 @@ class DeliveryNote(SellingController):
)
if bypass_credit_limit_check_at_sales_order:
validate_against_credit_limit = True
extra_amount = self.base_grand_total
for d in self.get("items"):
if not d.against_sales_invoice:
validate_against_credit_limit = True
extra_amount = self.base_grand_total
break
else:
for d in self.get("items"):
if not (d.against_sales_order or d.against_sales_invoice):

View File

@ -74,6 +74,7 @@
"against_sales_invoice",
"si_detail",
"dn_detail",
"pick_list_item",
"section_break_40",
"batch_no",
"serial_no",
@ -762,13 +763,22 @@
"fieldtype": "Check",
"label": "Grant Commission",
"read_only": 1
},
{
"fieldname": "pick_list_item",
"fieldtype": "Data",
"hidden": 1,
"label": "Pick List Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-02-24 14:42:20.211085",
"modified": "2022-03-31 18:36:24.671913",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",

View File

@ -1,109 +1,42 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:barcode",
"beta": 0,
"creation": "2017-12-09 18:54:50.562438",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"actions": [],
"autoname": "hash",
"creation": "2022-02-11 11:26:22.155183",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"barcode",
"barcode_type"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "barcode",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Barcode",
"length": 0,
"no_copy": 1,
"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,
"translatable": 0,
"fieldname": "barcode",
"fieldtype": "Data",
"in_global_search": 1,
"in_list_view": 1,
"label": "Barcode",
"no_copy": 1,
"unique": 1
},
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "barcode_type",
"fieldtype": "Select",
"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": "Barcode Type",
"length": 0,
"no_copy": 0,
"options": "\nEAN\nUPC-A",
"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,
"translatable": 0,
"unique": 0
"fieldname": "barcode_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Barcode Type",
"options": "\nEAN\nUPC-A"
}
],
"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": "2018-11-13 06:03:09.814357",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Barcode",
"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,
"track_views": 0
],
"istable": 1,
"links": [],
"modified": "2022-04-01 05:54:27.314030",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Barcode",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}

View File

@ -534,6 +534,7 @@ def map_pl_locations(pick_list, item_mapper, delivery_note, sales_order=None):
dn_item = map_child_doc(source_doc, delivery_note, table_mapper)
if dn_item:
dn_item.pick_list_item = location.name
dn_item.warehouse = location.warehouse
dn_item.qty = flt(location.picked_qty) / (flt(location.conversion_factor) or 1)
dn_item.batch_no = location.batch_no

View File

@ -521,6 +521,8 @@ class TestPickList(FrappeTestCase):
for dn_item in frappe.get_doc("Delivery Note", dn.name).get("items"):
self.assertEqual(dn_item.item_code, "_Test Item")
self.assertEqual(dn_item.against_sales_order, sales_order_1.name)
self.assertEqual(dn_item.pick_list_item, pick_list.locations[dn_item.idx - 1].name)
for dn in frappe.get_all(
"Delivery Note",
filters={"pick_list": pick_list.name, "customer": "_Test Customer 1"},

View File

@ -1,6 +1,6 @@
{
"actions": [],
"autoname": "REPOST-ITEM-VAL-.######",
"autoname": "hash",
"creation": "2022-01-11 15:03:38.273179",
"doctype": "DocType",
"editable_grid": 1,
@ -177,11 +177,11 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-01-18 10:57:33.450907",
"modified": "2022-03-30 07:22:48.520266",
"modified_by": "Administrator",
"module": "Stock",
"name": "Repost Item Valuation",
"naming_rule": "Expression (old style)",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [
{

View File

@ -646,21 +646,6 @@ frappe.ui.form.on('Stock Entry Detail', {
frm.events.calculate_basic_amount(frm, item);
},
barcode: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.barcode) {
frappe.call({
method: "erpnext.stock.get_item_details.get_item_code",
args: {"barcode": d.barcode },
callback: function(r) {
if (!r.exe){
frappe.model.set_value(cdt, cdn, "item_code", r.message);
}
}
});
}
},
uom: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.uom && d.item_code){

View File

@ -225,12 +225,16 @@ class StockEntry(StockController):
def set_transfer_qty(self):
for item in self.get("items"):
if not flt(item.qty):
frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx))
frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx), title=_("Zero quantity"))
if not flt(item.conversion_factor):
frappe.throw(_("Row {0}: UOM Conversion Factor is mandatory").format(item.idx))
item.transfer_qty = flt(
flt(item.qty) * flt(item.conversion_factor), self.precision("transfer_qty", item)
)
if not flt(item.transfer_qty):
frappe.throw(
_("Row {0}: Qty in Stock UOM can not be zero.").format(item.idx), title=_("Zero quantity")
)
def update_cost_in_project(self):
if self.work_order and not frappe.db.get_value(
@ -1382,7 +1386,6 @@ class StockEntry(StockController):
if self.purpose != "Send to Subcontractor" and self.purpose in ["Manufacture", "Repack"]:
scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
for item in scrap_item_dict.values():
item.idx = ""
if self.pro_doc and self.pro_doc.scrap_warehouse:
item["to_warehouse"] = self.pro_doc.scrap_warehouse
@ -1898,7 +1901,6 @@ class StockEntry(StockController):
se_child.is_process_loss = item_row.get("is_process_loss", 0)
for field in [
"idx",
"po_detail",
"original_item",
"expense_account",

View File

@ -51,7 +51,6 @@ class TestStockEntry(FrappeTestCase):
def tearDown(self):
frappe.db.rollback()
frappe.set_user("Administrator")
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0")
def test_fifo(self):
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
@ -767,13 +766,12 @@ class TestStockEntry(FrappeTestCase):
fg_cost, flt(rm_cost + bom_operation_cost + work_order.additional_operating_cost, 2)
)
@change_settings("Manufacturing Settings", {"material_consumption": 1})
def test_work_order_manufacture_with_material_consumption(self):
from erpnext.manufacturing.doctype.work_order.work_order import (
make_stock_entry as _make_stock_entry,
)
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "1")
bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item", "is_default": 1, "docstatus": 1})
work_order = frappe.new_doc("Work Order")
@ -983,43 +981,6 @@ class TestStockEntry(FrappeTestCase):
repack.insert()
self.assertRaises(frappe.ValidationError, repack.submit)
# def test_material_consumption(self):
# frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM")
# frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0")
# from erpnext.manufacturing.doctype.work_order.work_order \
# import make_stock_entry as _make_stock_entry
# bom_no = frappe.db.get_value("BOM", {"item": "_Test FG Item 2",
# "is_default": 1, "docstatus": 1})
# work_order = frappe.new_doc("Work Order")
# work_order.update({
# "company": "_Test Company",
# "fg_warehouse": "_Test Warehouse 1 - _TC",
# "production_item": "_Test FG Item 2",
# "bom_no": bom_no,
# "qty": 4.0,
# "stock_uom": "_Test UOM",
# "wip_warehouse": "_Test Warehouse - _TC",
# "additional_operating_cost": 1000,
# "use_multi_level_bom": 1
# })
# work_order.insert()
# work_order.submit()
# make_stock_entry(item_code="_Test Serialized Item With Series", target="_Test Warehouse - _TC", qty=50, basic_rate=100)
# make_stock_entry(item_code="_Test Item 2", target="_Test Warehouse - _TC", qty=50, basic_rate=20)
# item_quantity = {
# '_Test Item': 2.0,
# '_Test Item 2': 12.0,
# '_Test Serialized Item With Series': 6.0
# }
# stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Material Consumption for Manufacture", 2))
# for d in stock_entry.get('items'):
# self.assertEqual(item_quantity.get(d.item_code), d.qty)
def test_customer_provided_parts_se(self):
create_item(
"CUST-0987", is_customer_provided_item=1, customer="_Test Customer", is_purchase_item=0
@ -1358,6 +1319,13 @@ class TestStockEntry(FrappeTestCase):
issue.reload() # reload because reposting current voucher updates rate
self.assertEqual(issue.value_difference, -30)
def test_transfer_qty_validation(self):
se = make_stock_entry(item_code="_Test Item", do_not_save=True, qty=0.001, rate=100)
se.items[0].uom = "Kg"
se.items[0].conversion_factor = 0.002
self.assertRaises(frappe.ValidationError, se.save)
def make_serialized_item(**args):
args = frappe._dict(args)

View File

@ -163,20 +163,7 @@ frappe.ui.form.on("Stock Reconciliation", {
});
}
},
set_item_code: function(doc, cdt, cdn) {
var d = frappe.model.get_doc(cdt, cdn);
if (d.barcode) {
frappe.call({
method: "erpnext.stock.get_item_details.get_item_code",
args: {"barcode": d.barcode },
callback: function(r) {
if (!r.exe){
frappe.model.set_value(cdt, cdn, "item_code", r.message);
}
}
});
}
},
set_amount_quantity: function(doc, cdt, cdn) {
var d = frappe.model.get_doc(cdt, cdn);
if (d.qty & d.valuation_rate) {
@ -214,9 +201,6 @@ frappe.ui.form.on("Stock Reconciliation", {
});
frappe.ui.form.on("Stock Reconciliation Item", {
barcode: function(frm, cdt, cdn) {
frm.events.set_item_code(frm, cdt, cdn);
},
warehouse: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];

View File

@ -167,6 +167,9 @@ def update_stock(args, out):
reserved_so = get_so_reservation_for_item(args)
out.serial_no = get_serial_no(out, args.serial_no, sales_order=reserved_so)
if not out.serial_no:
out.pop("serial_no", None)
def set_valuation_rate(out, args):
if frappe.db.exists("Product Bundle", args.item_code, cache=True):

View File

@ -0,0 +1,31 @@
import frappe
from frappe.tests.utils import FrappeTestCase
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.stock.utils import scan_barcode
class TestStockUtilities(FrappeTestCase):
def test_barcode_scanning(self):
simple_item = make_item(properties={"barcodes": [{"barcode": "12399"}]})
self.assertEqual(scan_barcode("12399")["item_code"], simple_item.name)
batch_item = make_item(properties={"has_batch_no": 1, "create_new_batch": 1})
batch = frappe.get_doc(doctype="Batch", item=batch_item.name).insert()
batch_scan = scan_barcode(batch.name)
self.assertEqual(batch_scan["item_code"], batch_item.name)
self.assertEqual(batch_scan["batch_no"], batch.name)
self.assertEqual(batch_scan["has_batch_no"], 1)
self.assertEqual(batch_scan["has_serial_no"], 0)
serial_item = make_item(properties={"has_serial_no": 1})
serial = frappe.get_doc(
doctype="Serial No", item_code=serial_item.name, serial_no=frappe.generate_hash()
).insert()
serial_scan = scan_barcode(serial.name)
self.assertEqual(serial_scan["item_code"], serial_item.name)
self.assertEqual(serial_scan["serial_no"], serial.name)
self.assertEqual(serial_scan["has_batch_no"], 0)
self.assertEqual(serial_scan["has_serial_no"], 1)

View File

@ -3,6 +3,7 @@
import json
from typing import Dict, Optional
import frappe
from frappe import _
@ -526,7 +527,7 @@ def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool
filters = {
"docstatus": 1,
"status": ["in", ["Queued", "In Progress", "Failed"]],
"status": ["in", ["Queued", "In Progress"]],
"posting_date": ["<=", posting_date],
}
@ -548,3 +549,51 @@ def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool
)
return bool(reposting_pending)
@frappe.whitelist()
def scan_barcode(search_value: str) -> Dict[str, Optional[str]]:
# search barcode no
barcode_data = frappe.db.get_value(
"Item Barcode",
{"barcode": search_value},
["barcode", "parent as item_code"],
as_dict=True,
)
if barcode_data:
return _update_item_info(barcode_data)
# search serial no
serial_no_data = frappe.db.get_value(
"Serial No",
search_value,
["name as serial_no", "item_code", "batch_no"],
as_dict=True,
)
if serial_no_data:
return _update_item_info(serial_no_data)
# search batch no
batch_no_data = frappe.db.get_value(
"Batch",
search_value,
["name as batch_no", "item as item_code"],
as_dict=True,
)
if batch_no_data:
return _update_item_info(batch_no_data)
return {}
def _update_item_info(scan_result: Dict[str, Optional[str]]) -> Dict[str, Optional[str]]:
if item_code := scan_result.get("item_code"):
if item_info := frappe.get_cached_value(
"Item",
item_code,
["has_batch_no", "has_serial_no"],
as_dict=True,
):
scan_result.update(item_info)
return scan_result

View File

@ -8,7 +8,7 @@ no_cache = 1
def get_context(context):
homepage = frappe.get_doc("Homepage")
homepage = frappe.get_cached_doc("Homepage")
for item in homepage.products:
route = frappe.db.get_value("Website Item", {"item_code": item.item_code}, "route")
@ -20,10 +20,10 @@ def get_context(context):
context.homepage = homepage
if homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section:
homepage.hero_section_doc = frappe.get_doc("Homepage Section", homepage.hero_section)
homepage.hero_section_doc = frappe.get_cached_doc("Homepage Section", homepage.hero_section)
if homepage.slideshow:
doc = frappe.get_doc("Website Slideshow", homepage.slideshow)
doc = frappe.get_cached_doc("Website Slideshow", homepage.slideshow)
context.slideshow = homepage.slideshow
context.slideshow_header = doc.header
context.slides = doc.slideshow_items
@ -46,7 +46,7 @@ def get_context(context):
order_by="section_order asc",
)
context.homepage_sections = [
frappe.get_doc("Homepage Section", name) for name in homepage_sections
frappe.get_cached_doc("Homepage Section", name) for name in homepage_sections
]
context.metatags = context.metatags or frappe._dict({})