Compare commits

..

10 Commits

Author SHA1 Message Date
Frappe PR Bot
11b04acf8b chore(release): Bumped to Version 13.37.0
# [13.37.0](https://github.com/frappe/erpnext/compare/v13.36.5...v13.37.0) (2022-08-30)

### Bug Fixes

* Add docstatus filter for voucher_no in Repost Item Valuation ([2cf2885](2cf2885470))
* Cash and non trade discount calculation ([20e9599](20e9599fc1))
* do not clear promotion/transfer details if doc is amended ([#32000](https://github.com/frappe/erpnext/issues/32000)) ([074d484](074d484d3c))
* filter leave types and render leave application dashboard w/o from date ([#32001](https://github.com/frappe/erpnext/issues/32001)) ([7686c9e](7686c9e450))
* Loan Write-off for term loans ([e64e812](e64e812679))
* **minor:** don't print tax rate if its '0' ([#31838](https://github.com/frappe/erpnext/issues/31838)) ([a46dca5](a46dca57cb))
* permissions for Task Type ([#32016](https://github.com/frappe/erpnext/issues/32016)) ([1157bf8](1157bf887f))
* **pos:** edge case while closing pos (backport [#31748](https://github.com/frappe/erpnext/issues/31748)) ([#31893](https://github.com/frappe/erpnext/issues/31893)) ([261405c](261405cec1))
* Purposes not set ([edfaf99](edfaf99388))
* Route condition set for stock ledger (backport [#31935](https://github.com/frappe/erpnext/issues/31935)) ([#31946](https://github.com/frappe/erpnext/issues/31946)) ([34537c9](34537c9dc2))
* Set the condition to create a purchase receipt ([b4c992d](b4c992dd4d))
* Test cases ([7c85b48](7c85b487cd))

### Features

* In BOM,  Operation time can be fix (backport [#27063](https://github.com/frappe/erpnext/issues/27063)) ([#31923](https://github.com/frappe/erpnext/issues/31923)) ([c2b8d1b](c2b8d1bd9a))
2022-08-30 08:05:05 +00:00
Deepesh Garg
4c1156a816 Merge pull request #32023 from frappe/version-13-hotfix
chore: weekly version 13 release
2022-08-30 13:32:35 +05:30
Frappe PR Bot
f6248d0259 chore(release): Bumped to Version 13.36.5
## [13.36.5](https://github.com/frappe/erpnext/compare/v13.36.4...v13.36.5) (2022-08-23)

### Bug Fixes

* added employee name to call log ([476ded2](476ded2972))
* added field to show called group, user_id ([66578a5](66578a58cf))
* added tests ([aa8a063](aa8a063103))
* added type of call select field, additional status for agent rejecting call ([b65bce8](b65bce8f98))
* call status fix ([ffb1196](ffb1196516))
* call type doctype, fixes ([b94154f](b94154f00a))
* Handle exception where no employee is returned ([baab96d](baab96d02c))
* incorrect buying amount in Gross Profit rpt ([6405a93](6405a9378d))
* incorrect tax amt due to different exchange rate in PR and PI ([ba5ee1c](ba5ee1ca96))
* interview rescheduling not working ([a482840](a4828407d0))
* limit pos recent order page result ([9751f10](9751f1060e))
* linter, sider fixes ([b529627](b52962751c))
* **minor:** save the employee doc on promotion/transfer update ([36130c6](36130c6292))
* process loan interest accrual ([acbed43](acbed434c2))
* Replace walrus operator ([23a4412](23a441252b))
* sider fixes ([90ed14a](90ed14a055))
* TDS calculation for advance payment ([a452143](a452143782))
* term loan interest calculation ([8dea238](8dea238d12))
* Update received_by if "to" is changed ([9263d5f](9263d5ff4d))
* used get_employees_with_number, strip_number methods ([3f46b2a](3f46b2a0ce))
2022-08-23 13:37:34 +00:00
Deepesh Garg
4e6ef5d6fa Merge pull request #31939 from frappe/version-13-hotfix
chore: Weekly version 13 release
2022-08-23 19:05:53 +05:30
Frappe PR Bot
bafa3ce150 chore(release): Bumped to Version 13.36.4
## [13.36.4](https://github.com/frappe/erpnext/compare/v13.36.3...v13.36.4) (2022-08-18)

### Bug Fixes

* check item_code in all rows of po_items (backport [#31741](https://github.com/frappe/erpnext/issues/31741)) ([#31843](https://github.com/frappe/erpnext/issues/31843)) ([ba8dc89](ba8dc8925f))
* conflicts ([41b8563](41b8563b7a))
* contact search in request for quotation (backport [#31828](https://github.com/frappe/erpnext/issues/31828)) ([#31841](https://github.com/frappe/erpnext/issues/31841)) ([2a615af](2a615af00a))
* incorrect produced-qty in production-plan-item (backport [#31706](https://github.com/frappe/erpnext/issues/31706)) ([#31862](https://github.com/frappe/erpnext/issues/31862)) ([7ddb332](7ddb332f47))
* incorrect rate in BOM exploded items (backport [#31513](https://github.com/frappe/erpnext/issues/31513)) ([#31865](https://github.com/frappe/erpnext/issues/31865)) ([3274e76](3274e7681d))
* Make expense account editable in Purchase Receipt Item (backport [#31730](https://github.com/frappe/erpnext/issues/31730)) ([#31879](https://github.com/frappe/erpnext/issues/31879)) ([4775c42](4775c42593))
* not able to issue expired batches ([7ee75ff](7ee75ff762))
* set `billing_address` for purchases in `get_party_details` ([a7d66fa](a7d66fa352))
* set `company_address` for purchases in `party.js` ([d1de4b0](d1de4b027c))
* Transit filter for Default Target Warehouse in SE (backport [#31839](https://github.com/frappe/erpnext/issues/31839)) ([#31874](https://github.com/frappe/erpnext/issues/31874)) ([b0917aa](b0917aaf8a))
* use old style for `_dict.update` ([15654aa](15654aae8b))
2022-08-18 06:15:23 +00:00
Deepesh Garg
cff140db3d Merge pull request #31880 from frappe/version-13-hotfix
chore: weekly version-13 release
2022-08-18 11:43:42 +05:30
Frappe PR Bot
c15cff05b0 chore(release): Bumped to Version 13.36.3
## [13.36.3](https://github.com/frappe/erpnext/compare/v13.36.2...v13.36.3) (2022-08-09)

### Bug Fixes

* (india) HSN wise report ([08c69c7](08c69c7a76))
* add asset repair to accounting dimension list ([809d5ca](809d5caf80))
* consider precision while validating advance amount against sanctioned amount ([63cd434](63cd4349a6))
* **ecommerce:** remove query to non-existing field (backport [#31771](https://github.com/frappe/erpnext/issues/31771)) ([#31774](https://github.com/frappe/erpnext/issues/31774)) ([0e46b33](0e46b33ee3))
* f-string and where clause ([42b3959](42b395916d))
* getting error to show sales invoice group or print rep… (backport [#31756](https://github.com/frappe/erpnext/issues/31756)) ([#31768](https://github.com/frappe/erpnext/issues/31768)) ([473a43b](473a43b6b1))
* incorrect incoming rate set for inter transfer purchase receipt ([4e8b39a](4e8b39ab3f))
* incorrect tax calculation in case of reduced payment days ([80981d0](80981d025f))
* intercompany SO throws exception ([a17acfd](a17acfdaa2))
* minor changed link ([e9e53a7](e9e53a74c9))
* Payment Entry button is visible even when claim is fully paid ([d820757](d820757359))
* pending principal- amount ([16c94d2](16c94d292c))
* **pos:** validate product bundles while submitting pos invoice (backport [#31615](https://github.com/frappe/erpnext/issues/31615)) ([#31657](https://github.com/frappe/erpnext/issues/31657)) ([b145fe3](b145fe3b3e))
* specify allowed doctype in queries ([#31765](https://github.com/frappe/erpnext/issues/31765)) ([0dbfb15](0dbfb1589e))
* statistical component showing up in salary slip ([#31746](https://github.com/frappe/erpnext/issues/31746)) ([26aef4f](26aef4fb1c))
* sum stock_value and group by warehouse ([18d93f8](18d93f8398))
* taxable_value and gst_account_heads ([6c574fb](6c574fbf33))
* update To Date in Employee Work History ([#31811](https://github.com/frappe/erpnext/issues/31811)) ([0057c10](0057c10a7d))
2022-08-09 14:09:11 +00:00
Deepesh Garg
b80526f226 Merge pull request #31812 from frappe/version-13-hotfix
chore: weekly version 13 release
2022-08-09 19:37:13 +05:30
Frappe PR Bot
84e6cead56 chore(release): Bumped to Version 13.36.2
## [13.36.2](https://github.com/frappe/erpnext/compare/v13.36.1...v13.36.2) (2022-07-28)

### Bug Fixes

* (india) (e-invoice) margin & internal company transfer ([b97d30a](b97d30aad0))
* (india) add overseas in HSN wise report ([1d69ce1](1d69ce1932))
* Allow allocating advance amount against Expense Claim taxes ([42f3592](42f3592e95))
* assign duplicate_items_msg outside conditional ([#31639](https://github.com/frappe/erpnext/issues/31639)) ([8e23c6a](8e23c6ad69))
* correct Brazilian portuguese translations (backport [#31498](https://github.com/frappe/erpnext/issues/31498)) ([#31660](https://github.com/frappe/erpnext/issues/31660)) ([794fd08](794fd0819f))
* discount and test added ([a843e78](a843e784e6))
* display customer name on picking list ([dbf245c](dbf245c687))
* do not update component amount for timesheet components ([#31696](https://github.com/frappe/erpnext/issues/31696)) ([bc7cfe6](bc7cfe6919))
* enable tax withholding checkbox in PI with supplier_tds ([bc74942](bc7494278d))
* ensure defaults removed in bad frappe patch get set again (backport [#31659](https://github.com/frappe/erpnext/issues/31659)) ([#31661](https://github.com/frappe/erpnext/issues/31661)) ([763787b](763787b0a5))
* hero image not loading in portal homepage ([#31699](https://github.com/frappe/erpnext/issues/31699)) ([8a6432e](8a6432ec3f))
* **india:** e-way bill json for unregistered gst category ([01d6df4](01d6df45d0))
* make customer_name field read only. ([2381b81](2381b81aac))
* manually generated salary slips overwritten by structure amount ([#31711](https://github.com/frappe/erpnext/issues/31711)) ([32c1bb6](32c1bb61de))
* Map `Item` image to `Website Item` website_image only if published via UI (v13) ([9b1544a](9b1544aa14))
* payment entry to student ([#31708](https://github.com/frappe/erpnext/issues/31708)) ([4f02375](4f023757de))
* Reload loan Table in Salary Slip when change Employee ([#31525](https://github.com/frappe/erpnext/issues/31525)) ([a95c011](a95c011a93))
* rounding errors while closing pos (backport [#31654](https://github.com/frappe/erpnext/issues/31654)) ([#31658](https://github.com/frappe/erpnext/issues/31658)) ([529a47b](529a47bc88))
* Route condition set with proper filter ([#31556](https://github.com/frappe/erpnext/issues/31556)) ([5cdc267](5cdc267aee))
* The Fee details are not fetched in Program Enrollment ([#31153](https://github.com/frappe/erpnext/issues/31153)) ([0602848](0602848caa))
* update fr translations ([#31687](https://github.com/frappe/erpnext/issues/31687)) ([89348c1](89348c1bb4))
* update fr translations (backport [#31526](https://github.com/frappe/erpnext/issues/31526)) ([#31666](https://github.com/frappe/erpnext/issues/31666)) ([95e1021](95e1021caf))
* update SO's percentage billed on credit note ([2f2d3de](2f2d3de306))
* use current pos profile on sales return ([c442b4a](c442b4aef1))
2022-07-28 12:13:57 +00:00
Deepesh Garg
590e48fa1d Merge pull request #31725 from frappe/version-13-hotfix
chore: weekly version-13 release
2022-07-28 17:42:15 +05:30
47 changed files with 954 additions and 1455 deletions

View File

@@ -65,8 +65,6 @@ GNU/General Public License (see [license.txt](license.txt))
The ERPNext code is licensed as GNU General Public License (v3) and the Documentation is licensed as Creative Commons (CC-BY-SA-3.0) and the copyright is owned by Frappe Technologies Pvt Ltd (Frappe) and Contributors.
By contributing to ERPNext, you agree that your contributions will be licensed under its GNU General Public License (v3).
---
## Contributing

View File

@@ -4,7 +4,7 @@ import frappe
from erpnext.hooks import regional_overrides
__version__ = "13.36.1"
__version__ = "13.37.0"
def get_default_company(user=None):

View File

@@ -2,7 +2,7 @@
// For license information, please see license.txt
frappe.ui.form.on("Journal Entry Template", {
refresh: function(frm) {
setup: function(frm) {
frappe.model.set_default_values(frm.doc);
frm.set_query("account" ,"accounts", function(){

View File

@@ -43,7 +43,6 @@
"currency",
"write_off_account",
"write_off_cost_center",
"write_off_limit",
"account_for_change_amount",
"disable_rounded_total",
"column_break_23",
@@ -361,14 +360,6 @@
"fieldtype": "Check",
"label": "Validate Stock on Save"
},
{
"default": "1",
"description": "Auto write off precision loss while consolidation",
"fieldname": "write_off_limit",
"fieldtype": "Currency",
"label": "Write Off Limit",
"reqd": 1
},
{
"default": "0",
"description": "If enabled, the consolidated invoices will have rounded total disabled",
@@ -402,7 +393,7 @@
"link_fieldname": "pos_profile"
}
],
"modified": "2022-08-10 12:57:06.241439",
"modified": "2022-07-21 11:16:46.911173",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Profile",

View File

@@ -34,4 +34,4 @@ class ProcessDeferredAccounting(Document):
filters={"against_voucher_type": self.doctype, "against_voucher": self.name},
)
make_gl_entries(gl_map=gl_entries, cancel=1)
make_gl_entries(gl_entries=gl_entries, cancel=1)

View File

@@ -57,16 +57,3 @@ class TestProcessDeferredAccounting(unittest.TestCase):
]
check_gl_entries(self, si.name, expected_gle, "2019-01-10")
def test_pda_submission_and_cancellation(self):
pda = frappe.get_doc(
dict(
doctype="Process Deferred Accounting",
posting_date="2019-01-01",
start_date="2019-01-01",
end_date="2019-01-31",
type="Income",
)
)
pda.submit()
pda.cancel()

View File

@@ -535,11 +535,7 @@ def get_accounts(root_type, companies):
):
if account.account_name not in added_accounts:
accounts.append(account)
if account.account_number:
account_key = account.account_number + "-" + account.account_name
else:
account_key = account.account_name
added_accounts.append(account_key)
added_accounts.append(account.account_name)
return accounts

View File

@@ -818,31 +818,6 @@ def get_held_invoices(party_type, party):
return held_invoices
def remove_return_pos_invoices(party_type, party, invoice_list):
if invoice_list:
if party_type == "Customer":
sinv = frappe.qb.DocType("Sales Invoice")
return_pos = (
frappe.qb.from_(sinv)
.select(sinv.name)
.where((sinv.is_pos == 1) & (sinv.docstatus == 1) & (sinv.is_return == 1))
.run()
)
if return_pos:
return_pos = [x[0] for x in return_pos]
else:
return invoice_list
# remove pos return invoices from invoice_list
for idx, inv in enumerate(invoice_list, 0):
if inv.voucher_no in return_pos:
del invoice_list[idx]
return invoice_list
def get_outstanding_invoices(party_type, party, account, condition=None, filters=None):
outstanding_invoices = []
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2
@@ -893,8 +868,6 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
as_dict=True,
)
invoice_list = remove_return_pos_invoices(party_type, party, invoice_list)
payment_entries = frappe.db.sql(
"""
select against_voucher_type, against_voucher,

View File

@@ -303,11 +303,7 @@ class BuyingController(StockController, Subcontracting):
rate = flt(outgoing_rate * (d.conversion_factor or 1), d.precision("rate"))
else:
field = "incoming_rate" if self.get("is_internal_supplier") else "rate"
rate = flt(
frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), field)
* (d.conversion_factor or 1),
d.precision("rate"),
)
rate = frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), field)
if self.is_internal_transfer():
if rate != d.rate:

View File

@@ -770,18 +770,6 @@ class calculate_taxes_and_totals(object):
self.doc.precision("outstanding_amount"),
)
if (
self.doc.doctype == "Sales Invoice"
and self.doc.get("is_pos")
and self.doc.get("pos_profile")
and self.doc.get("is_consolidated")
):
write_off_limit = flt(
frappe.db.get_value("POS Profile", self.doc.pos_profile, "write_off_limit")
)
if write_off_limit and abs(self.doc.outstanding_amount) <= write_off_limit:
self.doc.write_off_outstanding_amount_automatically = 1
if (
self.doc.doctype == "Sales Invoice"
and self.doc.get("is_pos")

View File

@@ -19,7 +19,7 @@ from erpnext.hr.doctype.attendance.attendance import (
mark_attendance,
)
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday
test_records = frappe.get_test_records("Attendance")

View File

@@ -33,7 +33,6 @@ from erpnext.hr.doctype.leave_policy_assignment.leave_policy_assignment import (
create_assignment_for_multiple_employees,
)
from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
make_holiday_list,
make_leave_application,
@@ -1106,6 +1105,23 @@ def allocate_leaves(employee, leave_period, leave_type, new_leaves_allocated, el
allocate_leave.submit()
def get_first_sunday(holiday_list, for_date=None):
date = for_date or getdate()
month_start_date = get_first_day(date)
month_end_date = get_last_day(date)
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = %s
and holiday_date between %s and %s
order by holiday_date
""",
(holiday_list, month_start_date, month_end_date),
)[0][0]
return first_sunday
def make_policy_assignment(employee, leave_type, leave_period):
frappe.delete_doc_if_exists("Leave Type", leave_type, force=1)
frappe.get_doc(

View File

@@ -9,11 +9,13 @@ from frappe.utils import add_days, add_months, flt, get_year_ending, get_year_st
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list
from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
from erpnext.hr.doctype.leave_application.test_leave_application import (
get_first_sunday,
make_allocation_record,
)
from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import process_expired_allocation
from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type
from erpnext.hr.report.employee_leave_balance.employee_leave_balance import execute
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
make_holiday_list,
make_leave_application,

View File

@@ -22,9 +22,9 @@ def execute(filters=None):
def get_columns(leave_types):
columns = [
_("Employee") + ":Link/Employee:150",
_("Employee") + ":Link.Employee:150",
_("Employee Name") + "::200",
_("Department") + ":Link/Department:150",
_("Department") + "::150",
]
for leave_type in leave_types:

View File

@@ -9,10 +9,12 @@ from frappe.utils import add_days, flt, get_year_ending, get_year_start, getdate
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list
from erpnext.hr.doctype.leave_application.test_leave_application import make_allocation_record
from erpnext.hr.doctype.leave_application.test_leave_application import (
get_first_sunday,
make_allocation_record,
)
from erpnext.hr.doctype.leave_ledger_entry.leave_ledger_entry import process_expired_allocation
from erpnext.hr.report.employee_leave_balance_summary.employee_leave_balance_summary import execute
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.payroll.doctype.salary_slip.test_salary_slip import (
make_holiday_list,
make_leave_application,

View File

@@ -1,19 +0,0 @@
import frappe
from frappe.utils import get_first_day, get_last_day, getdate
def get_first_sunday(holiday_list="Salary Slip Test Holiday List", for_date=None):
date = for_date or getdate()
month_start_date = get_first_day(date)
month_end_date = get_last_day(date)
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = %s
and holiday_date between %s and %s
order by holiday_date
""",
(holiday_list, month_start_date, month_end_date),
)[0][0]
return first_sunday

View File

@@ -17,7 +17,6 @@
"posting_date",
"status",
"repay_from_salary",
"manually_update_paid_amount_in_salary_slip",
"section_break_8",
"loan_type",
"loan_amount",
@@ -52,10 +51,10 @@
"refund_amount",
"debit_adjustment_amount",
"credit_adjustment_amount",
"is_npa",
"column_break_19",
"total_interest_payable",
"total_amount_paid",
"is_npa",
"amended_from"
],
"fields": [
@@ -411,23 +410,16 @@
"fieldname": "is_npa",
"fieldtype": "Check",
"label": "Is NPA"
},
{
"allow_on_submit": 1,
"default": "0",
"depends_on": "repay_from_salary",
"fieldname": "manually_update_paid_amount_in_salary_slip",
"fieldtype": "Check",
"label": "Manually Update Paid Amount in Salary Slip"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-09-13 02:05:25.017190",
"modified": "2022-06-30 12:04:13.728880",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
@@ -453,5 +445,6 @@
"search_fields": "posting_date",
"sort_field": "creation",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}

View File

@@ -236,7 +236,7 @@ def get_term_loans(date, term_loan=None, loan_type=None):
AND l.is_term_loan =1
AND rs.payment_date <= %s
AND rs.is_accrued=0 {0}
AND rs.principal_amount > 0
AND rs.interest_amount > 0
AND l.status = 'Disbursed'
ORDER BY rs.payment_date""".format(
condition

View File

@@ -520,8 +520,6 @@ def get_accrued_interest_entries(against_loan, posting_date=None):
if not posting_date:
posting_date = getdate()
precision = cint(frappe.db.get_default("currency_precision")) or 2
unpaid_accrued_entries = frappe.db.sql(
"""
SELECT name, posting_date, interest_amount - paid_interest_amount as interest_amount,
@@ -542,13 +540,6 @@ def get_accrued_interest_entries(against_loan, posting_date=None):
as_dict=1,
)
# Skip entries with zero interest amount & payable principal amount
unpaid_accrued_entries = [
d
for d in unpaid_accrued_entries
if flt(d.interest_amount, precision) > 0 or flt(d.payable_principal_amount, precision) > 0
]
return unpaid_accrued_entries

View File

@@ -8,7 +8,6 @@ import json
import frappe
from frappe import _, msgprint
from frappe.model.document import Document
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils import (
add_days,
ceil,
@@ -21,7 +20,6 @@ from frappe.utils import (
nowdate,
)
from frappe.utils.csvutils import build_csv_response
from pypika.terms import ExistsCriterion
from six import iteritems
from erpnext.manufacturing.doctype.bom.bom import get_children, validate_bom_no
@@ -102,46 +100,39 @@ class ProductionPlan(Document):
@frappe.whitelist()
def get_pending_material_requests(self):
"""Pull Material Requests that are pending based on criteria selected"""
bom = frappe.qb.DocType("BOM")
mr = frappe.qb.DocType("Material Request")
mr_item = frappe.qb.DocType("Material Request Item")
pending_mr_query = (
frappe.qb.from_(mr)
.from_(mr_item)
.select(mr.name, mr.transaction_date)
.distinct()
.where(
(mr_item.parent == mr.name)
& (mr.material_request_type == "Manufacture")
& (mr.docstatus == 1)
& (mr.status != "Stopped")
& (mr.company == self.company)
& (mr_item.qty > IfNull(mr_item.ordered_qty, 0))
& (
ExistsCriterion(
frappe.qb.from_(bom)
.select(bom.name)
.where((bom.item == mr_item.item_code) & (bom.is_active == 1))
)
)
)
)
mr_filter = item_filter = ""
if self.from_date:
pending_mr_query = pending_mr_query.where(mr.transaction_date >= self.from_date)
mr_filter += " and mr.transaction_date >= %(from_date)s"
if self.to_date:
pending_mr_query = pending_mr_query.where(mr.transaction_date <= self.to_date)
mr_filter += " and mr.transaction_date <= %(to_date)s"
if self.warehouse:
pending_mr_query = pending_mr_query.where(mr_item.warehouse == self.warehouse)
mr_filter += " and mr_item.warehouse = %(warehouse)s"
if self.item_code:
pending_mr_query = pending_mr_query.where(mr_item.item_code == self.item_code)
item_filter += " and mr_item.item_code = %(item)s"
pending_mr = pending_mr_query.run(as_dict=True)
pending_mr = frappe.db.sql(
"""
select distinct mr.name, mr.transaction_date
from `tabMaterial Request` mr, `tabMaterial Request Item` mr_item
where mr_item.parent = mr.name
and mr.material_request_type = "Manufacture"
and mr.docstatus = 1 and mr.status != "Stopped" and mr.company = %(company)s
and mr_item.qty > ifnull(mr_item.ordered_qty,0) {0} {1}
and (exists (select name from `tabBOM` bom where bom.item=mr_item.item_code
and bom.is_active = 1))
""".format(
mr_filter, item_filter
),
{
"from_date": self.from_date,
"to_date": self.to_date,
"warehouse": self.warehouse,
"item": self.item_code,
"company": self.company,
},
as_dict=1,
)
self.add_mr_in_table(pending_mr)
@@ -169,17 +160,16 @@ class ProductionPlan(Document):
so_mr_list = [d.get(field) for d in self.get(table) if d.get(field)]
return so_mr_list
def get_bom_item_condition(self):
def get_bom_item(self):
"""Check if Item or if its Template has a BOM."""
bom_item_condition = None
bom_item = None
has_bom = frappe.db.exists({"doctype": "BOM", "item": self.item_code, "docstatus": 1})
if not has_bom:
bom = frappe.qb.DocType("BOM")
template_item = frappe.db.get_value("Item", self.item_code, ["variant_of"])
bom_item_condition = bom.item == template_item or None
return bom_item_condition
bom_item = (
"bom.item = {0}".format(frappe.db.escape(template_item)) if template_item else bom_item
)
return bom_item
def get_so_items(self):
# Check for empty table or empty rows
@@ -188,75 +178,46 @@ class ProductionPlan(Document):
so_list = self.get_so_mr_list("sales_order", "sales_orders")
bom = frappe.qb.DocType("BOM")
so_item = frappe.qb.DocType("Sales Order Item")
items_subquery = frappe.qb.from_(bom).select(bom.name).where(bom.is_active == 1)
items_query = (
frappe.qb.from_(so_item)
.select(
so_item.parent,
so_item.item_code,
so_item.warehouse,
(
(so_item.qty - so_item.work_order_qty - so_item.delivered_qty) * so_item.conversion_factor
).as_("pending_qty"),
so_item.description,
so_item.name,
)
.distinct()
.where(
(so_item.parent.isin(so_list))
& (so_item.docstatus == 1)
& (so_item.qty > so_item.work_order_qty)
)
)
item_condition = ""
bom_item = "bom.item = so_item.item_code"
if self.item_code and frappe.db.exists("Item", self.item_code):
items_query = items_query.where(so_item.item_code == self.item_code)
items_subquery = items_subquery.where(
self.get_bom_item_condition() or bom.item == so_item.item_code
)
bom_item = self.get_bom_item() or bom_item
item_condition = " and so_item.item_code = {0}".format(frappe.db.escape(self.item_code))
items_query = items_query.where(ExistsCriterion(items_subquery))
items = items_query.run(as_dict=True)
pi = frappe.qb.DocType("Packed Item")
packed_items_query = (
frappe.qb.from_(so_item)
.from_(pi)
.select(
pi.parent,
pi.item_code,
pi.warehouse.as_("warehouse"),
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty).as_("pending_qty"),
pi.parent_item,
pi.description,
so_item.name,
)
.distinct()
.where(
(so_item.parent == pi.parent)
& (so_item.docstatus == 1)
& (pi.parent_item == so_item.item_code)
& (so_item.parent.isin(so_list))
& (so_item.qty > so_item.work_order_qty)
& (
ExistsCriterion(
frappe.qb.from_(bom)
.select(bom.name)
.where((bom.item == pi.item_code) & (bom.is_active == 1))
)
)
)
items = frappe.db.sql(
"""
select
distinct parent, item_code, warehouse,
(qty - work_order_qty) * conversion_factor as pending_qty,
description, name
from
`tabSales Order Item` so_item
where
parent in (%s) and docstatus = 1 and qty > work_order_qty
and exists (select name from `tabBOM` bom where %s
and bom.is_active = 1) %s"""
% (", ".join(["%s"] * len(so_list)), bom_item, item_condition),
tuple(so_list),
as_dict=1,
)
if self.item_code:
packed_items_query = packed_items_query.where(so_item.item_code == self.item_code)
item_condition = " and so_item.item_code = {0}".format(frappe.db.escape(self.item_code))
packed_items = packed_items_query.run(as_dict=True)
packed_items = frappe.db.sql(
"""select distinct pi.parent, pi.item_code, pi.warehouse as warehouse,
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty)
as pending_qty, pi.parent_item, pi.description, so_item.name
from `tabSales Order Item` so_item, `tabPacked Item` pi
where so_item.parent = pi.parent and so_item.docstatus = 1
and pi.parent_item = so_item.item_code
and so_item.parent in (%s) and so_item.qty > so_item.work_order_qty
and exists (select name from `tabBOM` bom where bom.item=pi.item_code
and bom.is_active = 1) %s"""
% (", ".join(["%s"] * len(so_list)), item_condition),
tuple(so_list),
as_dict=1,
)
self.add_items(items + packed_items)
self.calculate_total_planned_qty()
@@ -272,38 +233,21 @@ class ProductionPlan(Document):
mr_list = self.get_so_mr_list("material_request", "material_requests")
bom = frappe.qb.DocType("BOM")
mr_item = frappe.qb.DocType("Material Request Item")
items_query = (
frappe.qb.from_(mr_item)
.select(
mr_item.parent,
mr_item.name,
mr_item.item_code,
mr_item.warehouse,
mr_item.description,
((mr_item.qty - mr_item.ordered_qty) * mr_item.conversion_factor).as_("pending_qty"),
)
.distinct()
.where(
(mr_item.parent.isin(mr_list))
& (mr_item.docstatus == 1)
& (mr_item.qty > mr_item.ordered_qty)
& (
ExistsCriterion(
frappe.qb.from_(bom)
.select(bom.name)
.where((bom.item == mr_item.item_code) & (bom.is_active == 1))
)
)
)
)
item_condition = ""
if self.item_code:
items_query = items_query.where(mr_item.item_code == self.item_code)
item_condition = " and mr_item.item_code ={0}".format(frappe.db.escape(self.item_code))
items = items_query.run(as_dict=True)
items = frappe.db.sql(
"""select distinct parent, name, item_code, warehouse, description,
(qty - ordered_qty) * conversion_factor as pending_qty
from `tabMaterial Request Item` mr_item
where parent in (%s) and docstatus = 1 and qty > ordered_qty
and exists (select name from `tabBOM` bom where bom.item=mr_item.item_code
and bom.is_active = 1) %s"""
% (", ".join(["%s"] * len(mr_list)), item_condition),
tuple(mr_list),
as_dict=1,
)
self.add_items(items)
self.calculate_total_planned_qty()
@@ -810,45 +754,29 @@ def download_raw_materials(doc, warehouses=None):
def get_exploded_items(item_details, company, bom_no, include_non_stock_items, planned_qty=1):
bei = frappe.qb.DocType("BOM Explosion Item")
bom = frappe.qb.DocType("BOM")
item = frappe.qb.DocType("Item")
item_default = frappe.qb.DocType("Item Default")
item_uom = frappe.qb.DocType("UOM Conversion Detail")
data = (
frappe.qb.from_(bei)
.join(bom)
.on(bom.name == bei.parent)
.join(item)
.on(item.name == bei.item_code)
.left_join(item_default)
.on((item_default.parent == item.name) & (item_default.company == company))
.left_join(item_uom)
.on((item.name == item_uom.parent) & (item_uom.uom == item.purchase_uom))
.select(
(IfNull(Sum(bei.stock_qty / IfNull(bom.quantity, 1)), 0) * planned_qty).as_("qty"),
item.item_name,
bei.description,
bei.stock_uom,
item.min_order_qty,
bei.source_warehouse,
item.default_material_request_type,
item.min_order_qty,
item_default.default_warehouse,
item.purchase_uom,
item_uom.conversion_factor,
item.safety_stock,
)
.where(
(bei.docstatus < 2)
& (bom.name == bom_no)
& (item.is_stock_item.isin([0, 1]) if include_non_stock_items else item.is_stock_item == 1)
)
.groupby(bei.item_code, bei.stock_uom)
).run(as_dict=True)
for d in data:
for d in frappe.db.sql(
"""select bei.item_code, item.default_bom as bom,
ifnull(sum(bei.stock_qty/ifnull(bom.quantity, 1)), 0)*%s as qty, item.item_name,
bei.description, bei.stock_uom, item.min_order_qty, bei.source_warehouse,
item.default_material_request_type, item.min_order_qty, item_default.default_warehouse,
item.purchase_uom, item_uom.conversion_factor, item.safety_stock
from
`tabBOM Explosion Item` bei
JOIN `tabBOM` bom ON bom.name = bei.parent
JOIN `tabItem` item ON item.name = bei.item_code
LEFT JOIN `tabItem Default` item_default
ON item_default.parent = item.name and item_default.company=%s
LEFT JOIN `tabUOM Conversion Detail` item_uom
ON item.name = item_uom.parent and item_uom.uom = item.purchase_uom
where
bei.docstatus < 2
and bom.name=%s and item.is_stock_item in (1, {0})
group by bei.item_code, bei.stock_uom""".format(
0 if include_non_stock_items else 1
),
(planned_qty, company, bom_no),
as_dict=1,
):
if not d.conversion_factor and d.purchase_uom:
d.conversion_factor = get_uom_conversion_factor(d.item_code, d.purchase_uom)
item_details.setdefault(d.get("item_code"), d)
@@ -873,47 +801,33 @@ def get_subitems(
parent_qty,
planned_qty=1,
):
bom_item = frappe.qb.DocType("BOM Item")
bom = frappe.qb.DocType("BOM")
item = frappe.qb.DocType("Item")
item_default = frappe.qb.DocType("Item Default")
item_uom = frappe.qb.DocType("UOM Conversion Detail")
items = (
frappe.qb.from_(bom_item)
.join(bom)
.on(bom.name == bom_item.parent)
.join(item)
.on(bom_item.item_code == item.name)
.left_join(item_default)
.on((item.name == item_default.parent) & (item_default.company == company))
.left_join(item_uom)
.on((item.name == item_uom.parent) & (item_uom.uom == item.purchase_uom))
.select(
bom_item.item_code,
item.default_material_request_type,
item.item_name,
IfNull(parent_qty * Sum(bom_item.stock_qty / IfNull(bom.quantity, 1)) * planned_qty, 0).as_(
"qty"
),
item.is_sub_contracted_item.as_("is_sub_contracted"),
bom_item.source_warehouse,
item.default_bom.as_("default_bom"),
bom_item.description.as_("description"),
bom_item.stock_uom.as_("stock_uom"),
item.min_order_qty.as_("min_order_qty"),
item.safety_stock.as_("safety_stock"),
item_default.default_warehouse,
item.purchase_uom,
item_uom.conversion_factor,
)
.where(
(bom.name == bom_no)
& (bom_item.docstatus < 2)
& (item.is_stock_item.isin([0, 1]) if include_non_stock_items else item.is_stock_item == 1)
)
.groupby(bom_item.item_code)
).run(as_dict=True)
items = frappe.db.sql(
"""
SELECT
bom_item.item_code, default_material_request_type, item.item_name,
ifnull(%(parent_qty)s * sum(bom_item.stock_qty/ifnull(bom.quantity, 1)) * %(planned_qty)s, 0) as qty,
item.is_sub_contracted_item as is_sub_contracted, bom_item.source_warehouse,
item.default_bom as default_bom, bom_item.description as description,
bom_item.stock_uom as stock_uom, item.min_order_qty as min_order_qty, item.safety_stock as safety_stock,
item_default.default_warehouse, item.purchase_uom, item_uom.conversion_factor
FROM
`tabBOM Item` bom_item
JOIN `tabBOM` bom ON bom.name = bom_item.parent
JOIN tabItem item ON bom_item.item_code = item.name
LEFT JOIN `tabItem Default` item_default
ON item.name = item_default.parent and item_default.company = %(company)s
LEFT JOIN `tabUOM Conversion Detail` item_uom
ON item.name = item_uom.parent and item_uom.uom = item.purchase_uom
where
bom.name = %(bom)s
and bom_item.docstatus < 2
and item.is_stock_item in (1, {0})
group by bom_item.item_code""".format(
0 if include_non_stock_items else 1
),
{"bom": bom_no, "parent_qty": parent_qty, "planned_qty": planned_qty, "company": company},
as_dict=1,
)
for d in items:
if not data.get("include_exploded_items") or not d.default_bom:
@@ -1001,69 +915,48 @@ def get_material_request_items(
def get_sales_orders(self):
bom = frappe.qb.DocType("BOM")
pi = frappe.qb.DocType("Packed Item")
so = frappe.qb.DocType("Sales Order")
so_item = frappe.qb.DocType("Sales Order Item")
open_so_subquery1 = frappe.qb.from_(bom).select(bom.name).where(bom.is_active == 1)
open_so_subquery2 = (
frappe.qb.from_(pi)
.select(pi.name)
.where(
(pi.parent == so.name)
& (pi.parent_item == so_item.item_code)
& (
ExistsCriterion(
frappe.qb.from_(bom).select(bom.name).where((bom.item == pi.item_code) & (bom.is_active == 1))
)
)
)
)
open_so_query = (
frappe.qb.from_(so)
.from_(so_item)
.select(so.name, so.transaction_date, so.customer, so.base_grand_total)
.distinct()
.where(
(so_item.parent == so.name)
& (so.docstatus == 1)
& (so.status.notin(["Stopped", "Closed"]))
& (so.company == self.company)
& (so_item.qty > so_item.work_order_qty)
)
)
so_filter = item_filter = ""
bom_item = "bom.item = so_item.item_code"
date_field_mapper = {
"from_date": self.from_date >= so.transaction_date,
"to_date": self.to_date <= so.transaction_date,
"from_delivery_date": self.from_delivery_date >= so_item.delivery_date,
"to_delivery_date": self.to_delivery_date <= so_item.delivery_date,
"from_date": (">=", "so.transaction_date"),
"to_date": ("<=", "so.transaction_date"),
"from_delivery_date": (">=", "so_item.delivery_date"),
"to_delivery_date": ("<=", "so_item.delivery_date"),
}
for field, value in date_field_mapper.items():
if self.get(field):
open_so_query = open_so_query.where(value)
so_filter += f" and {value[1]} {value[0]} %({field})s"
for field in ("customer", "project", "sales_order_status"):
for field in ["customer", "project", "sales_order_status"]:
if self.get(field):
so_field = "status" if field == "sales_order_status" else field
open_so_query = open_so_query.where(so[so_field] == self.get(field))
so_filter += f" and so.{so_field} = %({field})s"
if self.item_code and frappe.db.exists("Item", self.item_code):
open_so_query = open_so_query.where(so_item.item_code == self.item_code)
open_so_subquery1 = open_so_subquery1.where(
self.get_bom_item_condition() or bom.item == so_item.item_code
)
bom_item = self.get_bom_item() or bom_item
item_filter += " and so_item.item_code = %(item_code)s"
open_so_query = open_so_query.where(
(ExistsCriterion(open_so_subquery1) | ExistsCriterion(open_so_subquery2))
open_so = frappe.db.sql(
f"""
select distinct so.name, so.transaction_date, so.customer, so.base_grand_total
from `tabSales Order` so, `tabSales Order Item` so_item
where so_item.parent = so.name
and so.docstatus = 1 and so.status not in ("Stopped", "Closed")
and so.company = %(company)s
and so_item.qty > so_item.work_order_qty {so_filter} {item_filter}
and (exists (select name from `tabBOM` bom where {bom_item}
and bom.is_active = 1)
or exists (select name from `tabPacked Item` pi
where pi.parent = so.name and pi.parent_item = so_item.item_code
and exists (select name from `tabBOM` bom where bom.item=pi.item_code
and bom.is_active = 1)))
""",
self.as_dict(),
as_dict=1,
)
open_so = open_so_query.run(as_dict=True)
return open_so
@@ -1072,33 +965,36 @@ def get_bin_details(row, company, for_warehouse=None, all_warehouse=False):
if isinstance(row, str):
row = frappe._dict(json.loads(row))
bin = frappe.qb.DocType("Bin")
wh = frappe.qb.DocType("Warehouse")
subquery = frappe.qb.from_(wh).select(wh.name).where(wh.company == company)
company = frappe.db.escape(company)
conditions, warehouse = "", ""
conditions = " and warehouse in (select name from `tabWarehouse` where company = {0})".format(
company
)
if not all_warehouse:
warehouse = for_warehouse or row.get("source_warehouse") or row.get("default_warehouse")
if warehouse:
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
subquery = subquery.where((wh.lft >= lft) & (wh.rgt <= rgt) & (wh.name == bin.warehouse))
query = (
frappe.qb.from_(bin)
.select(
bin.warehouse,
IfNull(Sum(bin.projected_qty), 0).as_("projected_qty"),
IfNull(Sum(bin.actual_qty), 0).as_("actual_qty"),
IfNull(Sum(bin.ordered_qty), 0).as_("ordered_qty"),
IfNull(Sum(bin.reserved_qty_for_production), 0).as_("reserved_qty_for_production"),
IfNull(Sum(bin.planned_qty), 0).as_("planned_qty"),
conditions = """ and warehouse in (select name from `tabWarehouse`
where lft >= {0} and rgt <= {1} and name=`tabBin`.warehouse and company = {2})
""".format(
lft, rgt, company
)
.where((bin.item_code == row["item_code"]) & (bin.warehouse.isin(subquery)))
.groupby(bin.item_code, bin.warehouse)
)
return query.run(as_dict=True)
return frappe.db.sql(
""" select ifnull(sum(projected_qty),0) as projected_qty,
ifnull(sum(actual_qty),0) as actual_qty, ifnull(sum(ordered_qty),0) as ordered_qty,
ifnull(sum(reserved_qty_for_production),0) as reserved_qty_for_production, warehouse,
ifnull(sum(planned_qty),0) as planned_qty
from `tabBin` where item_code = %(item_code)s {conditions}
group by item_code, warehouse
""".format(
conditions=conditions
),
{"item_code": row["item_code"]},
as_dict=1,
)
@frappe.whitelist()

View File

@@ -12,7 +12,6 @@ from erpnext.manufacturing.doctype.production_plan.production_plan import (
)
from erpnext.manufacturing.doctype.work_order.work_order import OverProductionError
from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry as make_se_from_wo
from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.stock.doctype.item.test_item import create_item, make_item
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
@@ -539,21 +538,15 @@ class TestProductionPlan(FrappeTestCase):
"""
from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record
make_stock_entry(item_code="_Test Item", target="Work In Progress - _TC", qty=2, basic_rate=100)
make_stock_entry(
item_code="_Test Item Home Desktop 100", target="Work In Progress - _TC", qty=4, basic_rate=100
item_code="Raw Material Item 1", target="Work In Progress - _TC", qty=2, basic_rate=100
)
make_stock_entry(
item_code="Raw Material Item 2", target="Work In Progress - _TC", qty=2, basic_rate=100
)
item = "_Test FG Item"
make_stock_entry(item_code=item, target="_Test Warehouse - _TC", qty=1)
so = make_sales_order(item_code=item, qty=2)
dn = make_delivery_note(so.name)
dn.items[0].qty = 1
dn.save()
dn.submit()
item = "Test Production Item 1"
so = make_sales_order(item_code=item, qty=1)
pln = create_production_plan(
company=so.company, get_items_from="Sales Order", sales_order=so, skip_getting_mr_items=True

View File

@@ -11,24 +11,17 @@ frappe.query_reports["BOM Stock Calculated"] = {
"options": "BOM",
"reqd": 1
},
{
"fieldname": "warehouse",
"label": __("Warehouse"),
"fieldtype": "Link",
"options": "Warehouse",
},
{
"fieldname": "qty_to_make",
"label": __("Quantity to Make"),
"fieldtype": "Float",
"default": "1.0",
"reqd": 1
},
{
{
"fieldname": "qty_to_make",
"label": __("Quantity to Make"),
"fieldtype": "Int",
"default": "1"
},
{
"fieldname": "show_exploded_view",
"label": __("Show exploded view"),
"fieldtype": "Check",
"default": false,
"fieldtype": "Check"
}
]
}

View File

@@ -4,31 +4,29 @@
import frappe
from frappe import _
from frappe.query_builder.functions import IfNull, Sum
from frappe.utils.data import comma_and
from pypika.terms import ExistsCriterion
def execute(filters=None):
# if not filters: filters = {}
columns = get_columns()
data = []
summ_data = []
bom_data = get_bom_data(filters)
data = get_bom_stock(filters)
qty_to_make = filters.get("qty_to_make")
manufacture_details = get_manufacturer_records()
for row in data:
reqd_qty = qty_to_make * row.actual_qty
last_pur_price = frappe.db.get_value("Item", row.item_code, "last_purchase_rate")
for row in bom_data:
required_qty = qty_to_make * row.qty_per_unit
last_purchase_rate = frappe.db.get_value("Item", row.item_code, "last_purchase_rate")
data.append(get_report_data(last_purchase_rate, required_qty, row, manufacture_details))
return columns, data
summ_data.append(get_report_data(last_pur_price, reqd_qty, row, manufacture_details))
return columns, summ_data
def get_report_data(last_purchase_rate, required_qty, row, manufacture_details):
qty_per_unit = row.qty_per_unit if row.qty_per_unit > 0 else 0
difference_qty = row.actual_qty - required_qty
def get_report_data(last_pur_price, reqd_qty, row, manufacture_details):
to_build = row.to_build if row.to_build > 0 else 0
diff_qty = to_build - reqd_qty
return [
row.item_code,
row.description,
@@ -36,126 +34,85 @@ def get_report_data(last_purchase_rate, required_qty, row, manufacture_details):
comma_and(
manufacture_details.get(row.item_code, {}).get("manufacturer_part", []), add_quotes=False
),
qty_per_unit,
row.actual_qty,
required_qty,
difference_qty,
last_purchase_rate,
str(to_build),
reqd_qty,
diff_qty,
last_pur_price,
]
def get_columns():
return [
{
"fieldname": "item",
"label": _("Item"),
"fieldtype": "Link",
"options": "Item",
"width": 120,
},
{
"fieldname": "description",
"label": _("Description"),
"fieldtype": "Data",
"width": 150,
},
{
"fieldname": "manufacturer",
"label": _("Manufacturer"),
"fieldtype": "Data",
"width": 120,
},
{
"fieldname": "manufacturer_part_number",
"label": _("Manufacturer Part Number"),
"fieldtype": "Data",
"width": 150,
},
{
"fieldname": "qty_per_unit",
"label": _("Qty Per Unit"),
"fieldtype": "Float",
"width": 110,
},
{
"fieldname": "available_qty",
"label": _("Available Qty"),
"fieldtype": "Float",
"width": 120,
},
{
"fieldname": "required_qty",
"label": _("Required Qty"),
"fieldtype": "Float",
"width": 120,
},
{
"fieldname": "difference_qty",
"label": _("Difference Qty"),
"fieldtype": "Float",
"width": 130,
},
{
"fieldname": "last_purchase_rate",
"label": _("Last Purchase Rate"),
"fieldtype": "Float",
"width": 160,
},
"""return columns"""
columns = [
_("Item") + ":Link/Item:100",
_("Description") + "::150",
_("Manufacturer") + "::250",
_("Manufacturer Part Number") + "::250",
_("Qty") + ":Float:50",
_("Stock Qty") + ":Float:100",
_("Reqd Qty") + ":Float:100",
_("Diff Qty") + ":Float:100",
_("Last Purchase Price") + ":Float:100",
]
return columns
def get_bom_data(filters):
def get_bom_stock(filters):
conditions = ""
bom = filters.get("bom")
table = "`tabBOM Item`"
qty_field = "qty"
if filters.get("show_exploded_view"):
bom_item_table = "BOM Explosion Item"
else:
bom_item_table = "BOM Item"
bom_item = frappe.qb.DocType(bom_item_table)
bin = frappe.qb.DocType("Bin")
query = (
frappe.qb.from_(bom_item)
.left_join(bin)
.on(bom_item.item_code == bin.item_code)
.select(
bom_item.item_code,
bom_item.description,
bom_item.qty_consumed_per_unit.as_("qty_per_unit"),
IfNull(Sum(bin.actual_qty), 0).as_("actual_qty"),
)
.where((bom_item.parent == filters.get("bom")) & (bom_item.parenttype == "BOM"))
.groupby(bom_item.item_code)
)
table = "`tabBOM Explosion Item`"
qty_field = "stock_qty"
if filters.get("warehouse"):
warehouse_details = frappe.db.get_value(
"Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1
)
if warehouse_details:
wh = frappe.qb.DocType("Warehouse")
query = query.where(
ExistsCriterion(
frappe.qb.from_(wh)
.select(wh.name)
.where(
(wh.lft >= warehouse_details.lft)
& (wh.rgt <= warehouse_details.rgt)
& (bin.warehouse == wh.name)
)
)
conditions += (
" and exists (select name from `tabWarehouse` wh \
where wh.lft >= %s and wh.rgt <= %s and ledger.warehouse = wh.name)"
% (warehouse_details.lft, warehouse_details.rgt)
)
else:
query = query.where(bin.warehouse == frappe.db.escape(filters.get("warehouse")))
conditions += " and ledger.warehouse = %s" % frappe.db.escape(filters.get("warehouse"))
return query.run(as_dict=True)
else:
conditions += ""
return frappe.db.sql(
"""
SELECT
bom_item.item_code,
bom_item.description,
bom_item.{qty_field},
ifnull(sum(ledger.actual_qty), 0) as actual_qty,
ifnull(sum(FLOOR(ledger.actual_qty / bom_item.{qty_field})), 0) as to_build
FROM
{table} AS bom_item
LEFT JOIN `tabBin` AS ledger
ON bom_item.item_code = ledger.item_code
{conditions}
WHERE
bom_item.parent = '{bom}' and bom_item.parenttype='BOM'
GROUP BY bom_item.item_code""".format(
qty_field=qty_field, table=table, conditions=conditions, bom=bom
),
as_dict=1,
)
def get_manufacturer_records():
details = frappe.get_all(
"Item Manufacturer", fields=["manufacturer", "manufacturer_part_no", "item_code"]
)
manufacture_details = frappe._dict()
for detail in details:
dic = manufacture_details.setdefault(detail.get("item_code"), {})

View File

@@ -1,115 +0,0 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from frappe.tests.utils import FrappeTestCase
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
from erpnext.manufacturing.report.bom_stock_calculated.bom_stock_calculated import (
execute as bom_stock_calculated_report,
)
from erpnext.stock.doctype.item.test_item import make_item
class TestBOMStockCalculated(FrappeTestCase):
def setUp(self):
self.fg_item, self.rm_items = create_items()
self.boms = create_boms(self.fg_item, self.rm_items)
def test_bom_stock_calculated(self):
qty_to_make = 10
# Case 1: When Item(s) Qty and Stock Qty are equal.
data = bom_stock_calculated_report(
filters={
"qty_to_make": qty_to_make,
"bom": self.boms[0].name,
}
)[1]
expected_data = get_expected_data(self.boms[0], qty_to_make)
self.assertSetEqual(set(tuple(x) for x in data), set(tuple(x) for x in expected_data))
# Case 2: When Item(s) Qty and Stock Qty are different and BOM Qty is 1.
data = bom_stock_calculated_report(
filters={
"qty_to_make": qty_to_make,
"bom": self.boms[1].name,
}
)[1]
expected_data = get_expected_data(self.boms[1], qty_to_make)
self.assertSetEqual(set(tuple(x) for x in data), set(tuple(x) for x in expected_data))
# Case 3: When Item(s) Qty and Stock Qty are different and BOM Qty is greater than 1.
data = bom_stock_calculated_report(
filters={
"qty_to_make": qty_to_make,
"bom": self.boms[2].name,
}
)[1]
expected_data = get_expected_data(self.boms[2], qty_to_make)
self.assertSetEqual(set(tuple(x) for x in data), set(tuple(x) for x in expected_data))
def create_items():
fg_item = make_item(properties={"is_stock_item": 1}).name
rm_item1 = make_item(
properties={
"is_stock_item": 1,
"standard_rate": 100,
"opening_stock": 100,
"last_purchase_rate": 100,
}
).name
rm_item2 = make_item(
properties={
"is_stock_item": 1,
"standard_rate": 200,
"opening_stock": 200,
"last_purchase_rate": 200,
}
).name
return fg_item, [rm_item1, rm_item2]
def create_boms(fg_item, rm_items):
def update_bom_items(bom, uom, conversion_factor):
for item in bom.items:
item.uom = uom
item.conversion_factor = conversion_factor
return bom
bom1 = make_bom(item=fg_item, quantity=1, raw_materials=rm_items, rm_qty=10)
bom2 = make_bom(item=fg_item, quantity=1, raw_materials=rm_items, rm_qty=10, do_not_submit=True)
bom2 = update_bom_items(bom2, "Box", 10)
bom2.save()
bom2.submit()
bom3 = make_bom(item=fg_item, quantity=2, raw_materials=rm_items, rm_qty=10, do_not_submit=True)
bom3 = update_bom_items(bom3, "Box", 10)
bom3.save()
bom3.submit()
return [bom1, bom2, bom3]
def get_expected_data(bom, qty_to_make):
expected_data = []
for idx in range(len(bom.items)):
expected_data.append(
[
bom.items[idx].item_code,
bom.items[idx].item_code,
"",
"",
float(bom.items[idx].stock_qty / bom.quantity),
float(100 * (idx + 1)),
float(qty_to_make * (bom.items[idx].stock_qty / bom.quantity)),
float((100 * (idx + 1)) - (qty_to_make * (bom.items[idx].stock_qty / bom.quantity))),
float(100 * (idx + 1)),
]
)
return expected_data

View File

@@ -373,4 +373,3 @@ erpnext.patches.v13_0.fix_number_and_frequency_for_monthly_depreciation
erpnext.patches.v13_0.reset_corrupt_defaults
erpnext.patches.v13_0.show_hr_payroll_deprecation_warning
erpnext.patches.v13_0.create_accounting_dimensions_for_asset_repair
execute:frappe.db.set_value("Naming Series", "Naming Series", {"select_doc_for_series": "", "set_options": "", "prefix": "", "current_value": 0, "user_must_always_select": 0})

View File

@@ -16,18 +16,18 @@ def execute():
delete_auto_email_reports(report)
check_and_delete_linked_reports(report)
frappe.delete_doc("Report", report, force=True)
frappe.delete_doc("Report", report)
def delete_auto_email_reports(report):
"""Check for one or multiple Auto Email Reports and delete"""
auto_email_reports = frappe.db.get_values("Auto Email Report", {"report": report}, ["name"])
for auto_email_report in auto_email_reports:
frappe.delete_doc("Auto Email Report", auto_email_report[0], force=True)
frappe.delete_doc("Auto Email Report", auto_email_report[0])
def delete_links_from_desktop_icons(report):
"""Check for one or multiple Desktop Icons and delete"""
desktop_icons = frappe.db.get_values("Desktop Icon", {"_report": report}, ["name"])
for desktop_icon in desktop_icons:
frappe.delete_doc("Desktop Icon", desktop_icon[0], force=True)
frappe.delete_doc("Desktop Icon", desktop_icon[0])

View File

@@ -9,7 +9,7 @@ from frappe.utils import add_days, date_diff, get_year_ending, get_year_start, g
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.holiday_list.test_holiday_list import set_holiday_list
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.hr.doctype.leave_application.test_leave_application import get_first_sunday
from erpnext.hr.utils import get_holiday_dates_for_employee
from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_application import (
calculate_lwp,

View File

@@ -587,7 +587,7 @@ class SalarySlip(TransactionBase):
if self.salary_structure:
self.calculate_component_amounts("deductions")
self.add_applicable_loans()
self.set_loan_repayment()
self.set_precision_for_component_amounts()
self.set_net_pay()
@@ -632,19 +632,9 @@ class SalarySlip(TransactionBase):
continue
amount = self.eval_condition_and_formula(struct_row, data)
if struct_row.statistical_component:
# update statitical component amount in reference data based on payment days
# since row for statistical component is not added to salary slip
if struct_row.depends_on_payment_days:
joining_date, relieving_date = self.get_joining_and_relieving_dates()
default_data[struct_row.abbr] = amount
data[struct_row.abbr] = flt(
(flt(amount) * flt(self.payment_days) / cint(self.total_working_days)),
struct_row.precision("amount"),
)
elif amount or struct_row.amount_based_on_formula and amount is not None:
if (
amount or (struct_row.amount_based_on_formula and amount is not None)
) and struct_row.statistical_component == 0:
default_amount = self.eval_condition_and_formula(struct_row, default_data)
self.update_component_row(
struct_row, amount, component_type, data=data, default_amount=default_amount
@@ -697,8 +687,8 @@ class SalarySlip(TransactionBase):
for key in ("earnings", "deductions"):
for d in self.get(key):
default_data[d.abbr] = d.default_amount or 0
data[d.abbr] = d.amount or 0
default_data[d.abbr] = d.default_amount
data[d.abbr] = d.amount
return data, default_data
@@ -1380,47 +1370,44 @@ class SalarySlip(TransactionBase):
return joining_date, relieving_date
def add_applicable_loans(self):
def set_loan_repayment(self):
self.total_loan_repayment = 0
self.total_interest_amount = 0
self.total_principal_amount = 0
loans = [d.loan for d in self.get("loans")]
self.set("loans", [])
for loan in self.get_loan_details():
if loan.name not in loans:
amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment")
if (
amounts["interest_amount"] + amounts["payable_principal_amount"]
> amounts["written_off_amount"]
):
if amounts["interest_amount"] > amounts["written_off_amount"]:
amounts["interest_amount"] -= amounts["written_off_amount"]
amounts["written_off_amount"] = 0
else:
amounts["written_off_amount"] -= amounts["interest_amount"]
amounts["interest_amount"] = 0
amounts = calculate_amounts(loan.name, self.posting_date, "Regular Payment")
if amounts["payable_principal_amount"] > amounts["written_off_amount"]:
amounts["payable_principal_amount"] -= amounts["written_off_amount"]
amounts["written_off_amount"] = 0
else:
amounts["written_off_amount"] -= amounts["payable_principal_amount"]
amounts["payable_principal_amount"] = 0
if (amounts["interest_amount"] or amounts["payable_principal_amount"]) and (
amounts["payable_principal_amount"] + amounts["interest_amount"]
> amounts["written_off_amount"]
):
self.append(
"loans",
{
"loan": loan.name,
"interest_amount": amounts["interest_amount"],
"principal_amount": amounts["payable_principal_amount"],
"total_payment": amounts["interest_amount"] + amounts["payable_principal_amount"]
if not loan.manually_update_paid_amount_in_salary_slip
else 0,
"loan_account": loan.loan_account,
"interest_income_account": loan.interest_income_account,
},
)
if amounts["interest_amount"] > amounts["written_off_amount"]:
amounts["interest_amount"] -= amounts["written_off_amount"]
amounts["written_off_amount"] = 0
else:
amounts["written_off_amount"] -= amounts["interest_amount"]
amounts["interest_amount"] = 0
if amounts["payable_principal_amount"] > amounts["written_off_amount"]:
amounts["payable_principal_amount"] -= amounts["written_off_amount"]
amounts["written_off_amount"] = 0
else:
amounts["written_off_amount"] -= amounts["payable_principal_amount"]
amounts["payable_principal_amount"] = 0
self.append(
"loans",
{
"loan": loan.name,
"interest_amount": amounts["interest_amount"],
"principal_amount": amounts["payable_principal_amount"],
"loan_account": loan.loan_account,
"interest_income_account": loan.interest_income_account,
},
)
for payment in self.get("loans"):
amounts = calculate_amounts(payment.loan, self.posting_date, "Regular Payment")
@@ -1445,14 +1432,7 @@ class SalarySlip(TransactionBase):
def get_loan_details(self):
loan_details = frappe.get_all(
"Loan",
fields=[
"name",
"interest_income_account",
"loan_account",
"loan_type",
"is_term_loan",
"manually_update_paid_amount_in_salary_slip",
],
fields=["name", "interest_income_account", "loan_account", "loan_type", "is_term_loan"],
filters={
"applicant": self.employee,
"docstatus": 1,

View File

@@ -27,7 +27,6 @@ from erpnext.hr.doctype.attendance.attendance import mark_attendance
from erpnext.hr.doctype.employee.test_employee import make_employee
from erpnext.hr.doctype.leave_allocation.test_leave_allocation import create_leave_allocation
from erpnext.hr.doctype.leave_type.test_leave_type import create_leave_type
from erpnext.hr.tests.test_utils import get_first_sunday
from erpnext.payroll.doctype.employee_tax_exemption_declaration.test_employee_tax_exemption_declaration import (
create_exemption_category,
create_payroll_period,
@@ -56,7 +55,18 @@ class TestSalarySlip(FrappeTestCase):
frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0)
first_sunday = get_first_sunday()
month_start_date = get_first_day(nowdate())
month_end_date = get_last_day(nowdate())
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = 'Salary Slip Test Holiday List'
and holiday_date between %s and %s
order by holiday_date
""",
(month_start_date, month_end_date),
)[0][0]
mark_attendance(emp_id, first_sunday, "Absent", ignore_validate=True) # invalid lwp
mark_attendance(
@@ -263,7 +273,19 @@ class TestSalarySlip(FrappeTestCase):
frappe.db.set_value("Leave Type", "Leave Without Pay", "include_holiday", 0)
first_sunday = get_first_sunday()
month_start_date = get_first_day(nowdate())
month_end_date = get_last_day(nowdate())
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = 'Salary Slip Test Holiday List'
and holiday_date between %s and %s
order by holiday_date
""",
(month_start_date, month_end_date),
)[0][0]
make_leave_application(emp_id, first_sunday, add_days(first_sunday, 3), "Leave Without Pay")
leave_type_ppl = create_leave_type(leave_type_name="Test Partially Paid Leave", is_ppl=1)
@@ -316,7 +338,19 @@ class TestSalarySlip(FrappeTestCase):
frappe.db.set_value("Employee", emp, {"relieving_date": None, "status": "Active"})
# mark attendance
first_sunday = get_first_sunday()
month_start_date = get_first_day(nowdate())
month_end_date = get_last_day(nowdate())
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = 'Salary Slip Test Holiday List'
and holiday_date between %s and %s
order by holiday_date
""",
(month_start_date, month_end_date),
)[0][0]
mark_attendance(
emp, add_days(first_sunday, 1), "Absent", ignore_validate=True
) # counted as absent
@@ -325,8 +359,8 @@ class TestSalarySlip(FrappeTestCase):
make_salary_structure_for_timesheet(emp)
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
salary_slip = make_salary_slip_for_timesheet(timesheet.name)
salary_slip.start_date = get_first_day(nowdate())
salary_slip.end_date = get_last_day(nowdate())
salary_slip.start_date = month_start_date
salary_slip.end_date = month_end_date
salary_slip.save()
salary_slip.submit()
salary_slip.reload()
@@ -368,7 +402,18 @@ class TestSalarySlip(FrappeTestCase):
)
# mark employee absent for a day since this case works fine if payment days are equal to working days
first_sunday = get_first_sunday()
month_start_date = get_first_day(nowdate())
month_end_date = get_last_day(nowdate())
first_sunday = frappe.db.sql(
"""
select holiday_date from `tabHoliday`
where parent = 'Salary Slip Test Holiday List'
and holiday_date between %s and %s
order by holiday_date
""",
(month_start_date, month_end_date),
)[0][0]
mark_attendance(
employee, add_days(first_sunday, 1), "Absent", ignore_validate=True
@@ -987,42 +1032,6 @@ class TestSalarySlip(FrappeTestCase):
components = [row.salary_component for row in new_ss.get("earnings")]
self.assertNotIn("Statistical Component", components)
@change_settings(
"Payroll Settings",
{"payroll_based_on": "Attendance", "consider_unmarked_attendance_as": "Present"},
)
def test_statistical_component_based_on_payment_days(self):
"""
Tests whether component using statistical component in the formula
gets the updated value based on payment days
"""
from erpnext.payroll.doctype.salary_structure.test_salary_structure import (
create_salary_structure_assignment,
)
emp = make_employee("test_statistical_component@salary.com")
first_sunday = get_first_sunday()
mark_attendance(emp, add_days(first_sunday, 1), "Absent", ignore_validate=True)
salary_structure = make_salary_structure_for_payment_days_based_component_dependency(
test_statistical_comp=True
)
create_salary_structure_assignment(
emp, salary_structure.name, company="_Test Company", currency="INR"
)
# make salary slip and assert payment days
ss = make_salary_slip_for_payment_days_dependency_test(
"test_statistical_component@salary.com", salary_structure.name
)
amount = precision = None
for entry in ss.earnings:
if entry.salary_component == "Dependency Component":
amount = entry.amount
precision = entry.precision("amount")
break
self.assertEqual(amount, flt((1000 * ss.payment_days / ss.total_working_days) * 0.5, precision))
def make_activity_for_employee(self):
activity_type = frappe.get_doc("Activity Type", "_Test Activity Type")
activity_type.billing_rate = 50
@@ -1142,11 +1151,7 @@ def create_account(account_name, company, parent_account, account_type=None):
def make_earning_salary_component(
setup=False,
test_tax=False,
company_list=None,
include_flexi_benefits=False,
test_statistical_comp=False,
setup=False, test_tax=False, company_list=None, include_flexi_benefits=False
):
data = [
{
@@ -1512,7 +1517,7 @@ def make_holiday_list(list_name=None, from_date=None, to_date=None):
return holiday_list
def make_salary_structure_for_payment_days_based_component_dependency(test_statistical_comp=False):
def make_salary_structure_for_payment_days_based_component_dependency():
earnings = [
{
"salary_component": "Basic Salary - Payment Days",
@@ -1530,27 +1535,6 @@ def make_salary_structure_for_payment_days_based_component_dependency(test_stati
"formula": "base * 0.20",
},
]
if test_statistical_comp:
earnings.extend(
[
{
"salary_component": "Statistical Component",
"abbr": "SC",
"type": "Earning",
"statistical_component": 1,
"amount": 1000,
"depends_on_payment_days": 1,
},
{
"salary_component": "Dependency Component",
"abbr": "DC",
"type": "Earning",
"amount_based_on_formula": 1,
"formula": "SC * 0.5",
"depends_on_payment_days": 0,
},
]
)
make_salary_component(earnings, False, company_list=["_Test Company"])

View File

@@ -134,7 +134,6 @@ function open_form(frm, doctype, child_doctype, parentfield) {
new_child_doc.parentfield = parentfield;
new_child_doc.parenttype = doctype;
new_doc[parentfield] = [new_child_doc];
new_doc.project = frm.doc.name;
frappe.ui.form.make_quick_entry(doctype, null, null, new_doc);
});

View File

@@ -177,16 +177,16 @@ def get_tax_data_for_each_vat_setting(vat_setting, filters, doctype):
"parent": invoice.name,
"item_tax_template": vat_setting.item_tax_template,
},
fields=["item_code", "base_net_amount"],
fields=["item_code", "net_amount"],
)
for item in invoice_items:
# Summing up total taxable amount
if invoice.is_return == 0:
total_taxable_amount += item.base_net_amount
total_taxable_amount += item.net_amount
if invoice.is_return == 1:
total_taxable_adjustment_amount += item.base_net_amount
total_taxable_adjustment_amount += item.net_amount
# Summing up total tax
total_tax += get_tax_amount(item.item_code, vat_setting.account, doctype, invoice.name)

View File

@@ -87,7 +87,7 @@ def create_qr_code(doc, method=None):
tlv_array.append("".join([tag, length, value]))
# Invoice Amount
invoice_amount = str(doc.base_grand_total)
invoice_amount = str(doc.grand_total)
tag = bytes([4]).hex()
length = bytes([len(invoice_amount)]).hex()
value = invoice_amount.encode("utf-8").hex()
@@ -147,7 +147,7 @@ def get_vat_amount(doc):
for tax in doc.get("taxes"):
if tax.account_head in vat_accounts:
vat_amount += tax.base_tax_amount
vat_amount += tax.tax_amount
return vat_amount

View File

@@ -265,7 +265,7 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
def set_expired_status():
# filter out submitted non expired quotations whose validity has been ended
cond = "qo.docstatus = 1 and qo.status NOT IN ('Expired', 'Lost') and qo.valid_till < %s"
cond = "qo.docstatus = 1 and qo.status != 'Expired' and qo.valid_till < %s"
# check if those QUO have SO against it
so_against_quo = """
SELECT

View File

@@ -950,9 +950,6 @@ def get_events(start, end, filters=None):
@frappe.whitelist()
def make_purchase_order_for_default_supplier(source_name, selected_items=None, target_doc=None):
"""Creates Purchase Order for each Supplier. Returns a list of doc objects."""
from erpnext.setup.utils import get_exchange_rate
if not selected_items:
return
@@ -961,20 +958,10 @@ def make_purchase_order_for_default_supplier(source_name, selected_items=None, t
def set_missing_values(source, target):
target.supplier = supplier
target.currency = frappe.db.get_value(
"Supplier", filters={"name": supplier}, fieldname=["default_currency"]
)
company_currency = frappe.db.get_value(
"Company", filters={"name": target.company}, fieldname=["default_currency"]
)
target.conversion_rate = get_exchange_rate(target.currency, company_currency, args="for_buying")
target.apply_discount_on = ""
target.additional_discount_percentage = 0.0
target.discount_amount = 0.0
target.inter_company_order_reference = ""
target.shipping_rule = ""
default_price_list = frappe.get_value("Supplier", supplier, "default_price_list")
if default_price_list:
@@ -1093,7 +1080,6 @@ def make_purchase_order(source_name, selected_items=None, target_doc=None):
target.additional_discount_percentage = 0.0
target.discount_amount = 0.0
target.inter_company_order_reference = ""
target.shipping_rule = ""
target.customer = ""
target.customer_name = ""
target.run_method("set_missing_values")

View File

@@ -16,7 +16,6 @@
"in_list_view": 1,
"label": "Barcode",
"no_copy": 1,
"reqd": 1,
"unique": 1
},
{
@@ -29,7 +28,7 @@
],
"istable": 1,
"links": [],
"modified": "2022-08-24 19:59:47.871677",
"modified": "2022-04-01 05:54:27.314030",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Barcode",

View File

@@ -48,31 +48,41 @@
"oldfieldtype": "Select",
"options": "Item",
"reqd": 1,
"search_index": 1
"search_index": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"options": "UOM"
"options": "UOM",
"show_days": 1,
"show_seconds": 1
},
{
"default": "0",
"description": "Quantity that must be bought or sold per UOM",
"fieldname": "packing_unit",
"fieldtype": "Int",
"label": "Packing Unit"
"label": "Packing Unit",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "column_break_17",
"fieldtype": "Column Break"
"fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "item_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Item Name",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fetch_from": "item_code.brand",
@@ -80,29 +90,36 @@
"fieldtype": "Read Only",
"in_list_view": 1,
"label": "Brand",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "item_description",
"fieldtype": "Text",
"label": "Item Description",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "price_list_details",
"fieldtype": "Section Break",
"label": "Price List",
"options": "fa fa-tags"
"options": "fa fa-tags",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "price_list",
"fieldtype": "Link",
"in_global_search": 1,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Price List",
"options": "Price List",
"reqd": 1
"reqd": 1,
"show_days": 1,
"show_seconds": 1
},
{
"bold": 1,
@@ -110,37 +127,49 @@
"fieldname": "customer",
"fieldtype": "Link",
"label": "Customer",
"options": "Customer"
"options": "Customer",
"show_days": 1,
"show_seconds": 1
},
{
"depends_on": "eval:doc.buying == 1",
"fieldname": "supplier",
"fieldtype": "Link",
"label": "Supplier",
"options": "Supplier"
"options": "Supplier",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
"fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
},
{
"default": "0",
"fieldname": "buying",
"fieldtype": "Check",
"label": "Buying",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"default": "0",
"fieldname": "selling",
"fieldtype": "Check",
"label": "Selling",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "item_details",
"fieldtype": "Section Break",
"options": "fa fa-tag"
"options": "fa fa-tag",
"show_days": 1,
"show_seconds": 1
},
{
"bold": 1,
@@ -148,11 +177,15 @@
"fieldtype": "Link",
"label": "Currency",
"options": "Currency",
"read_only": 1
"read_only": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "col_br_1",
"fieldtype": "Column Break"
"fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "price_list_rate",
@@ -164,61 +197,80 @@
"oldfieldname": "ref_rate",
"oldfieldtype": "Currency",
"options": "currency",
"reqd": 1
"reqd": 1,
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "section_break_15",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
},
{
"default": "Today",
"fieldname": "valid_from",
"fieldtype": "Date",
"label": "Valid From"
"label": "Valid From",
"show_days": 1,
"show_seconds": 1
},
{
"default": "0",
"fieldname": "lead_time_days",
"fieldtype": "Int",
"label": "Lead Time in days"
"label": "Lead Time in days",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "column_break_18",
"fieldtype": "Column Break"
"fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "valid_upto",
"fieldtype": "Date",
"label": "Valid Upto"
"label": "Valid Upto",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "section_break_24",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "note",
"fieldtype": "Text",
"label": "Note"
"label": "Note",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "reference",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Reference"
"label": "Reference",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "batch_no",
"fieldtype": "Link",
"label": "Batch No",
"options": "Batch"
"options": "Batch",
"show_days": 1,
"show_seconds": 1
}
],
"icon": "fa fa-flag",
"idx": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-09-02 16:33:55.612992",
"modified": "2020-12-08 18:12:15.395772",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Price",
@@ -255,7 +307,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "ASC",
"states": [],
"title_field": "item_name",
"track_changes": 1
}

View File

@@ -1,3 +0,0 @@
frappe.listview_settings['Item Price'] = {
hide_name_column: true,
};

View File

@@ -1,43 +1,95 @@
{
"actions": [],
"creation": "2013-02-22 01:28:01",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"supplier",
"supplier_part_no"
],
"allow_copy": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2013-02-22 01:28:01",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"fields": [
{
"fieldname": "supplier",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Supplier",
"options": "Supplier",
"reqd": 1
},
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "supplier",
"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": "Supplier",
"length": 0,
"no_copy": 0,
"options": "Supplier",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"fieldname": "supplier_part_no",
"fieldtype": "Data",
"in_global_search": 1,
"in_list_view": 1,
"label": "Supplier Part Number",
"print_width": "200px",
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "supplier_part_no",
"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": "Supplier Part Number",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": "200px",
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "200px"
}
],
"idx": 1,
"istable": 1,
"links": [],
"modified": "2022-09-07 12:33:55.780062",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Supplier",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
],
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 1,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2017-02-20 13:29:32.569715",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Supplier",
"owner": "Administrator",
"permissions": [],
"quick_entry": 0,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"track_changes": 1,
"track_seen": 0
}

View File

@@ -174,7 +174,7 @@ class PickList(Document):
frappe.throw("Row #{0}: Item Code is Mandatory".format(item.idx))
item_code = item.item_code
reference = item.sales_order_item or item.material_request_item
key = (item_code, item.uom, item.warehouse, reference)
key = (item_code, item.uom, reference)
item.idx = None
item.name = None

View File

@@ -367,12 +367,6 @@ class PurchaseReceipt(BuyingController):
if credit_currency == self.company_currency
else flt(d.net_amount, d.precision("net_amount"))
)
outgoing_amount = d.base_net_amount
if self.is_internal_supplier and d.valuation_rate:
outgoing_amount = d.valuation_rate * d.stock_qty
credit_amount = outgoing_amount
if credit_amount:
account = warehouse_account[d.from_warehouse]["account"] if d.from_warehouse else stock_rbnb
@@ -380,7 +374,7 @@ class PurchaseReceipt(BuyingController):
gl_entries=gl_entries,
account=account,
cost_center=d.cost_center,
debit=-1 * flt(outgoing_amount, d.precision("base_net_amount")),
debit=-1 * flt(d.base_net_amount, d.precision("base_net_amount")),
credit=0.0,
remarks=remarks,
against_account=warehouse_account_name,
@@ -429,7 +423,7 @@ class PurchaseReceipt(BuyingController):
# divisional loss adjustment
valuation_amount_as_per_doc = (
flt(outgoing_amount, d.precision("base_net_amount"))
flt(d.base_net_amount, d.precision("base_net_amount"))
+ flt(d.landed_cost_voucher_amount)
+ flt(d.rm_supp_cost)
+ flt(d.item_tax_amount)

View File

@@ -9,7 +9,6 @@ from collections import defaultdict
import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, cint, cstr, flt, today
from pypika import functions as fn
from six import iteritems
import erpnext
@@ -1362,125 +1361,6 @@ class TestPurchaseReceipt(FrappeTestCase):
if gle.account == account:
self.assertEqual(gle.credit, 50)
def test_backdated_transaction_for_internal_transfer(self):
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
prepare_data_for_internal_transfer()
customer = "_Test Internal Customer 2"
company = "_Test Company with perpetual inventory"
from_warehouse = create_warehouse("_Test Internal From Warehouse New", company=company)
to_warehouse = create_warehouse("_Test Internal To Warehouse New", company=company)
item_doc = create_item("Test Internal Transfer Item")
target_warehouse = create_warehouse("_Test Internal GIT Warehouse New", company=company)
make_purchase_receipt(
item_code=item_doc.name,
company=company,
posting_date=add_days(today(), -1),
warehouse=from_warehouse,
qty=1,
rate=100,
)
dn1 = create_delivery_note(
item_code=item_doc.name,
company=company,
customer=customer,
cost_center="Main - TCP1",
expense_account="Cost of Goods Sold - TCP1",
qty=1,
rate=500,
warehouse=from_warehouse,
target_warehouse=target_warehouse,
)
self.assertEqual(dn1.items[0].rate, 100)
pr1 = make_inter_company_purchase_receipt(dn1.name)
pr1.items[0].warehouse = to_warehouse
self.assertEqual(pr1.items[0].rate, 100)
pr1.submit()
# Backdated purchase receipt entry, the valuation rate should be updated for DN1 and PR1
make_purchase_receipt(
item_code=item_doc.name,
company=company,
posting_date=add_days(today(), -2),
warehouse=from_warehouse,
qty=1,
rate=200,
)
dn_value = frappe.db.get_value(
"Stock Ledger Entry",
{"voucher_type": "Delivery Note", "voucher_no": dn1.name, "warehouse": target_warehouse},
"stock_value_difference",
)
self.assertEqual(abs(dn_value), 200.00)
pr_value = frappe.db.get_value(
"Stock Ledger Entry",
{"voucher_type": "Purchase Receipt", "voucher_no": pr1.name, "warehouse": to_warehouse},
"stock_value_difference",
)
self.assertEqual(abs(pr_value), 200.00)
pr1.load_from_db()
self.assertEqual(pr1.items[0].valuation_rate, 200)
self.assertEqual(pr1.items[0].rate, 100)
Gl = frappe.qb.DocType("GL Entry")
query = (
frappe.qb.from_(Gl)
.select(
(fn.Sum(Gl.debit) - fn.Sum(Gl.credit)).as_("value"),
)
.where((Gl.voucher_type == pr1.doctype) & (Gl.voucher_no == pr1.name))
).run(as_dict=True)
self.assertEqual(query[0].value, 0)
def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
company = "_Test Company with perpetual inventory"
create_internal_customer(
"_Test Internal Customer 2",
company,
company,
)
create_internal_supplier(
"_Test Internal Supplier 2",
company,
company,
)
if not frappe.db.get_value("Company", company, "unrealized_profit_loss_account"):
account = "Unrealized Profit and Loss - TCP1"
if not frappe.db.exists("Account", account):
frappe.get_doc(
{
"doctype": "Account",
"account_name": "Unrealized Profit and Loss",
"parent_account": "Direct Income - TCP1",
"company": company,
"is_group": 0,
"account_type": "Income Account",
}
).insert()
frappe.db.set_value("Company", company, "unrealized_profit_loss_account", account)
def get_sl_entries(voucher_type, voucher_no):
return frappe.db.sql(

View File

@@ -58,21 +58,6 @@ frappe.ui.form.on('Repost Item Valuation', {
}
frm.trigger('show_reposting_progress');
if (frm.doc.status === 'Queued' && frm.doc.docstatus === 1) {
frm.trigger('execute_reposting');
}
},
execute_reposting(frm) {
frm.add_custom_button(__("Start Reposting"), () => {
frappe.call({
method: 'erpnext.stock.doctype.repost_item_valuation.repost_item_valuation.execute_repost_item_valuation',
callback: function() {
frappe.msgprint(__('Reposting has been started in the background.'));
}
});
});
},
show_reposting_progress: function(frm) {

View File

@@ -302,9 +302,3 @@ def in_configured_timeslot(repost_settings=None, current_time=None):
return end_time >= now_time >= start_time
else:
return now_time >= start_time or now_time <= end_time
@frappe.whitelist()
def execute_repost_item_valuation():
"""Execute repost item valuation via scheduler."""
frappe.get_doc("Scheduled Job Type", "repost_item_valuation.repost_entries").enqueue(force=True)

View File

@@ -856,22 +856,15 @@ class StockEntry(StockController):
se_item.item_code, self.purchase_order
)
)
se = frappe.qb.DocType("Stock Entry")
se_detail = frappe.qb.DocType("Stock Entry Detail")
total_supplied = (
frappe.qb.from_(se)
.inner_join(se_detail)
.on(se.name == se_detail.parent)
.select(Sum(se_detail.transfer_qty))
.where(
(se.purpose == "Send to Subcontractor")
& (se.purchase_order == self.purchase_order)
& (se_detail.item_code == se_item.item_code)
& (se.docstatus == 1)
)
).run()[0][0]
total_supplied = frappe.db.sql(
"""select sum(transfer_qty)
from `tabStock Entry Detail`, `tabStock Entry`
where `tabStock Entry`.purchase_order = %s
and `tabStock Entry`.docstatus = 1
and `tabStock Entry Detail`.item_code = %s
and `tabStock Entry Detail`.parent = `tabStock Entry`.name""",
(self.purchase_order, se_item.item_code),
)[0][0]
if flt(total_supplied, precision) > flt(total_allowed, precision):
frappe.throw(
@@ -879,27 +872,6 @@ class StockEntry(StockController):
se_item.idx, se_item.item_code, total_allowed, self.purchase_order
)
)
elif not se_item.get("po_detail"):
filters = {
"parent": self.purchase_order,
"docstatus": 1,
"rm_item_code": se_item.item_code,
"main_item_code": se_item.subcontracted_item,
}
order_rm_detail = frappe.db.get_value("Purchase Order Item Supplied", filters, "name")
if order_rm_detail:
se_item.db_set("po_detail", order_rm_detail)
else:
if not se_item.allow_alternative_item:
frappe.throw(
_("Row {0}# Item {1} not found in 'Raw Materials Supplied' table in {2} {3}").format(
se_item.idx,
se_item.item_code,
"Purchase Order",
self.purchase_order,
)
)
elif backflush_raw_materials_based_on == "Material Transferred for Subcontract":
for row in self.items:
if not row.subcontracted_item:

View File

@@ -34,9 +34,6 @@ def format_report_data(filters: Filters, item_details: Dict, to_date: str) -> Li
precision = cint(frappe.db.get_single_value("System Settings", "float_precision", cache=True))
for item, item_dict in item_details.items():
if not flt(item_dict.get("total_qty"), precision):
continue
earliest_age, latest_age = 0, 0
details = item_dict["details"]

View File

@@ -638,25 +638,21 @@ class update_entries_after(object):
elif (
sle.voucher_type in ["Purchase Receipt", "Purchase Invoice"]
and sle.voucher_detail_no
and sle.actual_qty > 0
and frappe.get_cached_value(sle.voucher_type, sle.voucher_no, "is_internal_supplier")
):
field = (
"delivery_note_item" if sle.voucher_type == "Purchase Receipt" else "sales_invoice_item"
)
doctype = (
"Delivery Note Item" if sle.voucher_type == "Purchase Receipt" else "Sales Invoice Item"
)
refernce_name = frappe.get_cached_value(
sle.voucher_type + " Item", sle.voucher_detail_no, field
sle_details = frappe.db.get_value(
"Stock Ledger Entry",
{
"voucher_type": sle.voucher_type,
"voucher_no": sle.voucher_no,
"dependant_sle_voucher_detail_no": sle.voucher_detail_no,
},
["stock_value_difference", "actual_qty"],
as_dict=1,
)
if refernce_name:
rate = frappe.get_cached_value(
doctype,
refernce_name,
"incoming_rate",
)
rate = abs(sle_details.stock_value_difference / sle.actual_qty)
else:
if sle.voucher_type in ("Purchase Receipt", "Purchase Invoice"):
rate_field = "valuation_rate"
@@ -732,12 +728,7 @@ class update_entries_after(object):
def update_rate_on_purchase_receipt(self, sle, outgoing_rate):
if frappe.db.exists(sle.voucher_type + " Item", sle.voucher_detail_no):
frappe.db.set_value(
sle.voucher_type + " Item",
sle.voucher_detail_no,
{
"base_net_rate": outgoing_rate,
"valuation_rate": outgoing_rate,
},
sle.voucher_type + " Item", sle.voucher_detail_no, "base_net_rate", outgoing_rate
)
else:
frappe.db.set_value(

File diff suppressed because it is too large Load Diff