Merge branch 'develop' into feat/add-delivery-cutoff-date-on-so
This commit is contained in:
commit
12a4f2761c
22
.github/workflows/patch_faux.yml
vendored
Normal file
22
.github/workflows/patch_faux.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# Tests are skipped for these files but github doesn't allow "passing" hence this is required.
|
||||
|
||||
name: Skipped Patch Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "**.js"
|
||||
- "**.css"
|
||||
- "**.md"
|
||||
- "**.html"
|
||||
- "**.csv"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: Patch Test
|
||||
|
||||
steps:
|
||||
- name: Pass skipped tests unconditionally
|
||||
run: "echo Skipped"
|
24
.github/workflows/server-tests-mariadb-faux.yml
vendored
Normal file
24
.github/workflows/server-tests-mariadb-faux.yml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Tests are skipped for these files but github doesn't allow "passing" hence this is required.
|
||||
|
||||
name: Skipped Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "**.js"
|
||||
- "**.css"
|
||||
- "**.md"
|
||||
- "**.html"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
container: [1, 2, 3, 4]
|
||||
|
||||
name: Python Unit Tests
|
||||
|
||||
steps:
|
||||
- name: Pass skipped tests unconditionally
|
||||
run: "echo Skipped"
|
@ -36,16 +36,16 @@
|
||||
}
|
||||
},
|
||||
"Fixed Assets": {
|
||||
"Capital Equipments": {
|
||||
"Capital Equipment": {
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Electronic Equipments": {
|
||||
"Electronic Equipment": {
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Furnitures and Fixtures": {
|
||||
"Furniture and Fixtures": {
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Office Equipments": {
|
||||
"Office Equipment": {
|
||||
"account_type": "Fixed Asset"
|
||||
},
|
||||
"Plants and Machineries": {
|
||||
|
@ -23,13 +23,13 @@ def get():
|
||||
_("Tax Assets"): {"is_group": 1},
|
||||
},
|
||||
_("Fixed Assets"): {
|
||||
_("Capital Equipments"): {"account_type": "Fixed Asset"},
|
||||
_("Electronic Equipments"): {"account_type": "Fixed Asset"},
|
||||
_("Furnitures and Fixtures"): {"account_type": "Fixed Asset"},
|
||||
_("Office Equipments"): {"account_type": "Fixed Asset"},
|
||||
_("Capital Equipment"): {"account_type": "Fixed Asset"},
|
||||
_("Electronic Equipment"): {"account_type": "Fixed Asset"},
|
||||
_("Furniture and Fixtures"): {"account_type": "Fixed Asset"},
|
||||
_("Office Equipment"): {"account_type": "Fixed Asset"},
|
||||
_("Plants and Machineries"): {"account_type": "Fixed Asset"},
|
||||
_("Buildings"): {"account_type": "Fixed Asset"},
|
||||
_("Softwares"): {"account_type": "Fixed Asset"},
|
||||
_("Software"): {"account_type": "Fixed Asset"},
|
||||
_("Accumulated Depreciation"): {"account_type": "Accumulated Depreciation"},
|
||||
_("CWIP Account"): {
|
||||
"account_type": "Capital Work in Progress",
|
||||
|
@ -36,13 +36,13 @@ def get():
|
||||
"account_number": "1100-1600",
|
||||
},
|
||||
_("Fixed Assets"): {
|
||||
_("Capital Equipments"): {"account_type": "Fixed Asset", "account_number": "1710"},
|
||||
_("Electronic Equipments"): {"account_type": "Fixed Asset", "account_number": "1720"},
|
||||
_("Furnitures and Fixtures"): {"account_type": "Fixed Asset", "account_number": "1730"},
|
||||
_("Office Equipments"): {"account_type": "Fixed Asset", "account_number": "1740"},
|
||||
_("Capital Equipment"): {"account_type": "Fixed Asset", "account_number": "1710"},
|
||||
_("Electronic Equipment"): {"account_type": "Fixed Asset", "account_number": "1720"},
|
||||
_("Furniture and Fixtures"): {"account_type": "Fixed Asset", "account_number": "1730"},
|
||||
_("Office Equipment"): {"account_type": "Fixed Asset", "account_number": "1740"},
|
||||
_("Plants and Machineries"): {"account_type": "Fixed Asset", "account_number": "1750"},
|
||||
_("Buildings"): {"account_type": "Fixed Asset", "account_number": "1760"},
|
||||
_("Softwares"): {"account_type": "Fixed Asset", "account_number": "1770"},
|
||||
_("Software"): {"account_type": "Fixed Asset", "account_number": "1770"},
|
||||
_("Accumulated Depreciation"): {
|
||||
"account_type": "Accumulated Depreciation",
|
||||
"account_number": "1780",
|
||||
|
@ -119,7 +119,7 @@ class TestAccount(unittest.TestCase):
|
||||
InvalidAccountMergeError,
|
||||
merge_account,
|
||||
"Capital Stock - _TC",
|
||||
"Softwares - _TC",
|
||||
"Software - _TC",
|
||||
)
|
||||
|
||||
# Raise error as currency doesn't match
|
||||
|
@ -462,7 +462,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-20 09:37:47.650347",
|
||||
"modified": "2024-01-22 12:10:10.151819",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
|
@ -55,7 +55,7 @@ class BankAccount(Document):
|
||||
|
||||
def validate_company(self):
|
||||
if self.is_company_account and not self.company:
|
||||
frappe.throw(_("Company is manadatory for company account"))
|
||||
frappe.throw(_("Company is mandatory for company account"))
|
||||
|
||||
def validate_iban(self):
|
||||
"""
|
||||
|
@ -48,11 +48,11 @@ class BankGuarantee(Document):
|
||||
|
||||
def on_submit(self):
|
||||
if not self.bank_guarantee_number:
|
||||
frappe.throw(_("Enter the Bank Guarantee Number before submittting."))
|
||||
frappe.throw(_("Enter the Bank Guarantee Number before submitting."))
|
||||
if not self.name_of_beneficiary:
|
||||
frappe.throw(_("Enter the name of the Beneficiary before submittting."))
|
||||
frappe.throw(_("Enter the name of the Beneficiary before submitting."))
|
||||
if not self.bank:
|
||||
frappe.throw(_("Enter the name of the bank or lending institution before submittting."))
|
||||
frappe.throw(_("Enter the name of the bank or lending institution before submitting."))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -80,7 +80,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto"
|
||||
"label": "Valid Up To"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval: doc.coupon_type == \"Promotional\"",
|
||||
@ -115,7 +115,7 @@
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"modified": "2019-10-19 14:48:14.602481",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Coupon Code",
|
||||
|
@ -154,7 +154,7 @@ frappe.ui.form.on('Invoice Discounting', {
|
||||
}
|
||||
});
|
||||
},
|
||||
primary_action_label: __('Get Invocies')
|
||||
primary_action_label: __('Get Invoices')
|
||||
});
|
||||
d.show();
|
||||
},
|
||||
|
@ -150,6 +150,20 @@ class JournalEntry(AccountsController):
|
||||
if not self.title:
|
||||
self.title = self.get_title()
|
||||
|
||||
def submit(self):
|
||||
if len(self.accounts) > 100:
|
||||
msgprint(_("The task has been enqueued as a background job."), alert=True)
|
||||
self.queue_action("submit", timeout=4600)
|
||||
else:
|
||||
return self._submit()
|
||||
|
||||
def cancel(self):
|
||||
if len(self.accounts) > 100:
|
||||
msgprint(_("The task has been enqueued as a background job."), alert=True)
|
||||
self.queue_action("cancel", timeout=4600)
|
||||
else:
|
||||
return self._cancel()
|
||||
|
||||
def on_submit(self):
|
||||
self.validate_cheque_info()
|
||||
self.check_credit_limit()
|
||||
@ -187,8 +201,8 @@ class JournalEntry(AccountsController):
|
||||
def update_advance_paid(self):
|
||||
advance_paid = frappe._dict()
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
for d in self.get("accounts"):
|
||||
if d.is_advance:
|
||||
if d.reference_type in advance_payment_doctypes:
|
||||
|
@ -270,7 +270,7 @@ def start_import(invoices):
|
||||
errors, "<a href='/app/List/Error Log' class='variant-click'>Error Log</a>"
|
||||
),
|
||||
indicator="red",
|
||||
title=_("Error Occured"),
|
||||
title=_("Error Occurred"),
|
||||
)
|
||||
return names
|
||||
|
||||
|
@ -87,12 +87,14 @@
|
||||
"status",
|
||||
"custom_remarks",
|
||||
"remarks",
|
||||
"base_in_words",
|
||||
"column_break_16",
|
||||
"letter_head",
|
||||
"print_heading",
|
||||
"bank",
|
||||
"bank_account_no",
|
||||
"payment_order",
|
||||
"in_words",
|
||||
"subscription_section",
|
||||
"auto_repeat",
|
||||
"amended_from",
|
||||
@ -747,6 +749,20 @@
|
||||
"hidden": 1,
|
||||
"label": "Book Advance Payments in Separate Party Account",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "base_in_words",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "In Words (Company Currency)",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "in_words",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "In Words",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
|
@ -178,6 +178,7 @@ class PaymentEntry(AccountsController):
|
||||
self.validate_paid_invoices()
|
||||
self.ensure_supplier_is_not_blocked()
|
||||
self.set_status()
|
||||
self.set_total_in_words()
|
||||
|
||||
def on_submit(self):
|
||||
if self.difference_amount:
|
||||
@ -190,7 +191,7 @@ class PaymentEntry(AccountsController):
|
||||
|
||||
def set_liability_account(self):
|
||||
# Auto setting liability account should only be done during 'draft' status
|
||||
if self.docstatus > 0:
|
||||
if self.docstatus > 0 or self.payment_type == "Internal Transfer":
|
||||
return
|
||||
|
||||
if not frappe.db.get_value(
|
||||
@ -786,6 +787,21 @@ class PaymentEntry(AccountsController):
|
||||
|
||||
self.db_set("status", self.status, update_modified=True)
|
||||
|
||||
def set_total_in_words(self):
|
||||
from frappe.utils import money_in_words
|
||||
|
||||
if self.payment_type in ("Pay", "Internal Transfer"):
|
||||
base_amount = abs(self.base_paid_amount)
|
||||
amount = abs(self.paid_amount)
|
||||
currency = self.paid_from_account_currency
|
||||
elif self.payment_type == "Receive":
|
||||
base_amount = abs(self.base_received_amount)
|
||||
amount = abs(self.received_amount)
|
||||
currency = self.paid_to_account_currency
|
||||
|
||||
self.base_in_words = money_in_words(base_amount, self.company_currency)
|
||||
self.in_words = money_in_words(amount, currency)
|
||||
|
||||
def set_tax_withholding(self):
|
||||
if self.party_type != "Supplier":
|
||||
return
|
||||
@ -927,8 +943,8 @@ class PaymentEntry(AccountsController):
|
||||
def calculate_base_allocated_amount_for_reference(self, d) -> float:
|
||||
base_allocated_amount = 0
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
if d.reference_doctype in advance_payment_doctypes:
|
||||
# When referencing Sales/Purchase Order, use the source/target exchange rate depending on payment type.
|
||||
# This is so there are no Exchange Gain/Loss generated for such doctypes
|
||||
@ -1428,8 +1444,8 @@ class PaymentEntry(AccountsController):
|
||||
def update_advance_paid(self):
|
||||
if self.payment_type in ("Receive", "Pay") and self.party:
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
for d in self.get("references"):
|
||||
if d.allocated_amount and d.reference_doctype in advance_payment_doctypes:
|
||||
frappe.get_doc(
|
||||
|
@ -41,6 +41,7 @@
|
||||
{
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
"label": "Company",
|
||||
"options": "Company",
|
||||
"reqd": 1
|
||||
@ -229,7 +230,7 @@
|
||||
"is_virtual": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-12-14 13:38:16.264013",
|
||||
"modified": "2024-01-18 11:56:20.234667",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Reconciliation",
|
||||
|
@ -170,8 +170,8 @@ class PaymentRequest(Document):
|
||||
self.request_phone_payment()
|
||||
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
if self.reference_doctype in advance_payment_doctypes:
|
||||
# set advance payment status
|
||||
ref_doc.set_total_advance_paid()
|
||||
@ -216,8 +216,8 @@ class PaymentRequest(Document):
|
||||
|
||||
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
if self.reference_doctype in advance_payment_doctypes:
|
||||
# set advance payment status
|
||||
ref_doc.set_total_advance_paid()
|
||||
|
@ -11,7 +11,6 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_lo
|
||||
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
||||
SalesInvoice,
|
||||
get_bank_cash_account,
|
||||
get_mode_of_payment_info,
|
||||
update_multi_mode_option,
|
||||
)
|
||||
@ -208,7 +207,6 @@ class POSInvoice(SalesInvoice):
|
||||
self.validate_stock_availablility()
|
||||
self.validate_return_items_qty()
|
||||
self.set_status()
|
||||
self.set_account_for_mode_of_payment()
|
||||
self.validate_pos()
|
||||
self.validate_payment_amount()
|
||||
self.validate_loyalty_transaction()
|
||||
@ -371,7 +369,7 @@ class POSInvoice(SalesInvoice):
|
||||
if d.get("qty") > 0:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Row #{}: You cannot add postive quantities in a return invoice. Please remove item {} to complete the return."
|
||||
"Row #{}: You cannot add positive quantities in a return invoice. Please remove item {} to complete the return."
|
||||
).format(d.idx, frappe.bold(d.item_code)),
|
||||
title=_("Invalid Item"),
|
||||
)
|
||||
@ -643,11 +641,6 @@ class POSInvoice(SalesInvoice):
|
||||
update_multi_mode_option(self, pos_profile)
|
||||
self.paid_amount = 0
|
||||
|
||||
def set_account_for_mode_of_payment(self):
|
||||
for pay in self.payments:
|
||||
if not pay.account:
|
||||
pay.account = get_bank_cash_account(pay.mode_of_payment, self.company).get("account")
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_payment_request(self):
|
||||
for pay in self.payments:
|
||||
@ -793,7 +786,7 @@ def make_merge_log(invoices):
|
||||
invoices = json.loads(invoices)
|
||||
|
||||
if len(invoices) == 0:
|
||||
frappe.throw(_("Atleast one invoice has to be selected."))
|
||||
frappe.throw(_("At least one invoice has to be selected."))
|
||||
|
||||
merge_log = frappe.new_doc("POS Invoice Merge Log")
|
||||
merge_log.posting_date = getdate(nowdate())
|
||||
|
@ -93,7 +93,7 @@ class TestPOSInvoice(unittest.TestCase):
|
||||
|
||||
inv.save()
|
||||
|
||||
self.assertEqual(inv.net_total, 4298.25)
|
||||
self.assertEqual(inv.net_total, 4298.24)
|
||||
self.assertEqual(inv.grand_total, 4900.00)
|
||||
|
||||
def test_tax_calculation_with_multiple_items(self):
|
||||
|
@ -351,7 +351,7 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
|
||||
inv.load_from_db()
|
||||
consolidated_invoice = frappe.get_doc("Sales Invoice", inv.consolidated_invoice)
|
||||
self.assertEqual(consolidated_invoice.status, "Return")
|
||||
self.assertEqual(consolidated_invoice.rounding_adjustment, -0.001)
|
||||
self.assertEqual(consolidated_invoice.rounding_adjustment, -0.002)
|
||||
|
||||
finally:
|
||||
frappe.set_user("Administrator")
|
||||
|
@ -132,7 +132,7 @@ class POSProfile(Document):
|
||||
|
||||
if len(customer_groups) != len(set(customer_groups)):
|
||||
frappe.throw(
|
||||
_("Duplicate customer group found in the cutomer group table"),
|
||||
_("Duplicate customer group found in the customer group table"),
|
||||
title=_("Duplicate Customer Group"),
|
||||
)
|
||||
|
||||
|
@ -339,7 +339,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto"
|
||||
"label": "Valid Up To"
|
||||
},
|
||||
{
|
||||
"fieldname": "col_break1",
|
||||
@ -608,7 +608,7 @@
|
||||
"icon": "fa fa-gift",
|
||||
"idx": 1,
|
||||
"links": [],
|
||||
"modified": "2023-02-14 04:53:34.887358",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Pricing Rule",
|
||||
|
@ -193,7 +193,7 @@ class PricingRule(Document):
|
||||
|
||||
def validate_applicable_for_selling_or_buying(self):
|
||||
if not self.selling and not self.buying:
|
||||
throw(_("Atleast one of the Selling or Buying must be selected"))
|
||||
throw(_("At least one of the Selling or Buying must be selected"))
|
||||
|
||||
if not self.selling and self.applicable_for in [
|
||||
"Customer",
|
||||
|
@ -232,7 +232,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto"
|
||||
"label": "Valid Up To"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_26",
|
||||
@ -278,7 +278,7 @@
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2021-05-06 16:20:22.039078",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Promotional Scheme",
|
||||
|
@ -1253,6 +1253,7 @@
|
||||
"fieldtype": "Select",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "\nDraft\nReturn\nDebit Note Issued\nSubmitted\nPaid\nPartly Paid\nUnpaid\nOverdue\nCancelled\nInternal Transfer",
|
||||
"print_hide": 1
|
||||
},
|
||||
@ -1612,7 +1613,7 @@
|
||||
"idx": 204,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-29 15:35:44.697496",
|
||||
"modified": "2024-01-26 10:46:00.469053",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice",
|
||||
|
@ -1995,6 +1995,21 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
||||
|
||||
self.assertEqual(pi.items[0].cost_center, "_Test Cost Center Buying - _TC")
|
||||
|
||||
def test_debit_note_with_account_mismatch(self):
|
||||
new_creditors = create_account(
|
||||
parent_account="Accounts Payable - _TC",
|
||||
account_name="Creditors 2",
|
||||
company="_Test Company",
|
||||
account_type="Payable",
|
||||
)
|
||||
pi = make_purchase_invoice(qty=1, rate=1000)
|
||||
dr_note = make_purchase_invoice(
|
||||
qty=-1, rate=1000, is_return=1, return_against=pi.name, do_not_save=True
|
||||
)
|
||||
dr_note.credit_to = new_creditors
|
||||
|
||||
self.assertRaises(frappe.ValidationError, dr_note.save)
|
||||
|
||||
def test_debit_note_without_item(self):
|
||||
pi = make_purchase_invoice(item_name="_Test Item", qty=10, do_not_submit=True)
|
||||
pi.items[0].item_code = ""
|
||||
|
@ -421,7 +421,8 @@ class SalesInvoice(SellingController):
|
||||
self.calculate_taxes_and_totals()
|
||||
|
||||
def before_save(self):
|
||||
set_account_for_mode_of_payment(self)
|
||||
self.set_account_for_mode_of_payment()
|
||||
self.set_paid_amount()
|
||||
|
||||
def on_submit(self):
|
||||
self.validate_pos_paid_amount()
|
||||
@ -712,9 +713,6 @@ class SalesInvoice(SellingController):
|
||||
):
|
||||
data.sales_invoice = sales_invoice
|
||||
|
||||
def on_update(self):
|
||||
self.set_paid_amount()
|
||||
|
||||
def on_update_after_submit(self):
|
||||
if hasattr(self, "repost_required"):
|
||||
fields_to_check = [
|
||||
@ -745,6 +743,11 @@ class SalesInvoice(SellingController):
|
||||
self.paid_amount = paid_amount
|
||||
self.base_paid_amount = base_paid_amount
|
||||
|
||||
def set_account_for_mode_of_payment(self):
|
||||
for payment in self.payments:
|
||||
if not payment.account:
|
||||
payment.account = get_bank_cash_account(payment.mode_of_payment, self.company).get("account")
|
||||
|
||||
def validate_time_sheets_are_submitted(self):
|
||||
for data in self.timesheets:
|
||||
if data.time_sheet:
|
||||
@ -2113,12 +2116,6 @@ def make_sales_return(source_name, target_doc=None):
|
||||
return make_return_doc("Sales Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
def set_account_for_mode_of_payment(self):
|
||||
for data in self.payments:
|
||||
if not data.account:
|
||||
data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account")
|
||||
|
||||
|
||||
def get_inter_company_details(doc, doctype):
|
||||
if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"]:
|
||||
parties = frappe.db.get_all(
|
||||
|
@ -323,7 +323,8 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
si.insert()
|
||||
|
||||
# with inclusive tax
|
||||
self.assertEqual(si.items[0].net_amount, 3947.368421052631)
|
||||
self.assertEqual(si.items[0].net_amount, 3947.37)
|
||||
self.assertEqual(si.net_total, si.base_net_total)
|
||||
self.assertEqual(si.net_total, 3947.37)
|
||||
self.assertEqual(si.grand_total, 5000)
|
||||
|
||||
@ -667,7 +668,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
62.5,
|
||||
625.0,
|
||||
50,
|
||||
499.97600115194473,
|
||||
499.98,
|
||||
],
|
||||
"_Test Item Home Desktop 200": [
|
||||
190.66,
|
||||
@ -678,7 +679,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
190.66,
|
||||
953.3,
|
||||
150,
|
||||
749.9968530500239,
|
||||
750,
|
||||
],
|
||||
}
|
||||
|
||||
@ -691,20 +692,21 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
self.assertEqual(d.get(k), expected_values[d.item_code][i])
|
||||
|
||||
# check net total
|
||||
self.assertEqual(si.net_total, 1249.97)
|
||||
self.assertEqual(si.base_net_total, si.net_total)
|
||||
self.assertEqual(si.net_total, 1249.98)
|
||||
self.assertEqual(si.total, 1578.3)
|
||||
|
||||
# check tax calculation
|
||||
expected_values = {
|
||||
"keys": ["tax_amount", "total"],
|
||||
"_Test Account Excise Duty - _TC": [140, 1389.97],
|
||||
"_Test Account Education Cess - _TC": [2.8, 1392.77],
|
||||
"_Test Account S&H Education Cess - _TC": [1.4, 1394.17],
|
||||
"_Test Account CST - _TC": [27.88, 1422.05],
|
||||
"_Test Account VAT - _TC": [156.25, 1578.30],
|
||||
"_Test Account Customs Duty - _TC": [125, 1703.30],
|
||||
"_Test Account Shipping Charges - _TC": [100, 1803.30],
|
||||
"_Test Account Discount - _TC": [-180.33, 1622.97],
|
||||
"_Test Account Excise Duty - _TC": [140, 1389.98],
|
||||
"_Test Account Education Cess - _TC": [2.8, 1392.78],
|
||||
"_Test Account S&H Education Cess - _TC": [1.4, 1394.18],
|
||||
"_Test Account CST - _TC": [27.88, 1422.06],
|
||||
"_Test Account VAT - _TC": [156.25, 1578.31],
|
||||
"_Test Account Customs Duty - _TC": [125, 1703.31],
|
||||
"_Test Account Shipping Charges - _TC": [100, 1803.31],
|
||||
"_Test Account Discount - _TC": [-180.33, 1622.98],
|
||||
}
|
||||
|
||||
for d in si.get("taxes"):
|
||||
@ -740,7 +742,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
"base_rate": 2500,
|
||||
"base_amount": 25000,
|
||||
"net_rate": 40,
|
||||
"net_amount": 399.9808009215558,
|
||||
"net_amount": 399.98,
|
||||
"base_net_rate": 2000,
|
||||
"base_net_amount": 19999,
|
||||
},
|
||||
@ -754,7 +756,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
"base_rate": 7500,
|
||||
"base_amount": 37500,
|
||||
"net_rate": 118.01,
|
||||
"net_amount": 590.0531205155963,
|
||||
"net_amount": 590.05,
|
||||
"base_net_rate": 5900.5,
|
||||
"base_net_amount": 29502.5,
|
||||
},
|
||||
@ -792,8 +794,13 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
|
||||
self.assertEqual(si.base_grand_total, 60795)
|
||||
self.assertEqual(si.grand_total, 1215.90)
|
||||
self.assertEqual(si.rounding_adjustment, 0.01)
|
||||
self.assertEqual(si.base_rounding_adjustment, 0.50)
|
||||
# no rounding adjustment as the Smallest Currency Fraction Value of USD is 0.01
|
||||
if frappe.db.get_value("Currency", "USD", "smallest_currency_fraction_value") < 0.01:
|
||||
self.assertEqual(si.rounding_adjustment, 0.10)
|
||||
self.assertEqual(si.base_rounding_adjustment, 5.0)
|
||||
else:
|
||||
self.assertEqual(si.rounding_adjustment, 0.0)
|
||||
self.assertEqual(si.base_rounding_adjustment, 0.0)
|
||||
|
||||
def test_outstanding(self):
|
||||
w = self.make()
|
||||
@ -1543,6 +1550,19 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
self.assertEqual(frappe.db.get_value("Sales Invoice", si1.name, "outstanding_amount"), -1000)
|
||||
self.assertEqual(frappe.db.get_value("Sales Invoice", si.name, "outstanding_amount"), 2500)
|
||||
|
||||
def test_return_invoice_with_account_mismatch(self):
|
||||
debtors2 = create_account(
|
||||
parent_account="Accounts Receivable - _TC",
|
||||
account_name="Debtors 2",
|
||||
company="_Test Company",
|
||||
account_type="Receivable",
|
||||
)
|
||||
si = create_sales_invoice(qty=1, rate=1000)
|
||||
cr_note = create_sales_invoice(
|
||||
qty=-1, rate=1000, is_return=1, return_against=si.name, debit_to=debtors2, do_not_save=True
|
||||
)
|
||||
self.assertRaises(frappe.ValidationError, cr_note.save)
|
||||
|
||||
def test_gle_made_when_asset_is_returned(self):
|
||||
create_asset_data()
|
||||
asset = create_asset(item_code="Macbook Pro")
|
||||
@ -2082,7 +2102,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
|
||||
def test_rounding_adjustment_2(self):
|
||||
si = create_sales_invoice(rate=400, do_not_save=True)
|
||||
for rate in [400, 600, 100]:
|
||||
for rate in [400.25, 600.30, 100.65]:
|
||||
si.append(
|
||||
"items",
|
||||
{
|
||||
@ -2108,17 +2128,18 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
)
|
||||
si.save()
|
||||
si.submit()
|
||||
self.assertEqual(si.net_total, 1271.19)
|
||||
self.assertEqual(si.grand_total, 1500)
|
||||
self.assertEqual(si.total_taxes_and_charges, 228.82)
|
||||
self.assertEqual(si.rounding_adjustment, -0.01)
|
||||
self.assertEqual(si.net_total, si.base_net_total)
|
||||
self.assertEqual(si.net_total, 1272.20)
|
||||
self.assertEqual(si.grand_total, 1501.20)
|
||||
self.assertEqual(si.total_taxes_and_charges, 229)
|
||||
self.assertEqual(si.rounding_adjustment, -0.20)
|
||||
|
||||
expected_values = [
|
||||
["_Test Account Service Tax - _TC", 0.0, 114.41],
|
||||
["_Test Account VAT - _TC", 0.0, 114.41],
|
||||
[si.debit_to, 1500, 0.0],
|
||||
["Round Off - _TC", 0.01, 0.01],
|
||||
["Sales - _TC", 0.0, 1271.18],
|
||||
["_Test Account Service Tax - _TC", 0.0, 114.50],
|
||||
["_Test Account VAT - _TC", 0.0, 114.50],
|
||||
[si.debit_to, 1501, 0.0],
|
||||
["Round Off - _TC", 0.20, 0.0],
|
||||
["Sales - _TC", 0.0, 1272.20],
|
||||
]
|
||||
|
||||
gl_entries = frappe.db.sql(
|
||||
@ -2176,7 +2197,8 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
|
||||
si.save()
|
||||
si.submit()
|
||||
self.assertEqual(si.net_total, 4007.16)
|
||||
self.assertEqual(si.net_total, si.base_net_total)
|
||||
self.assertEqual(si.net_total, 4007.15)
|
||||
self.assertEqual(si.grand_total, 4488.02)
|
||||
self.assertEqual(si.total_taxes_and_charges, 480.86)
|
||||
self.assertEqual(si.rounding_adjustment, -0.02)
|
||||
@ -2188,7 +2210,7 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
["_Test Account Service Tax - _TC", 0.0, 240.43],
|
||||
["_Test Account VAT - _TC", 0.0, 240.43],
|
||||
["Sales - _TC", 0.0, 4007.15],
|
||||
["Round Off - _TC", 0.02, 0.01],
|
||||
["Round Off - _TC", 0.01, 0.0],
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "\nTrialling\nActive\nPast Due Date\nCancelled\nUnpaid\nCompleted",
|
||||
"options": "\nTrialing\nActive\nPast Due Date\nCancelled\nUnpaid\nCompleted",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
@ -267,7 +267,7 @@
|
||||
"link_fieldname": "subscription"
|
||||
}
|
||||
],
|
||||
"modified": "2023-12-28 17:20:42.687789",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Subscription",
|
||||
|
@ -78,9 +78,7 @@ class Subscription(Document):
|
||||
purchase_tax_template: DF.Link | None
|
||||
sales_tax_template: DF.Link | None
|
||||
start_date: DF.Date | None
|
||||
status: DF.Literal[
|
||||
"", "Trialling", "Active", "Past Due Date", "Cancelled", "Unpaid", "Completed"
|
||||
]
|
||||
status: DF.Literal["", "Trialing", "Active", "Past Due Date", "Cancelled", "Unpaid", "Completed"]
|
||||
submit_invoice: DF.Check
|
||||
trial_period_end: DF.Date | None
|
||||
trial_period_start: DF.Date | None
|
||||
@ -233,7 +231,7 @@ class Subscription(Document):
|
||||
Sets the status of the `Subscription`
|
||||
"""
|
||||
if self.is_trialling():
|
||||
self.status = "Trialling"
|
||||
self.status = "Trialing"
|
||||
elif (
|
||||
self.status == "Active" and self.end_date and getdate(posting_date) > getdate(self.end_date)
|
||||
):
|
||||
|
@ -1,7 +1,7 @@
|
||||
frappe.listview_settings['Subscription'] = {
|
||||
get_indicator: function(doc) {
|
||||
if(doc.status === 'Trialling') {
|
||||
return [__("Trialling"), "green"];
|
||||
if(doc.status === 'Trialing') {
|
||||
return [__("Trialing"), "green"];
|
||||
} else if(doc.status === 'Active') {
|
||||
return [__("Active"), "green"];
|
||||
} else if(doc.status === 'Completed') {
|
||||
|
@ -46,7 +46,7 @@ class TestSubscription(FrappeTestCase):
|
||||
get_date_str(subscription.current_invoice_end),
|
||||
)
|
||||
self.assertEqual(subscription.invoices, [])
|
||||
self.assertEqual(subscription.status, "Trialling")
|
||||
self.assertEqual(subscription.status, "Trialing")
|
||||
|
||||
def test_create_subscription_without_trial_with_correct_period(self):
|
||||
subscription = create_subscription()
|
||||
|
@ -4,7 +4,7 @@
|
||||
"doctype": "Form Tour",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"modified": "2021-06-29 17:00:26.145996",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
@ -82,7 +82,7 @@
|
||||
"label": "Accounts Frozen Till Date",
|
||||
"parent_field": "",
|
||||
"position": "Right",
|
||||
"title": "Accounts Frozen Upto"
|
||||
"title": "Accounts Frozen Up To"
|
||||
},
|
||||
{
|
||||
"description": "Users with this Role are allowed to set frozen accounts and create/modify accounting entries against frozen accounts.",
|
||||
|
@ -39,7 +39,7 @@ frappe.query_reports["Account Balance"] = {
|
||||
{ "value": "Asset Received But Not Billed", "label": __("Asset Received But Not Billed") },
|
||||
{ "value": "Bank", "label": __("Bank") },
|
||||
{ "value": "Cash", "label": __("Cash") },
|
||||
{ "value": "Chargeble", "label": __("Chargeble") },
|
||||
{ "value": "Chargeable", "label": __("Chargeable") },
|
||||
{ "value": "Capital Work in Progress", "label": __("Capital Work in Progress") },
|
||||
{ "value": "Cost of Goods Sold", "label": __("Cost of Goods Sold") },
|
||||
{ "value": "Depreciation", "label": __("Depreciation") },
|
||||
|
@ -5,7 +5,7 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
import frappe
|
||||
from frappe import _, qb, scrub
|
||||
from frappe import _, qb, query_builder, scrub
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import Date, Substring, Sum
|
||||
from frappe.utils import cint, cstr, flt, getdate, nowdate
|
||||
@ -576,6 +576,8 @@ class ReceivablePayableReport(object):
|
||||
def get_future_payments_from_payment_entry(self):
|
||||
pe = frappe.qb.DocType("Payment Entry")
|
||||
pe_ref = frappe.qb.DocType("Payment Entry Reference")
|
||||
ifelse = query_builder.CustomFunction("IF", ["condition", "then", "else"])
|
||||
|
||||
return (
|
||||
frappe.qb.from_(pe)
|
||||
.inner_join(pe_ref)
|
||||
@ -587,6 +589,11 @@ class ReceivablePayableReport(object):
|
||||
(pe.posting_date).as_("future_date"),
|
||||
(pe_ref.allocated_amount).as_("future_amount"),
|
||||
(pe.reference_no).as_("future_ref"),
|
||||
ifelse(
|
||||
pe.payment_type == "Receive",
|
||||
pe.source_exchange_rate * pe_ref.allocated_amount,
|
||||
pe.target_exchange_rate * pe_ref.allocated_amount,
|
||||
).as_("future_amount_in_base_currency"),
|
||||
)
|
||||
.where(
|
||||
(pe.docstatus < 2)
|
||||
@ -623,13 +630,24 @@ class ReceivablePayableReport(object):
|
||||
query = query.select(
|
||||
Sum(jea.debit_in_account_currency - jea.credit_in_account_currency).as_("future_amount")
|
||||
)
|
||||
query = query.select(Sum(jea.debit - jea.credit).as_("future_amount_in_base_currency"))
|
||||
else:
|
||||
query = query.select(
|
||||
Sum(jea.credit_in_account_currency - jea.debit_in_account_currency).as_("future_amount")
|
||||
)
|
||||
query = query.select(Sum(jea.credit - jea.debit).as_("future_amount_in_base_currency"))
|
||||
else:
|
||||
query = query.select(
|
||||
Sum(jea.debit if self.account_type == "Payable" else jea.credit).as_("future_amount")
|
||||
Sum(jea.debit if self.account_type == "Payable" else jea.credit).as_(
|
||||
"future_amount_in_base_currency"
|
||||
)
|
||||
)
|
||||
query = query.select(
|
||||
Sum(
|
||||
jea.debit_in_account_currency
|
||||
if self.account_type == "Payable"
|
||||
else jea.credit_in_account_currency
|
||||
).as_("future_amount")
|
||||
)
|
||||
|
||||
query = query.having(qb.Field("future_amount") > 0)
|
||||
@ -645,14 +663,19 @@ class ReceivablePayableReport(object):
|
||||
row.remaining_balance = row.outstanding
|
||||
row.future_amount = 0.0
|
||||
for future in self.future_payments.get((row.voucher_no, row.party), []):
|
||||
if row.remaining_balance > 0 and future.future_amount:
|
||||
if future.future_amount > row.outstanding:
|
||||
if self.filters.in_party_currency:
|
||||
future_amount_field = "future_amount"
|
||||
else:
|
||||
future_amount_field = "future_amount_in_base_currency"
|
||||
|
||||
if row.remaining_balance > 0 and future.get(future_amount_field):
|
||||
if future.get(future_amount_field) > row.outstanding:
|
||||
row.future_amount = row.outstanding
|
||||
future.future_amount = future.future_amount - row.outstanding
|
||||
future[future_amount_field] = future.get(future_amount_field) - row.outstanding
|
||||
row.remaining_balance = 0
|
||||
else:
|
||||
row.future_amount += future.future_amount
|
||||
future.future_amount = 0
|
||||
row.future_amount += future.get(future_amount_field)
|
||||
future[future_amount_field] = 0
|
||||
row.remaining_balance = row.outstanding - row.future_amount
|
||||
|
||||
row.setdefault("future_ref", []).append(
|
||||
|
@ -772,3 +772,92 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
# post sorting output should be [[Additional Debtors, ...], [Debtors, ...]]
|
||||
report_output = sorted(report_output, key=lambda x: x[0])
|
||||
self.assertEqual(expected_data, report_output)
|
||||
|
||||
def test_future_payments_on_foreign_currency(self):
|
||||
self.customer2 = (
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Customer",
|
||||
"customer_name": "Jane Doe",
|
||||
"type": "Individual",
|
||||
"default_currency": "USD",
|
||||
}
|
||||
)
|
||||
.insert()
|
||||
.submit()
|
||||
)
|
||||
|
||||
si = self.create_sales_invoice(do_not_submit=True)
|
||||
si.posting_date = add_days(today(), -1)
|
||||
si.customer = self.customer2
|
||||
si.currency = "USD"
|
||||
si.conversion_rate = 80
|
||||
si.debit_to = self.debtors_usd
|
||||
si.save().submit()
|
||||
|
||||
# full payment in USD
|
||||
pe = get_payment_entry(si.doctype, si.name)
|
||||
pe.posting_date = add_days(today(), 1)
|
||||
pe.base_received_amount = 7500
|
||||
pe.received_amount = 7500
|
||||
pe.source_exchange_rate = 75
|
||||
pe.save().submit()
|
||||
|
||||
filters = frappe._dict(
|
||||
{
|
||||
"company": self.company,
|
||||
"report_date": today(),
|
||||
"range1": 30,
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"show_future_payments": True,
|
||||
"in_party_currency": False,
|
||||
}
|
||||
)
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 1)
|
||||
|
||||
expected_data = [8000.0, 8000.0, 500.0, 7500.0]
|
||||
row = report[0]
|
||||
self.assertEqual(
|
||||
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
|
||||
)
|
||||
|
||||
filters.in_party_currency = True
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 1)
|
||||
expected_data = [100.0, 100.0, 0.0, 100.0]
|
||||
row = report[0]
|
||||
self.assertEqual(
|
||||
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
|
||||
)
|
||||
|
||||
pe.cancel()
|
||||
# partial payment in USD on a future date
|
||||
pe = get_payment_entry(si.doctype, si.name)
|
||||
pe.posting_date = add_days(today(), 1)
|
||||
pe.base_received_amount = 6750
|
||||
pe.received_amount = 6750
|
||||
pe.source_exchange_rate = 75
|
||||
pe.paid_amount = 90 # in USD
|
||||
pe.references[0].allocated_amount = 90
|
||||
pe.save().submit()
|
||||
|
||||
filters.in_party_currency = False
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 1)
|
||||
expected_data = [8000.0, 8000.0, 1250.0, 6750.0]
|
||||
row = report[0]
|
||||
self.assertEqual(
|
||||
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
|
||||
)
|
||||
|
||||
filters.in_party_currency = True
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 1)
|
||||
expected_data = [100.0, 100.0, 10.0, 90.0]
|
||||
row = report[0]
|
||||
self.assertEqual(
|
||||
expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount]
|
||||
)
|
||||
|
@ -8,6 +8,20 @@ frappe.query_reports["Balance Sheet"] = $.extend(
|
||||
|
||||
erpnext.utils.add_dimensions("Balance Sheet", 10);
|
||||
|
||||
frappe.query_reports["Balance Sheet"]["filters"].push(
|
||||
{
|
||||
"fieldname": "selected_view",
|
||||
"label": __("Select View"),
|
||||
"fieldtype": "Select",
|
||||
"options": [
|
||||
{ "value": "Report", "label": __("Report View") },
|
||||
{ "value": "Growth", "label": __("Growth View") }
|
||||
],
|
||||
"default": "Report",
|
||||
"reqd": 1
|
||||
},
|
||||
);
|
||||
|
||||
frappe.query_reports["Balance Sheet"]["filters"].push({
|
||||
fieldname: "accumulated_values",
|
||||
label: __("Accumulated Values"),
|
||||
|
@ -8,6 +8,21 @@ frappe.query_reports["Profit and Loss Statement"] = $.extend(
|
||||
|
||||
erpnext.utils.add_dimensions("Profit and Loss Statement", 10);
|
||||
|
||||
frappe.query_reports["Profit and Loss Statement"]["filters"].push(
|
||||
{
|
||||
"fieldname": "selected_view",
|
||||
"label": __("Select View"),
|
||||
"fieldtype": "Select",
|
||||
"options": [
|
||||
{ "value": "Report", "label": __("Report View") },
|
||||
{ "value": "Growth", "label": __("Growth View") },
|
||||
{ "value": "Margin", "label": __("Margin View") },
|
||||
],
|
||||
"default": "Report",
|
||||
"reqd": 1
|
||||
},
|
||||
);
|
||||
|
||||
frappe.query_reports["Profit and Loss Statement"]["filters"].push({
|
||||
fieldname: "accumulated_values",
|
||||
label: __("Accumulated Values"),
|
||||
|
@ -240,7 +240,6 @@ def get_balance_on(
|
||||
cond.append("""gle.cost_center = %s """ % (frappe.db.escape(cost_center, percent=False),))
|
||||
|
||||
if account:
|
||||
|
||||
if not (frappe.flags.ignore_account_permission or ignore_account_permission):
|
||||
acc.check_permission("read")
|
||||
|
||||
@ -286,18 +285,22 @@ def get_balance_on(
|
||||
cond.append("""gle.company = %s """ % (frappe.db.escape(company, percent=False)))
|
||||
|
||||
if account or (party_type and party) or account_type:
|
||||
|
||||
precision = get_currency_precision()
|
||||
if in_account_currency:
|
||||
select_field = "sum(debit_in_account_currency) - sum(credit_in_account_currency)"
|
||||
select_field = (
|
||||
"sum(round(debit_in_account_currency, %s)) - sum(round(credit_in_account_currency, %s))"
|
||||
)
|
||||
else:
|
||||
select_field = "sum(debit) - sum(credit)"
|
||||
select_field = "sum(round(debit, %s)) - sum(round(credit, %s))"
|
||||
|
||||
bal = frappe.db.sql(
|
||||
"""
|
||||
SELECT {0}
|
||||
FROM `tabGL Entry` gle
|
||||
WHERE {1}""".format(
|
||||
select_field, " and ".join(cond)
|
||||
)
|
||||
),
|
||||
(precision, precision),
|
||||
)[0][0]
|
||||
# if bal is None, return 0
|
||||
return flt(bal)
|
||||
@ -619,8 +622,8 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
|
||||
|
||||
# Update Advance Paid in SO/PO since they might be getting unlinked
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
if jv_detail.get("reference_type") in advance_payment_doctypes:
|
||||
frappe.get_doc(jv_detail.reference_type, jv_detail.reference_name).set_total_advance_paid()
|
||||
|
||||
@ -696,8 +699,8 @@ def update_reference_in_payment_entry(
|
||||
|
||||
# Update Advance Paid in SO/PO since they are getting unlinked
|
||||
advance_payment_doctypes = frappe.get_hooks(
|
||||
"advance_payment_customer_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_supplier_doctypes")
|
||||
"advance_payment_receivable_doctypes"
|
||||
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||
if existing_row.get("reference_doctype") in advance_payment_doctypes:
|
||||
frappe.get_doc(
|
||||
existing_row.reference_doctype, existing_row.reference_name
|
||||
|
@ -571,16 +571,16 @@ frappe.ui.form.on('Asset', {
|
||||
indicator: 'red'
|
||||
});
|
||||
}
|
||||
var is_grouped_asset = frappe.db.get_value('Item', item.item_code, 'is_grouped_asset');
|
||||
var asset_quantity = is_grouped_asset ? item.qty : 1;
|
||||
var purchase_amount = flt(item.valuation_rate * asset_quantity, precision('gross_purchase_amount'));
|
||||
|
||||
frm.set_value('gross_purchase_amount', purchase_amount);
|
||||
frm.set_value('purchase_receipt_amount', purchase_amount);
|
||||
frm.set_value('asset_quantity', asset_quantity);
|
||||
frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center);
|
||||
if(item.asset_location) { frm.set_value('location', item.asset_location); }
|
||||
frappe.db.get_value('Item', item.item_code, 'is_grouped_asset', (r) => {
|
||||
var asset_quantity = r.is_grouped_asset ? item.qty : 1;
|
||||
var purchase_amount = flt(item.valuation_rate * asset_quantity, precision('gross_purchase_amount'));
|
||||
|
||||
frm.set_value('gross_purchase_amount', purchase_amount);
|
||||
frm.set_value('purchase_receipt_amount', purchase_amount);
|
||||
frm.set_value('asset_quantity', asset_quantity);
|
||||
frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center);
|
||||
if(item.asset_location) { frm.set_value('location', item.asset_location); }
|
||||
});
|
||||
},
|
||||
|
||||
set_depreciation_rate: function(frm, row) {
|
||||
|
@ -519,14 +519,11 @@ class Asset(AccountsController):
|
||||
movement.cancel()
|
||||
|
||||
def cancel_capitalization(self):
|
||||
asset_capitalization = frappe.db.get_value(
|
||||
"Asset Capitalization",
|
||||
{"target_asset": self.name, "docstatus": 1, "entry_type": "Capitalization"},
|
||||
)
|
||||
|
||||
if asset_capitalization:
|
||||
asset_capitalization = frappe.get_doc("Asset Capitalization", asset_capitalization)
|
||||
asset_capitalization.cancel()
|
||||
if self.capitalized_in:
|
||||
self.db_set("capitalized_in", None)
|
||||
asset_capitalization = frappe.get_doc("Asset Capitalization", self.capitalized_in)
|
||||
if asset_capitalization.docstatus == 1:
|
||||
asset_capitalization.cancel()
|
||||
|
||||
def delete_depreciation_entries(self):
|
||||
if self.calculate_depreciation:
|
||||
@ -1011,7 +1008,7 @@ def make_asset_movement(assets, purpose=None):
|
||||
assets = json.loads(assets)
|
||||
|
||||
if len(assets) == 0:
|
||||
frappe.throw(_("Atleast one asset has to be selected."))
|
||||
frappe.throw(_("At least one asset has to be selected."))
|
||||
|
||||
asset_movement = frappe.new_doc("Asset Movement")
|
||||
asset_movement.quantity = len(assets)
|
||||
|
@ -561,6 +561,8 @@ def modify_depreciation_schedule_for_asset_repairs(asset, notes):
|
||||
def reverse_depreciation_entry_made_after_disposal(asset, date):
|
||||
for row in asset.get("finance_books"):
|
||||
asset_depr_schedule_doc = get_asset_depr_schedule_doc(asset.name, "Active", row.finance_book)
|
||||
if not asset_depr_schedule_doc:
|
||||
continue
|
||||
|
||||
for schedule_idx, schedule in enumerate(asset_depr_schedule_doc.get("depreciation_schedule")):
|
||||
if schedule.schedule_date == date:
|
||||
|
@ -146,6 +146,7 @@ class AssetCapitalization(StockController):
|
||||
def cancel_target_asset(self):
|
||||
if self.entry_type == "Capitalization" and self.target_asset:
|
||||
asset_doc = frappe.get_doc("Asset", self.target_asset)
|
||||
frappe.db.set_value("Asset", self.target_asset, "capitalized_in", None)
|
||||
if asset_doc.docstatus == 1:
|
||||
asset_doc.cancel()
|
||||
|
||||
|
@ -40,7 +40,7 @@ class AssetMaintenance(Document):
|
||||
if getdate(task.next_due_date) < getdate(nowdate()):
|
||||
task.maintenance_status = "Overdue"
|
||||
if not task.assign_to and self.docstatus == 0:
|
||||
throw(_("Row #{}: Please asign task to a member.").format(task.idx))
|
||||
throw(_("Row #{}: Please assign task to a member.").format(task.idx))
|
||||
|
||||
def on_update(self):
|
||||
for task in self.get("asset_maintenance_tasks"):
|
||||
|
@ -2,14 +2,14 @@
|
||||
"action": "Show Form Tour",
|
||||
"action_label": "Let's review existing Asset Category",
|
||||
"creation": "2021-08-13 14:26:18.656303",
|
||||
"description": "# Asset Category\n\nAn Asset Category classifies different assets of a Company.\n\nYou can create an Asset Category based on the type of assets. For example, all your desktops and laptops can be part of an Asset Category named \"Electronic Equipments\". Create a separate category for furniture. Also, you can update default properties for each category, like:\n - Depreciation type and duration\n - Fixed asset account\n - Depreciation account\n",
|
||||
"description": "# Asset Category\n\nAn Asset Category classifies different assets of a Company.\n\nYou can create an Asset Category based on the type of assets. For example, all your desktops and laptops can be part of an Asset Category named \"Electronic Equipment\". Create a separate category for furniture. Also, you can update default properties for each category, like:\n - Depreciation type and duration\n - Fixed asset account\n - Depreciation account\n",
|
||||
"docstatus": 0,
|
||||
"doctype": "Onboarding Step",
|
||||
"idx": 0,
|
||||
"is_complete": 0,
|
||||
"is_single": 0,
|
||||
"is_skipped": 0,
|
||||
"modified": "2021-11-23 10:02:03.242127",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"name": "Asset Category",
|
||||
"owner": "Administrator",
|
||||
|
@ -202,7 +202,7 @@ def prepare_chart_data(data, filters):
|
||||
"values": [flt(d.get("asset_value"), 2) for d in labels_values_map.values()],
|
||||
},
|
||||
{
|
||||
"name": _("Depreciatied Amount"),
|
||||
"name": _("Depreciated Amount"),
|
||||
"values": [flt(d.get("depreciated_amount"), 2) for d in labels_values_map.values()],
|
||||
},
|
||||
],
|
||||
|
@ -22,6 +22,7 @@ from frappe.utils import (
|
||||
get_link_to_form,
|
||||
getdate,
|
||||
nowdate,
|
||||
parse_json,
|
||||
today,
|
||||
)
|
||||
|
||||
@ -201,6 +202,7 @@ class AccountsController(TransactionBase):
|
||||
self.validate_party()
|
||||
self.validate_currency()
|
||||
self.validate_party_account_currency()
|
||||
self.validate_return_against_account()
|
||||
|
||||
if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
|
||||
if invalid_advances := [
|
||||
@ -349,6 +351,20 @@ class AccountsController(TransactionBase):
|
||||
for bundle in bundles:
|
||||
frappe.delete_doc("Serial and Batch Bundle", bundle.name)
|
||||
|
||||
def validate_return_against_account(self):
|
||||
if (
|
||||
self.doctype in ["Sales Invoice", "Purchase Invoice"] and self.is_return and self.return_against
|
||||
):
|
||||
cr_dr_account_field = "debit_to" if self.doctype == "Sales Invoice" else "credit_to"
|
||||
cr_dr_account_label = "Debit To" if self.doctype == "Sales Invoice" else "Credit To"
|
||||
cr_dr_account = self.get(cr_dr_account_field)
|
||||
if frappe.get_value(self.doctype, self.return_against, cr_dr_account_field) != cr_dr_account:
|
||||
frappe.throw(
|
||||
_("'{0}' account: '{1}' should match the Return Against Invoice").format(
|
||||
frappe.bold(cr_dr_account_label), frappe.bold(cr_dr_account)
|
||||
)
|
||||
)
|
||||
|
||||
def validate_deferred_income_expense_account(self):
|
||||
field_map = {
|
||||
"Sales Invoice": "deferred_revenue_account",
|
||||
@ -833,6 +849,37 @@ class AccountsController(TransactionBase):
|
||||
|
||||
self.extend("taxes", get_taxes_and_charges(tax_master_doctype, self.get("taxes_and_charges")))
|
||||
|
||||
def append_taxes_from_item_tax_template(self):
|
||||
if not frappe.db.get_single_value("Accounts Settings", "add_taxes_from_item_tax_template"):
|
||||
return
|
||||
|
||||
for row in self.items:
|
||||
item_tax_rate = row.get("item_tax_rate")
|
||||
if not item_tax_rate:
|
||||
continue
|
||||
|
||||
if isinstance(item_tax_rate, str):
|
||||
item_tax_rate = parse_json(item_tax_rate)
|
||||
|
||||
for account_head, rate in item_tax_rate.items():
|
||||
row = self.get_tax_row(account_head)
|
||||
|
||||
if not row:
|
||||
self.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": account_head,
|
||||
"rate": 0,
|
||||
"description": account_head,
|
||||
},
|
||||
)
|
||||
|
||||
def get_tax_row(self, account_head):
|
||||
for row in self.taxes:
|
||||
if row.account_head == account_head:
|
||||
return row
|
||||
|
||||
def set_other_charges(self):
|
||||
self.set("taxes", [])
|
||||
self.set_taxes()
|
||||
@ -1761,9 +1808,9 @@ class AccountsController(TransactionBase):
|
||||
|
||||
def set_total_advance_paid(self):
|
||||
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||
if self.doctype in frappe.get_hooks("advance_payment_customer_doctypes"):
|
||||
if self.doctype in frappe.get_hooks("advance_payment_receivable_doctypes"):
|
||||
party = self.customer
|
||||
if self.doctype in frappe.get_hooks("advance_payment_supplier_doctypes"):
|
||||
if self.doctype in frappe.get_hooks("advance_payment_payable_doctypes"):
|
||||
party = self.supplier
|
||||
advance = (
|
||||
frappe.qb.from_(ple)
|
||||
@ -1829,9 +1876,9 @@ class AccountsController(TransactionBase):
|
||||
"docstatus": 1,
|
||||
},
|
||||
)
|
||||
if self.doctype in frappe.get_hooks("advance_payment_customer_doctypes"):
|
||||
if self.doctype in frappe.get_hooks("advance_payment_receivable_doctypes"):
|
||||
new_status = "Requested" if prs else "Not Requested"
|
||||
if self.doctype in frappe.get_hooks("advance_payment_supplier_doctypes"):
|
||||
if self.doctype in frappe.get_hooks("advance_payment_payable_doctypes"):
|
||||
new_status = "Initiated" if prs else "Not Initiated"
|
||||
|
||||
if new_status == self.advance_payment_status:
|
||||
|
@ -141,7 +141,7 @@ def validate_returned_items(doc):
|
||||
items_returned = True
|
||||
|
||||
if not items_returned:
|
||||
frappe.throw(_("Atleast one item should be entered with negative quantity in return document"))
|
||||
frappe.throw(_("At least one item should be entered with negative quantity in return document"))
|
||||
|
||||
|
||||
def validate_quantity(doc, args, ref, valid_items, already_returned_items):
|
||||
|
@ -99,7 +99,8 @@ status_map = {
|
||||
],
|
||||
"Purchase Receipt": [
|
||||
["Draft", None],
|
||||
["To Bill", "eval:self.per_billed < 100 and self.docstatus == 1"],
|
||||
["To Bill", "eval:self.per_billed == 0 and self.docstatus == 1"],
|
||||
["Partly Billed", "eval:self.per_billed > 0 and self.per_billed < 100 and self.docstatus == 1"],
|
||||
["Return Issued", "eval:self.per_returned == 100 and self.docstatus == 1"],
|
||||
["Completed", "eval:self.per_billed == 100 and self.docstatus == 1"],
|
||||
["Cancelled", "eval:self.docstatus==2"],
|
||||
|
@ -6,7 +6,7 @@ from collections import defaultdict
|
||||
from typing import List, Tuple
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe import _, bold
|
||||
from frappe.utils import cint, flt, get_link_to_form, getdate
|
||||
|
||||
import erpnext
|
||||
@ -697,6 +697,9 @@ class StockController(AccountsController):
|
||||
self.validate_in_transit_warehouses()
|
||||
self.validate_multi_currency()
|
||||
self.validate_packed_items()
|
||||
|
||||
if self.get("is_internal_supplier"):
|
||||
self.validate_internal_transfer_qty()
|
||||
else:
|
||||
self.validate_internal_transfer_warehouse()
|
||||
|
||||
@ -735,6 +738,116 @@ class StockController(AccountsController):
|
||||
if self.doctype in ("Sales Invoice", "Delivery Note Item") and self.get("packed_items"):
|
||||
frappe.throw(_("Packed Items cannot be transferred internally"))
|
||||
|
||||
def validate_internal_transfer_qty(self):
|
||||
if self.doctype not in ["Purchase Invoice", "Purchase Receipt"]:
|
||||
return
|
||||
|
||||
item_wise_transfer_qty = self.get_item_wise_inter_transfer_qty()
|
||||
if not item_wise_transfer_qty:
|
||||
return
|
||||
|
||||
item_wise_received_qty = self.get_item_wise_inter_received_qty()
|
||||
precision = frappe.get_precision(self.doctype + " Item", "qty")
|
||||
|
||||
over_receipt_allowance = frappe.db.get_single_value(
|
||||
"Stock Settings", "over_delivery_receipt_allowance"
|
||||
)
|
||||
|
||||
parent_doctype = {
|
||||
"Purchase Receipt": "Delivery Note",
|
||||
"Purchase Invoice": "Sales Invoice",
|
||||
}.get(self.doctype)
|
||||
|
||||
for key, transferred_qty in item_wise_transfer_qty.items():
|
||||
recevied_qty = flt(item_wise_received_qty.get(key), precision)
|
||||
if over_receipt_allowance:
|
||||
transferred_qty = transferred_qty + flt(
|
||||
transferred_qty * over_receipt_allowance / 100, precision
|
||||
)
|
||||
|
||||
if recevied_qty > flt(transferred_qty, precision):
|
||||
frappe.throw(
|
||||
_("For Item {0} cannot be received more than {1} qty against the {2} {3}").format(
|
||||
bold(key[1]),
|
||||
bold(flt(transferred_qty, precision)),
|
||||
bold(parent_doctype),
|
||||
get_link_to_form(parent_doctype, self.get("inter_company_reference")),
|
||||
)
|
||||
)
|
||||
|
||||
def get_item_wise_inter_transfer_qty(self):
|
||||
reference_field = "inter_company_reference"
|
||||
if self.doctype == "Purchase Invoice":
|
||||
reference_field = "inter_company_invoice_reference"
|
||||
|
||||
parent_doctype = {
|
||||
"Purchase Receipt": "Delivery Note",
|
||||
"Purchase Invoice": "Sales Invoice",
|
||||
}.get(self.doctype)
|
||||
|
||||
child_doctype = parent_doctype + " Item"
|
||||
|
||||
parent_tab = frappe.qb.DocType(parent_doctype)
|
||||
child_tab = frappe.qb.DocType(child_doctype)
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(parent_doctype)
|
||||
.inner_join(child_tab)
|
||||
.on(child_tab.parent == parent_tab.name)
|
||||
.select(
|
||||
child_tab.name,
|
||||
child_tab.item_code,
|
||||
child_tab.qty,
|
||||
)
|
||||
.where((parent_tab.name == self.get(reference_field)) & (parent_tab.docstatus == 1))
|
||||
)
|
||||
|
||||
data = query.run(as_dict=True)
|
||||
item_wise_transfer_qty = defaultdict(float)
|
||||
for row in data:
|
||||
item_wise_transfer_qty[(row.name, row.item_code)] += flt(row.qty)
|
||||
|
||||
return item_wise_transfer_qty
|
||||
|
||||
def get_item_wise_inter_received_qty(self):
|
||||
child_doctype = self.doctype + " Item"
|
||||
|
||||
parent_tab = frappe.qb.DocType(self.doctype)
|
||||
child_tab = frappe.qb.DocType(child_doctype)
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(self.doctype)
|
||||
.inner_join(child_tab)
|
||||
.on(child_tab.parent == parent_tab.name)
|
||||
.select(
|
||||
child_tab.item_code,
|
||||
child_tab.qty,
|
||||
)
|
||||
.where(parent_tab.docstatus < 2)
|
||||
)
|
||||
|
||||
if self.doctype == "Purchase Invoice":
|
||||
query = query.select(
|
||||
child_tab.sales_invoice_item.as_("name"),
|
||||
)
|
||||
|
||||
query = query.where(
|
||||
parent_tab.inter_company_invoice_reference == self.inter_company_invoice_reference
|
||||
)
|
||||
else:
|
||||
query = query.select(
|
||||
child_tab.delivery_note_item.as_("name"),
|
||||
)
|
||||
|
||||
query = query.where(parent_tab.inter_company_reference == self.inter_company_reference)
|
||||
|
||||
data = query.run(as_dict=True)
|
||||
item_wise_transfer_qty = defaultdict(float)
|
||||
for row in data:
|
||||
item_wise_transfer_qty[(row.name, row.item_code)] += flt(row.qty)
|
||||
|
||||
return item_wise_transfer_qty
|
||||
|
||||
def validate_putaway_capacity(self):
|
||||
# if over receipt is attempted while 'apply putaway rule' is disabled
|
||||
# and if rule was applied on the transaction, validate it.
|
||||
|
@ -260,18 +260,22 @@ class SubcontractingController(StockController):
|
||||
return frappe.get_all(f"{doctype}", fields=fields, filters=filters)
|
||||
|
||||
def __get_consumed_items(self, doctype, receipt_items):
|
||||
fields = [
|
||||
"serial_no",
|
||||
"rm_item_code",
|
||||
"reference_name",
|
||||
"batch_no",
|
||||
"consumed_qty",
|
||||
"main_item_code",
|
||||
"parent as voucher_no",
|
||||
]
|
||||
|
||||
if self.subcontract_data.receipt_supplied_items_field != "Purchase Receipt Item Supplied":
|
||||
fields.append("serial_and_batch_bundle")
|
||||
|
||||
return frappe.get_all(
|
||||
self.subcontract_data.receipt_supplied_items_field,
|
||||
fields=[
|
||||
"serial_no",
|
||||
"rm_item_code",
|
||||
"reference_name",
|
||||
"serial_and_batch_bundle",
|
||||
"batch_no",
|
||||
"consumed_qty",
|
||||
"main_item_code",
|
||||
"parent as voucher_no",
|
||||
],
|
||||
fields=fields,
|
||||
filters={"docstatus": 1, "reference_name": ("in", list(receipt_items)), "parenttype": doctype},
|
||||
)
|
||||
|
||||
@ -881,7 +885,9 @@ class SubcontractingController(StockController):
|
||||
"posting_time": self.posting_time,
|
||||
"qty": -1 * item.consumed_qty,
|
||||
"voucher_detail_no": item.name,
|
||||
"serial_and_batch_bundle": item.serial_and_batch_bundle,
|
||||
"serial_and_batch_bundle": item.get("serial_and_batch_bundle"),
|
||||
"serial_no": item.get("serial_no"),
|
||||
"batch_no": item.get("batch_no"),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -8,6 +8,7 @@ import frappe
|
||||
from frappe import _, scrub
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint, flt, round_based_on_smallest_currency_fraction
|
||||
from frappe.utils.deprecations import deprecated
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
|
||||
@ -74,7 +75,7 @@ class calculate_taxes_and_totals(object):
|
||||
self.calculate_net_total()
|
||||
self.calculate_tax_withholding_net_total()
|
||||
self.calculate_taxes()
|
||||
self.manipulate_grand_total_for_inclusive_tax()
|
||||
self.adjust_grand_total_for_inclusive_tax()
|
||||
self.calculate_totals()
|
||||
self._cleanup()
|
||||
self.calculate_total_net_weight()
|
||||
@ -279,7 +280,7 @@ class calculate_taxes_and_totals(object):
|
||||
):
|
||||
amount = flt(item.amount) - total_inclusive_tax_amount_per_qty
|
||||
|
||||
item.net_amount = flt(amount / (1 + cumulated_tax_fraction))
|
||||
item.net_amount = flt(amount / (1 + cumulated_tax_fraction), item.precision("net_amount"))
|
||||
item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
|
||||
item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage"))
|
||||
|
||||
@ -516,7 +517,12 @@ class calculate_taxes_and_totals(object):
|
||||
tax.base_tax_amount = round(tax.base_tax_amount, 0)
|
||||
tax.base_tax_amount_after_discount_amount = round(tax.base_tax_amount_after_discount_amount, 0)
|
||||
|
||||
@deprecated
|
||||
def manipulate_grand_total_for_inclusive_tax(self):
|
||||
# for backward compatablility - if in case used by an external application
|
||||
return self.adjust_grand_total_for_inclusive_tax()
|
||||
|
||||
def adjust_grand_total_for_inclusive_tax(self):
|
||||
# if fully inclusive taxes and diff
|
||||
if self.doc.get("taxes") and any(cint(t.included_in_print_rate) for t in self.doc.get("taxes")):
|
||||
last_tax = self.doc.get("taxes")[-1]
|
||||
@ -538,17 +544,21 @@ class calculate_taxes_and_totals(object):
|
||||
diff = flt(diff, self.doc.precision("rounding_adjustment"))
|
||||
|
||||
if diff and abs(diff) <= (5.0 / 10 ** last_tax.precision("tax_amount")):
|
||||
self.doc.rounding_adjustment = diff
|
||||
self.doc.grand_total_diff = diff
|
||||
else:
|
||||
self.doc.grand_total_diff = 0
|
||||
|
||||
def calculate_totals(self):
|
||||
if self.doc.get("taxes"):
|
||||
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(self.doc.rounding_adjustment)
|
||||
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(
|
||||
self.doc.get("grand_total_diff")
|
||||
)
|
||||
else:
|
||||
self.doc.grand_total = flt(self.doc.net_total)
|
||||
|
||||
if self.doc.get("taxes"):
|
||||
self.doc.total_taxes_and_charges = flt(
|
||||
self.doc.grand_total - self.doc.net_total - flt(self.doc.rounding_adjustment),
|
||||
self.doc.grand_total - self.doc.net_total - flt(self.doc.get("grand_total_diff")),
|
||||
self.doc.precision("total_taxes_and_charges"),
|
||||
)
|
||||
else:
|
||||
@ -613,8 +623,8 @@ class calculate_taxes_and_totals(object):
|
||||
self.doc.grand_total, self.doc.currency, self.doc.precision("rounded_total")
|
||||
)
|
||||
|
||||
# if print_in_rate is set, we would have already calculated rounding adjustment
|
||||
self.doc.rounding_adjustment += flt(
|
||||
# rounding adjustment should always be the difference vetween grand and rounded total
|
||||
self.doc.rounding_adjustment = flt(
|
||||
self.doc.rounded_total - self.doc.grand_total, self.doc.precision("rounding_adjustment")
|
||||
)
|
||||
|
||||
@ -832,7 +842,6 @@ class calculate_taxes_and_totals(object):
|
||||
self.calculate_paid_amount()
|
||||
|
||||
def calculate_paid_amount(self):
|
||||
|
||||
paid_amount = base_paid_amount = 0.0
|
||||
|
||||
if self.doc.is_pos:
|
||||
|
@ -155,7 +155,7 @@ class TallyMigration(Document):
|
||||
except RecursionError:
|
||||
self.log(
|
||||
_(
|
||||
"Error occured while parsing Chart of Accounts: Please make sure that no two accounts have the same name"
|
||||
"Error occurred while parsing Chart of Accounts: Please make sure that no two accounts have the same name"
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -481,8 +481,8 @@ payment_gateway_enabled = "erpnext.accounts.utils.create_payment_gateway_account
|
||||
|
||||
communication_doctypes = ["Customer", "Supplier"]
|
||||
|
||||
advance_payment_customer_doctypes = ["Sales Order"]
|
||||
advance_payment_supplier_doctypes = ["Purchase Order"]
|
||||
advance_payment_receivable_doctypes = ["Sales Order"]
|
||||
advance_payment_payable_doctypes = ["Purchase Order"]
|
||||
|
||||
invoice_doctypes = ["Sales Invoice", "Purchase Invoice"]
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -222,7 +222,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
def validate_maintenance_detail(self):
|
||||
if not self.get("items"):
|
||||
throw(_("Please enter Maintaince Details first"))
|
||||
throw(_("Please enter Maintenance Details first"))
|
||||
|
||||
for d in self.get("items"):
|
||||
if not d.item_code:
|
||||
|
@ -176,8 +176,10 @@ class BOM(WebsiteGenerator):
|
||||
|
||||
def autoname(self):
|
||||
# ignore amended documents while calculating current index
|
||||
|
||||
search_key = f"{self.doctype}-{self.item}%"
|
||||
existing_boms = frappe.get_all(
|
||||
"BOM", filters={"item": self.item, "amended_from": ["is", "not set"]}, pluck="name"
|
||||
"BOM", filters={"name": ("like", search_key), "amended_from": ["is", "not set"]}, pluck="name"
|
||||
)
|
||||
|
||||
if existing_boms:
|
||||
|
@ -1520,7 +1520,7 @@ def validate_operation_data(row):
|
||||
|
||||
if row.get("qty") > row.get("pending_qty"):
|
||||
frappe.throw(
|
||||
_("For operation {0}: Quantity ({1}) can not be greter than pending quantity({2})").format(
|
||||
_("For operation {0}: Quantity ({1}) can not be greater than pending quantity({2})").format(
|
||||
frappe.bold(row.get("operation")),
|
||||
frappe.bold(row.get("qty")),
|
||||
frappe.bold(row.get("pending_qty")),
|
||||
|
@ -188,4 +188,4 @@ def execute():
|
||||
raise err
|
||||
else:
|
||||
break
|
||||
print(f"{processed} records have been sucessfully migrated")
|
||||
print(f"{processed} records have been successfully migrated")
|
||||
|
@ -160,7 +160,7 @@ erpnext.accounts.taxes = {
|
||||
let tax = frappe.get_doc(cdt, cdn);
|
||||
try {
|
||||
me.validate_taxes_and_charges(cdt, cdn);
|
||||
me.validate_inclusive_tax(tax);
|
||||
me.validate_inclusive_tax(tax, frm);
|
||||
} catch(e) {
|
||||
tax.included_in_print_rate = 0;
|
||||
refresh_field("included_in_print_rate", tax.name, tax.parentfield);
|
||||
@ -170,7 +170,8 @@ erpnext.accounts.taxes = {
|
||||
});
|
||||
},
|
||||
|
||||
validate_inclusive_tax: function(tax) {
|
||||
validate_inclusive_tax: function(tax, frm) {
|
||||
this.frm = this.frm || frm;
|
||||
let actual_type_error = function() {
|
||||
var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
|
||||
frappe.throw(msg);
|
||||
@ -186,12 +187,12 @@ erpnext.accounts.taxes = {
|
||||
if(tax.charge_type == "Actual") {
|
||||
// inclusive tax cannot be of type Actual
|
||||
actual_type_error();
|
||||
} else if(tax.charge_type == "On Previous Row Amount" &&
|
||||
} else if (tax.charge_type == "On Previous Row Amount" && this.frm &&
|
||||
!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)
|
||||
) {
|
||||
// referred row should also be an inclusive tax
|
||||
on_previous_row_error(tax.row_id);
|
||||
} else if(tax.charge_type == "On Previous Row Total") {
|
||||
} else if (tax.charge_type == "On Previous Row Total" && this.frm) {
|
||||
var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
|
||||
function(t) { return cint(t.included_in_print_rate) ? null : t; });
|
||||
if(taxes_not_included.length > 0) {
|
||||
|
@ -103,7 +103,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
this.determine_exclusive_rate();
|
||||
this.calculate_net_total();
|
||||
this.calculate_taxes();
|
||||
this.manipulate_grand_total_for_inclusive_tax();
|
||||
this.adjust_grand_total_for_inclusive_tax();
|
||||
this.calculate_totals();
|
||||
this._cleanup();
|
||||
}
|
||||
@ -185,7 +185,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
|
||||
if (!this.discount_amount_applied) {
|
||||
erpnext.accounts.taxes.validate_taxes_and_charges(tax.doctype, tax.name);
|
||||
erpnext.accounts.taxes.validate_inclusive_tax(tax);
|
||||
erpnext.accounts.taxes.validate_inclusive_tax(tax, this.frm);
|
||||
}
|
||||
frappe.model.round_floats_in(tax);
|
||||
});
|
||||
@ -248,7 +248,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
|
||||
if(!me.discount_amount_applied && item.qty && (total_inclusive_tax_amount_per_qty || cumulated_tax_fraction)) {
|
||||
var amount = flt(item.amount) - total_inclusive_tax_amount_per_qty;
|
||||
item.net_amount = flt(amount / (1 + cumulated_tax_fraction));
|
||||
item.net_amount = flt(amount / (1 + cumulated_tax_fraction), precision("net_amount", item));
|
||||
item.net_rate = item.qty ? flt(item.net_amount / item.qty, precision("net_rate", item)) : 0;
|
||||
|
||||
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
|
||||
@ -303,6 +303,8 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
me.frm.doc.net_total += item.net_amount;
|
||||
me.frm.doc.base_net_total += item.base_net_amount;
|
||||
});
|
||||
|
||||
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
|
||||
}
|
||||
|
||||
calculate_shipping_charges() {
|
||||
@ -521,8 +523,17 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use adjust_grand_total_for_inclusive_tax instead.
|
||||
*/
|
||||
manipulate_grand_total_for_inclusive_tax() {
|
||||
// for backward compatablility - if in case used by an external application
|
||||
this.adjust_grand_total_for_inclusive_tax()
|
||||
}
|
||||
|
||||
adjust_grand_total_for_inclusive_tax() {
|
||||
var me = this;
|
||||
|
||||
// if fully inclusive taxes and diff
|
||||
if (this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
|
||||
var any_inclusive_tax = false;
|
||||
@ -548,7 +559,9 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
diff = flt(diff, precision("rounding_adjustment"));
|
||||
|
||||
if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) {
|
||||
me.frm.doc.rounding_adjustment = diff;
|
||||
me.frm.doc.grand_total_diff = diff;
|
||||
} else {
|
||||
me.frm.doc.grand_total_diff = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,7 +572,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
var me = this;
|
||||
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
|
||||
this.frm.doc.grand_total = flt(tax_count
|
||||
? this.frm.doc["taxes"][tax_count - 1].total + flt(this.frm.doc.rounding_adjustment)
|
||||
? this.frm.doc["taxes"][tax_count - 1].total + flt(this.frm.doc.grand_total_diff)
|
||||
: this.frm.doc.net_total);
|
||||
|
||||
if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice", "POS Invoice"], this.frm.doc.doctype)) {
|
||||
@ -619,7 +632,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
|
||||
this.frm.doc.rounded_total = round_based_on_smallest_currency_fraction(this.frm.doc.grand_total,
|
||||
this.frm.doc.currency, precision("rounded_total"));
|
||||
this.frm.doc.rounding_adjustment += flt(this.frm.doc.rounded_total - this.frm.doc.grand_total,
|
||||
this.frm.doc.rounding_adjustment = flt(this.frm.doc.rounded_total - this.frm.doc.grand_total,
|
||||
precision("rounding_adjustment"));
|
||||
|
||||
this.set_in_company_currency(this.frm.doc, ["rounding_adjustment", "rounded_total"]);
|
||||
@ -687,8 +700,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
||||
if (total_for_discount_amount) {
|
||||
$.each(this.frm._items || [], function(i, item) {
|
||||
distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
|
||||
item.net_amount = flt(item.net_amount - distributed_amount,
|
||||
precision("base_amount", item));
|
||||
item.net_amount = flt(item.net_amount - distributed_amount, precision("net_amount", item));
|
||||
net_total += item.net_amount;
|
||||
|
||||
// discount amount rounding loss adjustment if no taxes
|
||||
|
@ -790,24 +790,25 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
if (me.frm.doc.price_list_currency == company_currency) {
|
||||
me.frm.set_value('plc_conversion_rate', 1.0);
|
||||
}
|
||||
if (company_doc && company_doc.default_letter_head) {
|
||||
if(me.frm.fields_dict.letter_head) {
|
||||
me.frm.set_value("letter_head", company_doc.default_letter_head);
|
||||
if (company_doc){
|
||||
if (company_doc.default_letter_head) {
|
||||
if(me.frm.fields_dict.letter_head) {
|
||||
me.frm.set_value("letter_head", company_doc.default_letter_head);
|
||||
}
|
||||
}
|
||||
let selling_doctypes_for_tc = ["Sales Invoice", "Quotation", "Sales Order", "Delivery Note"];
|
||||
if (company_doc.default_selling_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
|
||||
selling_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
|
||||
me.frm.set_value("tc_name", company_doc.default_selling_terms);
|
||||
}
|
||||
let buying_doctypes_for_tc = ["Request for Quotation", "Supplier Quotation", "Purchase Order",
|
||||
"Material Request", "Purchase Receipt"];
|
||||
// Purchase Invoice is excluded as per issue #3345
|
||||
if (company_doc.default_buying_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
|
||||
buying_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
|
||||
me.frm.set_value("tc_name", company_doc.default_buying_terms);
|
||||
}
|
||||
}
|
||||
let selling_doctypes_for_tc = ["Sales Invoice", "Quotation", "Sales Order", "Delivery Note"];
|
||||
if (company_doc.default_selling_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
|
||||
selling_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
|
||||
me.frm.set_value("tc_name", company_doc.default_selling_terms);
|
||||
}
|
||||
let buying_doctypes_for_tc = ["Request for Quotation", "Supplier Quotation", "Purchase Order",
|
||||
"Material Request", "Purchase Receipt"];
|
||||
// Purchase Invoice is excluded as per issue #3345
|
||||
if (company_doc.default_buying_terms && frappe.meta.has_field(me.frm.doc.doctype, "tc_name") &&
|
||||
buying_doctypes_for_tc.indexOf(me.frm.doc.doctype) != -1) {
|
||||
me.frm.set_value("tc_name", company_doc.default_buying_terms);
|
||||
}
|
||||
|
||||
frappe.run_serially([
|
||||
() => me.frm.script_manager.trigger("currency"),
|
||||
() => me.update_item_tax_map(),
|
||||
|
@ -2,7 +2,58 @@ frappe.provide("erpnext.financial_statements");
|
||||
|
||||
erpnext.financial_statements = {
|
||||
"filters": get_filters(),
|
||||
"baseData": null,
|
||||
"formatter": function(value, row, column, data, default_formatter, filter) {
|
||||
if(frappe.query_report.get_filter_value("selected_view") == "Growth" && data && column.colIndex >= 3){
|
||||
//Assuming that the first three columns are s.no, account name and the very first year of the accounting values, to calculate the relative percentage values of the successive columns.
|
||||
const lastAnnualValue = row[column.colIndex - 1].content;
|
||||
const currentAnnualvalue = data[column.fieldname];
|
||||
if(currentAnnualvalue == undefined) return 'NA'; //making this not applicable for undefined/null values
|
||||
let annualGrowth = 0;
|
||||
if(lastAnnualValue == 0 && currentAnnualvalue > 0){
|
||||
//If the previous year value is 0 and the current value is greater than 0
|
||||
annualGrowth = 1;
|
||||
}
|
||||
else if(lastAnnualValue > 0){
|
||||
annualGrowth = (currentAnnualvalue - lastAnnualValue) / lastAnnualValue;
|
||||
}
|
||||
|
||||
const growthPercent = (Math.round(annualGrowth*10000)/100); //calculating the rounded off percentage
|
||||
|
||||
value = $(`<span>${((growthPercent >=0)? '+':'' )+growthPercent+'%'}</span>`);
|
||||
if(growthPercent < 0){
|
||||
value = $(value).addClass("text-danger");
|
||||
}
|
||||
else{
|
||||
value = $(value).addClass("text-success");
|
||||
}
|
||||
value = $(value).wrap("<p></p>").parent().html();
|
||||
|
||||
return value;
|
||||
}
|
||||
else if(frappe.query_report.get_filter_value("selected_view") == "Margin" && data){
|
||||
if(column.fieldname =="account" && data.account_name == __("Income")){
|
||||
//Taking the total income from each column (for all the financial years) as the base (100%)
|
||||
this.baseData = row;
|
||||
}
|
||||
if(column.colIndex >= 2){
|
||||
//Assuming that the first two columns are s.no and account name, to calculate the relative percentage values of the successive columns.
|
||||
const currentAnnualvalue = data[column.fieldname];
|
||||
const baseValue = this.baseData[column.colIndex].content;
|
||||
if(currentAnnualvalue == undefined || baseValue <= 0) return 'NA';
|
||||
const marginPercent = Math.round((currentAnnualvalue/baseValue)*10000)/100;
|
||||
|
||||
value = $(`<span>${marginPercent+'%'}</span>`);
|
||||
if(marginPercent < 0)
|
||||
value = $(value).addClass("text-danger");
|
||||
else
|
||||
value = $(value).addClass("text-success");
|
||||
value = $(value).wrap("<p></p>").parent().html();
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (data && column.fieldname=="account") {
|
||||
value = data.account_name || value;
|
||||
|
||||
@ -74,22 +125,24 @@ erpnext.financial_statements = {
|
||||
});
|
||||
});
|
||||
|
||||
const views_menu = report.page.add_custom_button_group(__('Financial Statements'));
|
||||
if (report.page){
|
||||
const views_menu = report.page.add_custom_button_group(__('Financial Statements'));
|
||||
|
||||
report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
|
||||
});
|
||||
report.page.add_custom_menu_item(views_menu, __("Balance Sheet"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Balance Sheet', {company: filters.company});
|
||||
});
|
||||
|
||||
report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
|
||||
});
|
||||
report.page.add_custom_menu_item(views_menu, __("Profit and Loss"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Profit and Loss Statement', {company: filters.company});
|
||||
});
|
||||
|
||||
report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
|
||||
});
|
||||
report.page.add_custom_menu_item(views_menu, __("Cash Flow Statement"), function() {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route('query-report', 'Cash Flow', {company: filters.company});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -71,6 +71,10 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
||||
let warehouse = this.item?.type_of_transaction === "Outward" ?
|
||||
(this.item.warehouse || this.item.s_warehouse) : "";
|
||||
|
||||
if (!warehouse && this.frm.doc.doctype === 'Stock Reconciliation') {
|
||||
warehouse = this.get_warehouse();
|
||||
}
|
||||
|
||||
return {
|
||||
'item_code': this.item.item_code,
|
||||
'warehouse': ["=", warehouse]
|
||||
|
@ -64,7 +64,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto",
|
||||
"label": "Valid Up To",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@ -135,7 +135,7 @@
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-04-18 08:25:35.302081",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Regional",
|
||||
"name": "Lower Deduction Certificate",
|
||||
|
@ -37,7 +37,7 @@ class LowerDeductionCertificate(Document):
|
||||
|
||||
def validate_dates(self):
|
||||
if getdate(self.valid_upto) < getdate(self.valid_from):
|
||||
frappe.throw(_("Valid Upto date cannot be before Valid From date"))
|
||||
frappe.throw(_("Valid Up To date cannot be before Valid From date"))
|
||||
|
||||
fiscal_year = get_fiscal_year(fiscal_year=self.fiscal_year, as_dict=True)
|
||||
|
||||
@ -45,7 +45,7 @@ class LowerDeductionCertificate(Document):
|
||||
frappe.throw(_("Valid From date not in Fiscal Year {0}").format(frappe.bold(self.fiscal_year)))
|
||||
|
||||
if not (fiscal_year.year_start_date <= getdate(self.valid_upto) <= fiscal_year.year_end_date):
|
||||
frappe.throw(_("Valid Upto date not in Fiscal Year {0}").format(frappe.bold(self.fiscal_year)))
|
||||
frappe.throw(_("Valid Up To date not in Fiscal Year {0}").format(frappe.bold(self.fiscal_year)))
|
||||
|
||||
def validate_supplier_against_tax_category(self):
|
||||
duplicate_certificate = frappe.db.get_value(
|
||||
|
@ -124,6 +124,7 @@ class Customer(TransactionBase):
|
||||
),
|
||||
title=_("Note"),
|
||||
indicator="yellow",
|
||||
alert=True,
|
||||
)
|
||||
|
||||
return new_customer_name
|
||||
|
@ -427,11 +427,11 @@ def create_internal_customer(
|
||||
if not allowed_to_interact_with:
|
||||
allowed_to_interact_with = represents_company
|
||||
|
||||
exisiting_representative = frappe.db.get_value(
|
||||
existing_representative = frappe.db.get_value(
|
||||
"Customer", {"represents_company": represents_company}
|
||||
)
|
||||
if exisiting_representative:
|
||||
return exisiting_representative
|
||||
if existing_representative:
|
||||
return existing_representative
|
||||
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
customer = frappe.get_doc(
|
||||
|
@ -346,8 +346,8 @@ def make_sales_order(source_name: str, target_doc=None):
|
||||
return _make_sales_order(source_name, target_doc)
|
||||
|
||||
|
||||
def _make_sales_order(source_name, target_doc=None, customer_group=None, ignore_permissions=False):
|
||||
customer = _make_customer(source_name, ignore_permissions, customer_group)
|
||||
def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
|
||||
customer = _make_customer(source_name, ignore_permissions)
|
||||
ordered_items = frappe._dict(
|
||||
frappe.db.get_all(
|
||||
"Sales Order Item",
|
||||
@ -391,7 +391,6 @@ def _make_sales_order(source_name, target_doc=None, customer_group=None, ignore_
|
||||
balance_qty = obj.qty - ordered_items.get(obj.item_code, 0.0)
|
||||
target.qty = balance_qty if balance_qty > 0 else 0
|
||||
target.stock_qty = flt(target.qty) * flt(obj.conversion_factor)
|
||||
target.delivery_date = nowdate()
|
||||
|
||||
if obj.against_blanket_order:
|
||||
target.against_blanket_order = obj.against_blanket_order
|
||||
@ -507,50 +506,51 @@ def _make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
|
||||
return doclist
|
||||
|
||||
|
||||
def _make_customer(source_name, ignore_permissions=False, customer_group=None):
|
||||
def _make_customer(source_name, ignore_permissions=False):
|
||||
quotation = frappe.db.get_value(
|
||||
"Quotation", source_name, ["order_type", "party_name", "customer_name"], as_dict=1
|
||||
"Quotation",
|
||||
source_name,
|
||||
["order_type", "quotation_to", "party_name", "customer_name"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if quotation and quotation.get("party_name"):
|
||||
if not frappe.db.exists("Customer", quotation.get("party_name")):
|
||||
lead_name = quotation.get("party_name")
|
||||
customer_name = frappe.db.get_value(
|
||||
"Customer", {"lead_name": lead_name}, ["name", "customer_name"], as_dict=True
|
||||
)
|
||||
if not customer_name:
|
||||
from erpnext.crm.doctype.lead.lead import _make_customer
|
||||
if quotation.quotation_to == "Customer":
|
||||
return frappe.get_doc("Customer", quotation.party_name)
|
||||
|
||||
customer_doclist = _make_customer(lead_name, ignore_permissions=ignore_permissions)
|
||||
customer = frappe.get_doc(customer_doclist)
|
||||
customer.flags.ignore_permissions = ignore_permissions
|
||||
customer.customer_group = customer_group
|
||||
# If the Quotation is not to a Customer, it must be to a Lead.
|
||||
# Check if a Customer already exists for the Lead.
|
||||
existing_customer_for_lead = frappe.db.get_value("Customer", {"lead_name": quotation.party_name})
|
||||
if existing_customer_for_lead:
|
||||
return frappe.get_doc("Customer", existing_customer_for_lead)
|
||||
|
||||
try:
|
||||
customer.insert()
|
||||
return customer
|
||||
except frappe.NameError:
|
||||
if frappe.defaults.get_global_default("cust_master_name") == "Customer Name":
|
||||
customer.run_method("autoname")
|
||||
customer.name += "-" + lead_name
|
||||
customer.insert()
|
||||
return customer
|
||||
else:
|
||||
raise
|
||||
except frappe.MandatoryError as e:
|
||||
mandatory_fields = e.args[0].split(":")[1].split(",")
|
||||
mandatory_fields = [customer.meta.get_label(field.strip()) for field in mandatory_fields]
|
||||
# If no Customer exists for the Lead, create a new Customer.
|
||||
return create_customer_from_lead(quotation.party_name, ignore_permissions=ignore_permissions)
|
||||
|
||||
frappe.local.message_log = []
|
||||
lead_link = frappe.utils.get_link_to_form("Lead", lead_name)
|
||||
message = (
|
||||
_("Could not auto create Customer due to the following missing mandatory field(s):") + "<br>"
|
||||
)
|
||||
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
|
||||
message += _("Please create Customer from Lead {0}.").format(lead_link)
|
||||
|
||||
frappe.throw(message, title=_("Mandatory Missing"))
|
||||
else:
|
||||
return customer_name
|
||||
else:
|
||||
return frappe.get_doc("Customer", quotation.get("party_name"))
|
||||
def create_customer_from_lead(lead_name, ignore_permissions=False):
|
||||
from erpnext.crm.doctype.lead.lead import _make_customer
|
||||
|
||||
customer = _make_customer(lead_name, ignore_permissions=ignore_permissions)
|
||||
customer.flags.ignore_permissions = ignore_permissions
|
||||
|
||||
try:
|
||||
customer.insert()
|
||||
return customer
|
||||
except frappe.MandatoryError as e:
|
||||
handle_mandatory_error(e, customer, lead_name)
|
||||
|
||||
|
||||
def handle_mandatory_error(e, customer, lead_name):
|
||||
from frappe.utils import get_link_to_form
|
||||
|
||||
mandatory_fields = e.args[0].split(":")[1].split(",")
|
||||
mandatory_fields = [customer.meta.get_label(field.strip()) for field in mandatory_fields]
|
||||
|
||||
frappe.local.message_log = []
|
||||
message = (
|
||||
_("Could not auto create Customer due to the following missing mandatory field(s):") + "<br>"
|
||||
)
|
||||
message += "<br><ul><li>" + "</li><li>".join(mandatory_fields) + "</li></ul>"
|
||||
message += _("Please create Customer from Lead {0}.").format(get_link_to_form("Lead", lead_name))
|
||||
|
||||
frappe.throw(message, title=_("Mandatory Missing"))
|
||||
|
@ -99,7 +99,6 @@ class TestQuotation(FrappeTestCase):
|
||||
self.assertEqual(sales_order.get("items")[0].prevdoc_docname, quotation.name)
|
||||
self.assertEqual(sales_order.customer, "_Test Customer")
|
||||
|
||||
sales_order.delivery_date = "2014-01-01"
|
||||
sales_order.naming_series = "_T-Quotation-"
|
||||
sales_order.transaction_date = nowdate()
|
||||
sales_order.insert()
|
||||
@ -132,7 +131,6 @@ class TestQuotation(FrappeTestCase):
|
||||
self.assertEqual(sales_order.get("items")[0].prevdoc_docname, quotation.name)
|
||||
self.assertEqual(sales_order.customer, "_Test Customer")
|
||||
|
||||
sales_order.delivery_date = "2014-01-01"
|
||||
sales_order.naming_series = "_T-Quotation-"
|
||||
sales_order.transaction_date = nowdate()
|
||||
sales_order.insert()
|
||||
@ -609,6 +607,61 @@ class TestQuotation(FrappeTestCase):
|
||||
quotation.items[0].conversion_factor = 2.23
|
||||
self.assertRaises(frappe.ValidationError, quotation.save)
|
||||
|
||||
def test_item_tax_template_for_quotation(self):
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
if not frappe.db.exists("Account", {"account_name": "_Test Vat", "company": "_Test Company"}):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Account",
|
||||
"account_name": "_Test Vat",
|
||||
"company": "_Test Company",
|
||||
"account_type": "Tax",
|
||||
"root_type": "Asset",
|
||||
"is_group": 0,
|
||||
"parent_account": "Tax Assets - _TC",
|
||||
"tax_rate": 10,
|
||||
}
|
||||
).insert()
|
||||
|
||||
if not frappe.db.exists("Item Tax Template", "Vat Template - _TC"):
|
||||
doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Item Tax Template",
|
||||
"name": "Vat Template",
|
||||
"title": "Vat Template",
|
||||
"company": "_Test Company",
|
||||
"taxes": [
|
||||
{
|
||||
"tax_type": "_Test Vat - _TC",
|
||||
"tax_rate": 5,
|
||||
}
|
||||
],
|
||||
}
|
||||
).insert()
|
||||
|
||||
item_doc = make_item("_Test Item Tax Template QTN", {"is_stock_item": 1})
|
||||
if not frappe.db.exists(
|
||||
"Item Tax", {"parent": item_doc.name, "item_tax_template": "Vat Template - _TC"}
|
||||
):
|
||||
item_doc.append("taxes", {"item_tax_template": "Vat Template - _TC"})
|
||||
item_doc.save()
|
||||
|
||||
quotation = make_quotation(
|
||||
item_code="_Test Item Tax Template QTN", qty=1, rate=100, do_not_submit=1
|
||||
)
|
||||
self.assertFalse(quotation.taxes)
|
||||
|
||||
quotation.append_taxes_from_item_tax_template()
|
||||
quotation.save()
|
||||
self.assertTrue(quotation.taxes)
|
||||
for row in quotation.taxes:
|
||||
self.assertEqual(row.account_head, "_Test Vat - _TC")
|
||||
self.assertAlmostEqual(row.base_tax_amount, quotation.total * 5 / 100)
|
||||
|
||||
item_doc.taxes = []
|
||||
item_doc.save()
|
||||
|
||||
|
||||
test_records = frappe.get_test_records("Quotation")
|
||||
|
||||
|
@ -643,7 +643,7 @@ class SalesOrder(SellingController):
|
||||
if not frappe.get_cached_value("Item", item.item_code, "has_serial_no"):
|
||||
frappe.throw(
|
||||
_(
|
||||
"Item {0} has no Serial No. Only serilialized items can have delivery based on Serial No"
|
||||
"Item {0} has no Serial No. Only serialized items can have delivery based on Serial No"
|
||||
).format(item.item_code)
|
||||
)
|
||||
if not frappe.db.exists("BOM", {"item": item.item_code, "is_active": 1}):
|
||||
|
@ -118,6 +118,7 @@
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Item",
|
||||
"print_width": "150px",
|
||||
"reqd": 1,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
@ -908,7 +909,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-24 13:24:55.756320",
|
||||
"modified": "2024-01-25 14:24:00.330219",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Sales Order Item",
|
||||
|
@ -43,7 +43,8 @@ class SalesOrderItem(Document):
|
||||
gross_profit: DF.Currency
|
||||
image: DF.Attach | None
|
||||
is_free_item: DF.Check
|
||||
item_code: DF.Link | None
|
||||
is_stock_item: DF.Check
|
||||
item_code: DF.Link
|
||||
item_group: DF.Link | None
|
||||
item_name: DF.Data
|
||||
item_tax_rate: DF.Code | None
|
||||
|
@ -360,7 +360,7 @@ erpnext.PointOfSale.Controller = class {
|
||||
this.order_summary.load_summary_of(this.frm.doc, true);
|
||||
frappe.show_alert({
|
||||
indicator: 'green',
|
||||
message: __('POS invoice {0} created succesfully', [r.doc.name])
|
||||
message: __('POS invoice {0} created successfully', [r.doc.name])
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -210,7 +210,6 @@ def get_so_with_invoices(filters):
|
||||
.where(
|
||||
(so.docstatus == 1)
|
||||
& (so.status.isin(["To Deliver and Bill", "To Bill", "To Pay"]))
|
||||
& (so.payment_terms_template != "NULL")
|
||||
& (so.company == conditions.company)
|
||||
& (so.transaction_date[conditions.start_date : conditions.end_date])
|
||||
)
|
||||
|
@ -54,7 +54,7 @@ class AuthorizationControl(TransactionBase):
|
||||
if not has_common(appr_roles, frappe.get_roles()) and not has_common(
|
||||
appr_users, [session["user"]]
|
||||
):
|
||||
frappe.msgprint(_("Not authroized since {0} exceeds limits").format(_(based_on)))
|
||||
frappe.msgprint(_("Not authorized since {0} exceeds limits").format(_(based_on)))
|
||||
frappe.throw(_("Can be approved by {0}").format(comma_or(appr_roles + appr_users)))
|
||||
|
||||
def validate_auth_rule(self, doctype_name, total, based_on, cond, company, master_name=""):
|
||||
|
@ -908,8 +908,8 @@ def generate_id_for_deletion_job(company):
|
||||
@frappe.whitelist()
|
||||
def is_deletion_job_running(company):
|
||||
job_id = generate_id_for_deletion_job(company)
|
||||
job_name = get_job(job_id).get_id() # job name will have site prefix
|
||||
if is_job_enqueued(job_id):
|
||||
job_name = get_job(job_id).get_id() # job name will have site prefix
|
||||
frappe.throw(
|
||||
_("A Transaction Deletion Job: {0} is already running for {1}").format(
|
||||
frappe.bold(get_link_to_form("RQ Job", job_name)), frappe.bold(company)
|
||||
|
@ -441,13 +441,13 @@
|
||||
{
|
||||
"fieldname": "prefered_contact_email",
|
||||
"fieldtype": "Select",
|
||||
"label": "Prefered Contact Email",
|
||||
"label": "Preferred Contact Email",
|
||||
"options": "\nCompany Email\nPersonal Email\nUser ID"
|
||||
},
|
||||
{
|
||||
"fieldname": "prefered_email",
|
||||
"fieldtype": "Data",
|
||||
"label": "Prefered Email",
|
||||
"label": "Preferred Email",
|
||||
"options": "Email",
|
||||
"read_only": 1
|
||||
},
|
||||
@ -524,7 +524,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto"
|
||||
"label": "Valid Up To"
|
||||
},
|
||||
{
|
||||
"fieldname": "place_of_issue",
|
||||
@ -824,7 +824,7 @@
|
||||
"image_field": "image",
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"modified": "2024-01-03 17:36:20.984421",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Employee",
|
||||
|
@ -4,9 +4,10 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestTransactionDeletionRecord(unittest.TestCase):
|
||||
class TestTransactionDeletionRecord(FrappeTestCase):
|
||||
def setUp(self):
|
||||
create_company("Dunder Mifflin Paper Co")
|
||||
|
||||
@ -14,7 +15,7 @@ class TestTransactionDeletionRecord(unittest.TestCase):
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_doctypes_contain_company_field(self):
|
||||
tdr = create_transaction_deletion_request("Dunder Mifflin Paper Co")
|
||||
tdr = create_transaction_deletion_doc("Dunder Mifflin Paper Co")
|
||||
for doctype in tdr.doctypes:
|
||||
contains_company = False
|
||||
doctype_fields = frappe.get_meta(doctype.doctype_name).as_dict()["fields"]
|
||||
@ -27,17 +28,27 @@ class TestTransactionDeletionRecord(unittest.TestCase):
|
||||
def test_no_of_docs_is_correct(self):
|
||||
for i in range(5):
|
||||
create_task("Dunder Mifflin Paper Co")
|
||||
tdr = create_transaction_deletion_request("Dunder Mifflin Paper Co")
|
||||
tdr = create_transaction_deletion_doc("Dunder Mifflin Paper Co")
|
||||
for doctype in tdr.doctypes:
|
||||
if doctype.doctype_name == "Task":
|
||||
self.assertEqual(doctype.no_of_docs, 5)
|
||||
|
||||
def test_deletion_is_successful(self):
|
||||
create_task("Dunder Mifflin Paper Co")
|
||||
create_transaction_deletion_request("Dunder Mifflin Paper Co")
|
||||
create_transaction_deletion_doc("Dunder Mifflin Paper Co")
|
||||
tasks_containing_company = frappe.get_all("Task", filters={"company": "Dunder Mifflin Paper Co"})
|
||||
self.assertEqual(tasks_containing_company, [])
|
||||
|
||||
def test_company_transaction_deletion_request(self):
|
||||
from erpnext.setup.doctype.company.company import create_transaction_deletion_request
|
||||
|
||||
# don't reuse below company for other test cases
|
||||
company = "Deep Space Exploration"
|
||||
create_company(company)
|
||||
|
||||
# below call should not raise any exceptions or throw errors
|
||||
create_transaction_deletion_request(company)
|
||||
|
||||
|
||||
def create_company(company_name):
|
||||
company = frappe.get_doc(
|
||||
@ -46,7 +57,7 @@ def create_company(company_name):
|
||||
company.insert(ignore_if_duplicate=True)
|
||||
|
||||
|
||||
def create_transaction_deletion_request(company):
|
||||
def create_transaction_deletion_doc(company):
|
||||
tdr = frappe.get_doc({"doctype": "Transaction Deletion Record", "company": company})
|
||||
tdr.insert()
|
||||
tdr.submit()
|
||||
|
@ -52,7 +52,7 @@ frappe.ui.form.on('Batch', {
|
||||
// sort by qty
|
||||
r.message.sort(function(a, b) { a.qty > b.qty ? 1 : -1 });
|
||||
|
||||
var rows = $('<div></div>').appendTo(section);
|
||||
const rows = $('<div></div>').appendTo(section);
|
||||
|
||||
// show
|
||||
(r.message || []).forEach(function(d) {
|
||||
@ -76,7 +76,7 @@ frappe.ui.form.on('Batch', {
|
||||
|
||||
// move - ask for target warehouse and make stock entry
|
||||
rows.find('.btn-move').on('click', function() {
|
||||
var $btn = $(this);
|
||||
const $btn = $(this);
|
||||
const fields = [
|
||||
{
|
||||
fieldname: 'to_warehouse',
|
||||
@ -115,7 +115,7 @@ frappe.ui.form.on('Batch', {
|
||||
// split - ask for new qty and batch ID (optional)
|
||||
// and make stock entry via batch.batch_split
|
||||
rows.find('.btn-split').on('click', function() {
|
||||
var $btn = $(this);
|
||||
const $btn = $(this);
|
||||
frappe.prompt([{
|
||||
fieldname: 'qty',
|
||||
label: __('New Batch Qty'),
|
||||
@ -128,19 +128,16 @@ frappe.ui.form.on('Batch', {
|
||||
fieldtype: 'Data',
|
||||
}],
|
||||
(data) => {
|
||||
frappe.call({
|
||||
method: 'erpnext.stock.doctype.batch.batch.split_batch',
|
||||
args: {
|
||||
frappe.xcall(
|
||||
'erpnext.stock.doctype.batch.batch.split_batch',
|
||||
{
|
||||
item_code: frm.doc.item,
|
||||
batch_no: frm.doc.name,
|
||||
qty: data.qty,
|
||||
warehouse: $btn.attr('data-warehouse'),
|
||||
new_batch_id: data.new_batch_id
|
||||
},
|
||||
callback: (r) => {
|
||||
frm.refresh();
|
||||
},
|
||||
});
|
||||
}
|
||||
).then(() => frm.reload_doc());
|
||||
},
|
||||
__('Split Batch'),
|
||||
__('Split')
|
||||
|
@ -9,7 +9,7 @@ from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.naming import make_autoname, revert_series_if_last
|
||||
from frappe.query_builder.functions import CurDate, Sum
|
||||
from frappe.utils import cint, flt, get_link_to_form, nowtime, today
|
||||
from frappe.utils import cint, flt, get_link_to_form
|
||||
from frappe.utils.data import add_days
|
||||
from frappe.utils.jinja import render_template
|
||||
|
||||
@ -248,8 +248,9 @@ def get_batches_by_oldest(item_code, warehouse):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def split_batch(batch_no, item_code, warehouse, qty, new_batch_id=None):
|
||||
|
||||
def split_batch(
|
||||
batch_no: str, item_code: str, warehouse: str, qty: float, new_batch_id: str | None = None
|
||||
):
|
||||
"""Split the batch into a new batch"""
|
||||
batch = frappe.get_doc(dict(doctype="Batch", item=item_code, batch_id=new_batch_id)).insert()
|
||||
qty = flt(qty)
|
||||
@ -257,29 +258,21 @@ def split_batch(batch_no, item_code, warehouse, qty, new_batch_id=None):
|
||||
company = frappe.db.get_value("Warehouse", warehouse, "company")
|
||||
|
||||
from_bundle_id = make_batch_bundle(
|
||||
frappe._dict(
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"batches": frappe._dict({batch_no: qty}),
|
||||
"company": company,
|
||||
"type_of_transaction": "Outward",
|
||||
"qty": qty,
|
||||
}
|
||||
)
|
||||
item_code=item_code,
|
||||
warehouse=warehouse,
|
||||
batches=frappe._dict({batch_no: qty}),
|
||||
company=company,
|
||||
type_of_transaction="Outward",
|
||||
qty=qty,
|
||||
)
|
||||
|
||||
to_bundle_id = make_batch_bundle(
|
||||
frappe._dict(
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"batches": frappe._dict({batch.name: qty}),
|
||||
"company": company,
|
||||
"type_of_transaction": "Inward",
|
||||
"qty": qty,
|
||||
}
|
||||
)
|
||||
item_code=item_code,
|
||||
warehouse=warehouse,
|
||||
batches=frappe._dict({batch.name: qty}),
|
||||
company=company,
|
||||
type_of_transaction="Inward",
|
||||
qty=qty,
|
||||
)
|
||||
|
||||
stock_entry = frappe.get_doc(
|
||||
@ -304,21 +297,30 @@ def split_batch(batch_no, item_code, warehouse, qty, new_batch_id=None):
|
||||
return batch.name
|
||||
|
||||
|
||||
def make_batch_bundle(kwargs):
|
||||
def make_batch_bundle(
|
||||
item_code: str,
|
||||
warehouse: str,
|
||||
batches: dict[str, float],
|
||||
company: str,
|
||||
type_of_transaction: str,
|
||||
qty: float,
|
||||
):
|
||||
from frappe.utils import nowtime, today
|
||||
|
||||
from erpnext.stock.serial_batch_bundle import SerialBatchCreation
|
||||
|
||||
return (
|
||||
SerialBatchCreation(
|
||||
{
|
||||
"item_code": kwargs.item_code,
|
||||
"warehouse": kwargs.warehouse,
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"posting_date": today(),
|
||||
"posting_time": nowtime(),
|
||||
"voucher_type": "Stock Entry",
|
||||
"qty": flt(kwargs.qty),
|
||||
"type_of_transaction": kwargs.type_of_transaction,
|
||||
"company": kwargs.company,
|
||||
"batches": kwargs.batches,
|
||||
"qty": qty,
|
||||
"type_of_transaction": type_of_transaction,
|
||||
"company": company,
|
||||
"batches": batches,
|
||||
"do_not_submit": True,
|
||||
}
|
||||
)
|
||||
|
@ -796,36 +796,36 @@ def update_billed_amount_based_on_so(so_detail, update_modified=True):
|
||||
|
||||
updated_dn = []
|
||||
for dnd in dn_details:
|
||||
billed_amt_agianst_dn = 0
|
||||
billed_amt_against_dn = 0
|
||||
|
||||
# If delivered against Sales Invoice
|
||||
if dnd.si_detail:
|
||||
billed_amt_agianst_dn = flt(dnd.amount)
|
||||
billed_against_so -= billed_amt_agianst_dn
|
||||
billed_amt_against_dn = flt(dnd.amount)
|
||||
billed_against_so -= billed_amt_against_dn
|
||||
else:
|
||||
# Get billed amount directly against Delivery Note
|
||||
billed_amt_agianst_dn = frappe.db.sql(
|
||||
billed_amt_against_dn = frappe.db.sql(
|
||||
"""select sum(amount) from `tabSales Invoice Item`
|
||||
where dn_detail=%s and docstatus=1""",
|
||||
dnd.name,
|
||||
)
|
||||
billed_amt_agianst_dn = billed_amt_agianst_dn and billed_amt_agianst_dn[0][0] or 0
|
||||
billed_amt_against_dn = billed_amt_against_dn and billed_amt_against_dn[0][0] or 0
|
||||
|
||||
# Distribute billed amount directly against SO between DNs based on FIFO
|
||||
if billed_against_so and billed_amt_agianst_dn < dnd.amount:
|
||||
pending_to_bill = flt(dnd.amount) - billed_amt_agianst_dn
|
||||
if billed_against_so and billed_amt_against_dn < dnd.amount:
|
||||
pending_to_bill = flt(dnd.amount) - billed_amt_against_dn
|
||||
if pending_to_bill <= billed_against_so:
|
||||
billed_amt_agianst_dn += pending_to_bill
|
||||
billed_amt_against_dn += pending_to_bill
|
||||
billed_against_so -= pending_to_bill
|
||||
else:
|
||||
billed_amt_agianst_dn += billed_against_so
|
||||
billed_amt_against_dn += billed_against_so
|
||||
billed_against_so = 0
|
||||
|
||||
frappe.db.set_value(
|
||||
"Delivery Note Item",
|
||||
dnd.name,
|
||||
"billed_amt",
|
||||
billed_amt_agianst_dn,
|
||||
billed_amt_against_dn,
|
||||
update_modified=update_modified,
|
||||
)
|
||||
|
||||
|
@ -8,6 +8,7 @@ def get_data():
|
||||
"Stock Entry": "delivery_note_no",
|
||||
"Quality Inspection": "reference_name",
|
||||
"Auto Repeat": "reference_document",
|
||||
"Purchase Receipt": "inter_company_reference",
|
||||
},
|
||||
"internal_links": {
|
||||
"Sales Order": ["items", "against_sales_order"],
|
||||
@ -22,6 +23,9 @@ def get_data():
|
||||
{"label": _("Reference"), "items": ["Sales Order", "Shipment", "Quality Inspection"]},
|
||||
{"label": _("Returns"), "items": ["Stock Entry"]},
|
||||
{"label": _("Subscription"), "items": ["Auto Repeat"]},
|
||||
{"label": _("Internal Transfer"), "items": ["Material Request", "Purchase Order"]},
|
||||
{
|
||||
"label": _("Internal Transfer"),
|
||||
"items": ["Material Request", "Purchase Order", "Purchase Receipt"],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -1597,8 +1597,8 @@ def create_delivery_note(**args):
|
||||
{
|
||||
"item_code": args.item or args.item_code or "_Test Item",
|
||||
"warehouse": args.warehouse or "_Test Warehouse - _TC",
|
||||
"qty": args.qty if args.get("qty") is not None else 1,
|
||||
"rate": args.rate if args.get("rate") is not None else 100,
|
||||
"qty": args.get("qty", 1),
|
||||
"rate": args.get("rate", 100),
|
||||
"conversion_factor": 1.0,
|
||||
"serial_and_batch_bundle": bundle_id,
|
||||
"allow_zero_valuation_rate": args.allow_zero_valuation_rate or 1,
|
||||
|
@ -191,7 +191,7 @@
|
||||
{
|
||||
"fieldname": "valid_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Valid Upto"
|
||||
"label": "Valid Up To"
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_24",
|
||||
@ -220,7 +220,7 @@
|
||||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-15 08:26:04.041861",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item Price",
|
||||
|
@ -59,7 +59,7 @@ class ItemPrice(Document):
|
||||
def validate_dates(self):
|
||||
if self.valid_from and self.valid_upto:
|
||||
if getdate(self.valid_from) > getdate(self.valid_upto):
|
||||
frappe.throw(_("Valid From Date must be lesser than Valid Upto Date."))
|
||||
frappe.throw(_("Valid From Date must be lesser than Valid Up To Date."))
|
||||
|
||||
def update_price_list_details(self):
|
||||
if self.price_list:
|
||||
|
@ -64,7 +64,7 @@ class TestItemPrice(FrappeTestCase):
|
||||
# Enter invalid dates valid_from >= valid_upto
|
||||
doc.valid_from = "2017-04-20"
|
||||
doc.valid_upto = "2017-04-17"
|
||||
# Valid Upto Date can not be less/equal than Valid From Date
|
||||
# Valid Up To Date can not be less/equal than Valid From Date
|
||||
self.assertRaises(frappe.ValidationError, doc.save)
|
||||
|
||||
def test_price_in_a_qty(self):
|
||||
|
@ -429,6 +429,9 @@ frappe.ui.form.on("Material Request Item", {
|
||||
|
||||
rate: function(frm, doctype, name) {
|
||||
const item = locals[doctype][name];
|
||||
item.amount = flt(item.qty) * flt(item.rate);
|
||||
frappe.model.set_value(doctype, name, "amount", item.amount);
|
||||
refresh_field("amount", item.name, item.parentfield);
|
||||
frm.events.get_item_data(frm, item, false);
|
||||
},
|
||||
|
||||
@ -514,6 +517,13 @@ erpnext.buying.MaterialRequestController = class MaterialRequestController exten
|
||||
schedule_date() {
|
||||
set_schedule_date(this.frm);
|
||||
}
|
||||
|
||||
qty(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
row.amount = flt(row.qty) * flt(row.rate);
|
||||
frappe.model.set_value(cdt, cdn, "amount", row.amount);
|
||||
refresh_field("amount", row.name, row.parentfield);
|
||||
}
|
||||
};
|
||||
|
||||
// for backward compatibility: combine new and previous states
|
||||
|
@ -776,7 +776,7 @@ def raise_work_orders(material_request):
|
||||
)
|
||||
else:
|
||||
msgprint(
|
||||
_("The {0} {1} created sucessfully").format(frappe.bold(_("Work Order")), work_orders_list[0])
|
||||
_("The {0} {1} created successfully").format(frappe.bold(_("Work Order")), work_orders_list[0])
|
||||
)
|
||||
|
||||
if errors:
|
||||
|
@ -24,7 +24,7 @@ frappe.listview_settings['Material Request'] = {
|
||||
} else if (doc.material_request_type == "Purchase") {
|
||||
return [__("Ordered"), "green", "per_ordered,=,100"];
|
||||
} else if (doc.material_request_type == "Material Transfer") {
|
||||
return [__("Transfered"), "green", "per_ordered,=,100"];
|
||||
return [__("Transferred"), "green", "per_ordered,=,100"];
|
||||
} else if (doc.material_request_type == "Material Issue") {
|
||||
return [__("Issued"), "green", "per_ordered,=,100"];
|
||||
} else if (doc.material_request_type == "Customer Provided") {
|
||||
|
@ -774,6 +774,62 @@ class TestMaterialRequest(FrappeTestCase):
|
||||
self.assertEqual(mr.per_ordered, 100)
|
||||
self.assertEqual(existing_requested_qty, current_requested_qty)
|
||||
|
||||
def test_auto_email_users_with_company_user_permissions(self):
|
||||
from erpnext.stock.reorder_item import get_email_list
|
||||
|
||||
comapnywise_users = {
|
||||
"_Test Company": "test_auto_email_@example.com",
|
||||
"_Test Company 1": "test_auto_email_1@example.com",
|
||||
}
|
||||
|
||||
permissions = []
|
||||
|
||||
for company, user in comapnywise_users.items():
|
||||
if not frappe.db.exists("User", user):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": user,
|
||||
"first_name": user,
|
||||
"send_notifications": 0,
|
||||
"enabled": 1,
|
||||
"user_type": "System User",
|
||||
"roles": [{"role": "Purchase Manager"}],
|
||||
}
|
||||
).insert(ignore_permissions=True)
|
||||
|
||||
if not frappe.db.exists(
|
||||
"User Permission", {"user": user, "allow": "Company", "for_value": company}
|
||||
):
|
||||
perm_doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "User Permission",
|
||||
"user": user,
|
||||
"allow": "Company",
|
||||
"for_value": company,
|
||||
"apply_to_all_doctypes": 1,
|
||||
}
|
||||
).insert(ignore_permissions=True)
|
||||
|
||||
permissions.append(perm_doc)
|
||||
|
||||
comapnywise_mr_list = frappe._dict({})
|
||||
mr1 = make_material_request()
|
||||
comapnywise_mr_list.setdefault(mr1.company, []).append(mr1.name)
|
||||
|
||||
mr2 = make_material_request(
|
||||
company="_Test Company 1", warehouse="Stores - _TC1", cost_center="Main - _TC1"
|
||||
)
|
||||
comapnywise_mr_list.setdefault(mr2.company, []).append(mr2.name)
|
||||
|
||||
for company, mr_list in comapnywise_mr_list.items():
|
||||
emails = get_email_list(company)
|
||||
|
||||
self.assertTrue(comapnywise_users[company] in emails)
|
||||
|
||||
for perm in permissions:
|
||||
perm.delete()
|
||||
|
||||
|
||||
def get_in_transit_warehouse(company):
|
||||
if not frappe.db.exists("Warehouse Type", "Transit"):
|
||||
|
@ -951,32 +951,32 @@ def update_billed_amount_based_on_po(po_details, update_modified=True, pr_doc=No
|
||||
billed_against_po = flt(po_billed_amt_details.get(pr_item.purchase_order_item))
|
||||
|
||||
# Get billed amount directly against Purchase Receipt
|
||||
billed_amt_agianst_pr = flt(pr_items_billed_amount.get(pr_item.name, 0))
|
||||
billed_amt_against_pr = flt(pr_items_billed_amount.get(pr_item.name, 0))
|
||||
|
||||
# Distribute billed amount directly against PO between PRs based on FIFO
|
||||
if billed_against_po and billed_amt_agianst_pr < pr_item.amount:
|
||||
pending_to_bill = flt(pr_item.amount) - billed_amt_agianst_pr
|
||||
if billed_against_po and billed_amt_against_pr < pr_item.amount:
|
||||
pending_to_bill = flt(pr_item.amount) - billed_amt_against_pr
|
||||
if pending_to_bill <= billed_against_po:
|
||||
billed_amt_agianst_pr += pending_to_bill
|
||||
billed_amt_against_pr += pending_to_bill
|
||||
billed_against_po -= pending_to_bill
|
||||
else:
|
||||
billed_amt_agianst_pr += billed_against_po
|
||||
billed_amt_against_pr += billed_against_po
|
||||
billed_against_po = 0
|
||||
|
||||
po_billed_amt_details[pr_item.purchase_order_item] = billed_against_po
|
||||
|
||||
if pr_item.billed_amt != billed_amt_agianst_pr:
|
||||
if pr_item.billed_amt != billed_amt_against_pr:
|
||||
# update existing doc if possible
|
||||
if pr_doc and pr_item.parent == pr_doc.name:
|
||||
pr_item = next((item for item in pr_doc.items if item.name == pr_item.name), None)
|
||||
pr_item.db_set("billed_amt", billed_amt_agianst_pr, update_modified=update_modified)
|
||||
pr_item.db_set("billed_amt", billed_amt_against_pr, update_modified=update_modified)
|
||||
|
||||
else:
|
||||
frappe.db.set_value(
|
||||
"Purchase Receipt Item",
|
||||
pr_item.name,
|
||||
"billed_amt",
|
||||
billed_amt_agianst_pr,
|
||||
billed_amt_against_pr,
|
||||
update_modified=update_modified,
|
||||
)
|
||||
|
||||
|
@ -8,8 +8,10 @@ frappe.listview_settings['Purchase Receipt'] = {
|
||||
return [__("Closed"), "green", "status,=,Closed"];
|
||||
} else if (flt(doc.per_returned, 2) === 100) {
|
||||
return [__("Return Issued"), "grey", "per_returned,=,100"];
|
||||
} else if (flt(doc.grand_total) !== 0 && flt(doc.per_billed, 2) < 100) {
|
||||
} else if (flt(doc.grand_total) !== 0 && flt(doc.per_billed, 2) == 0) {
|
||||
return [__("To Bill"), "orange", "per_billed,<,100"];
|
||||
} else if (flt(doc.per_billed, 2) > 0 && flt(doc.per_billed, 2) < 100) {
|
||||
return [__("Partly Billed"), "yellow", "per_billed,<,100"];
|
||||
} else if (flt(doc.grand_total) === 0 || flt(doc.per_billed, 2) === 100) {
|
||||
return [__("Completed"), "green", "per_billed,=,100"];
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle
|
||||
get_serial_nos_from_bundle,
|
||||
make_serial_batch_bundle,
|
||||
)
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
from erpnext.stock.stock_ledger import SerialNoExistsInFutureTransaction
|
||||
|
||||
|
||||
class TestPurchaseReceipt(FrappeTestCase):
|
||||
@ -722,7 +720,7 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
pr2.load_from_db()
|
||||
self.assertEqual(pr2.get("items")[0].billed_amt, 2000)
|
||||
self.assertEqual(pr2.per_billed, 80)
|
||||
self.assertEqual(pr2.status, "To Bill")
|
||||
self.assertEqual(pr2.status, "Partly Billed")
|
||||
|
||||
pr2.cancel()
|
||||
pi2.reload()
|
||||
@ -735,7 +733,6 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
po.cancel()
|
||||
|
||||
def test_serial_no_against_purchase_receipt(self):
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
|
||||
item_code = "Test Manual Created Serial No"
|
||||
if not frappe.db.exists("Item", item_code):
|
||||
@ -1020,6 +1017,11 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
def test_stock_transfer_from_purchase_receipt_with_valuation(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
|
||||
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
|
||||
create_stock_reconciliation,
|
||||
)
|
||||
from erpnext.stock.get_item_details import get_valuation_rate
|
||||
from erpnext.stock.utils import get_stock_balance
|
||||
|
||||
prepare_data_for_internal_transfer()
|
||||
|
||||
@ -1034,6 +1036,22 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
company="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
if (
|
||||
get_valuation_rate(
|
||||
pr1.items[0].item_code, "_Test Company with perpetual inventory", warehouse="Stores - TCP1"
|
||||
)
|
||||
!= 50
|
||||
):
|
||||
balance = get_stock_balance(item_code=pr1.items[0].item_code, warehouse="Stores - TCP1")
|
||||
create_stock_reconciliation(
|
||||
item_code=pr1.items[0].item_code,
|
||||
company="_Test Company with perpetual inventory",
|
||||
warehouse="Stores - TCP1",
|
||||
qty=balance,
|
||||
rate=50,
|
||||
do_not_save=True,
|
||||
)
|
||||
|
||||
customer = "_Test Internal Customer 2"
|
||||
company = "_Test Company with perpetual inventory"
|
||||
|
||||
@ -1071,7 +1089,8 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
sl_entries = get_sl_entries("Purchase Receipt", pr.name)
|
||||
|
||||
expected_gle = [
|
||||
["Stock In Hand - TCP1", 272.5, 0.0],
|
||||
["Stock In Hand - TCP1", 250.0, 0.0],
|
||||
["Cost of Goods Sold - TCP1", 22.5, 0.0],
|
||||
["_Test Account Stock In Hand - TCP1", 0.0, 250.0],
|
||||
["_Test Account Shipping Charges - TCP1", 0.0, 22.5],
|
||||
]
|
||||
@ -1133,7 +1152,7 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
pi.load_from_db()
|
||||
pr.load_from_db()
|
||||
|
||||
self.assertEqual(pr.status, "To Bill")
|
||||
self.assertEqual(pr.status, "Partly Billed")
|
||||
self.assertAlmostEqual(pr.per_billed, 50.0, places=2)
|
||||
|
||||
def test_purchase_receipt_with_exchange_rate_difference(self):
|
||||
@ -1656,9 +1675,10 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
make_stock_entry(
|
||||
purpose="Material Receipt",
|
||||
item_code=item.name,
|
||||
qty=15,
|
||||
qty=20,
|
||||
company=company,
|
||||
to_warehouse=from_warehouse,
|
||||
posting_date=add_days(today(), -3),
|
||||
)
|
||||
|
||||
# Step 3: Create Delivery Note with Internal Customer
|
||||
@ -1681,13 +1701,15 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
|
||||
|
||||
pr = make_inter_company_purchase_receipt(dn.name)
|
||||
pr.set_posting_time = 1
|
||||
pr.posting_date = today()
|
||||
pr.items[0].qty = 15
|
||||
pr.items[0].from_warehouse = target_warehouse
|
||||
pr.items[0].warehouse = to_warehouse
|
||||
pr.items[0].rejected_warehouse = from_warehouse
|
||||
pr.save()
|
||||
|
||||
self.assertRaises(OverAllowanceError, pr.submit)
|
||||
self.assertRaises(frappe.ValidationError, pr.submit)
|
||||
|
||||
# Step 5: Test Over Receipt Allowance
|
||||
frappe.db.set_single_value("Stock Settings", "over_delivery_receipt_allowance", 50)
|
||||
@ -1699,8 +1721,10 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
company=company,
|
||||
from_warehouse=from_warehouse,
|
||||
to_warehouse=target_warehouse,
|
||||
posting_date=add_days(pr.posting_date, -1),
|
||||
)
|
||||
|
||||
pr.reload()
|
||||
pr.submit()
|
||||
|
||||
frappe.db.set_single_value("Stock Settings", "over_delivery_receipt_allowance", 0)
|
||||
|
@ -250,6 +250,7 @@ class SerialandBatchBundle(Document):
|
||||
|
||||
for d in self.entries:
|
||||
available_qty = 0
|
||||
|
||||
if self.has_serial_no:
|
||||
d.incoming_rate = abs(sn_obj.serial_no_incoming_rate.get(d.serial_no, 0.0))
|
||||
else:
|
||||
@ -892,6 +893,13 @@ class SerialandBatchBundle(Document):
|
||||
elif batch_nos:
|
||||
self.set("entries", batch_nos)
|
||||
|
||||
def delete_serial_batch_entries(self):
|
||||
SBBE = frappe.qb.DocType("Serial and Batch Entry")
|
||||
|
||||
frappe.qb.from_(SBBE).delete().where(SBBE.parent == self.name).run()
|
||||
|
||||
self.set("entries", [])
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_blank_csv_template(content):
|
||||
@ -1374,10 +1382,12 @@ def get_available_serial_nos(kwargs):
|
||||
elif kwargs.based_on == "Expiry":
|
||||
order_by = "amc_expiry_date asc"
|
||||
|
||||
filters = {"item_code": kwargs.item_code, "warehouse": ("is", "set")}
|
||||
filters = {"item_code": kwargs.item_code}
|
||||
|
||||
if kwargs.warehouse:
|
||||
filters["warehouse"] = kwargs.warehouse
|
||||
if not kwargs.get("ignore_warehouse"):
|
||||
filters["warehouse"] = ("is", "set")
|
||||
if kwargs.warehouse:
|
||||
filters["warehouse"] = kwargs.warehouse
|
||||
|
||||
# Since SLEs are not present against Reserved Stock [POS invoices, SRE], need to ignore reserved serial nos.
|
||||
ignore_serial_nos = get_reserved_serial_nos(kwargs)
|
||||
|
@ -228,7 +228,6 @@ class StockEntry(StockController):
|
||||
self.fg_completed_qty = 0.0
|
||||
|
||||
self.validate_serialized_batch()
|
||||
self.set_actual_qty()
|
||||
self.calculate_rate_and_amount()
|
||||
self.validate_putaway_capacity()
|
||||
|
||||
@ -640,7 +639,7 @@ class StockEntry(StockController):
|
||||
frappe.throw(_("Source and target warehouse cannot be same for row {0}").format(d.idx))
|
||||
|
||||
if not (d.s_warehouse or d.t_warehouse):
|
||||
frappe.throw(_("Atleast one warehouse is mandatory"))
|
||||
frappe.throw(_("At least one warehouse is mandatory"))
|
||||
|
||||
def validate_work_order(self):
|
||||
if self.purpose in (
|
||||
|
@ -156,6 +156,7 @@ class StockReconciliation(StockController):
|
||||
"warehouse": item.warehouse,
|
||||
"posting_date": self.posting_date,
|
||||
"posting_time": self.posting_time,
|
||||
"ignore_warehouse": 1,
|
||||
}
|
||||
)
|
||||
)
|
||||
@ -780,7 +781,20 @@ class StockReconciliation(StockController):
|
||||
|
||||
current_qty = 0.0
|
||||
if row.current_serial_and_batch_bundle:
|
||||
current_qty = self.get_qty_for_serial_and_batch_bundle(row)
|
||||
current_qty = self.get_current_qty_for_serial_or_batch(row)
|
||||
elif row.serial_no:
|
||||
item_dict = get_stock_balance_for(
|
||||
row.item_code,
|
||||
row.warehouse,
|
||||
self.posting_date,
|
||||
self.posting_time,
|
||||
voucher_no=self.name,
|
||||
)
|
||||
|
||||
current_qty = item_dict.get("qty")
|
||||
row.current_serial_no = item_dict.get("serial_nos")
|
||||
row.current_valuation_rate = item_dict.get("rate")
|
||||
val_rate = item_dict.get("rate")
|
||||
elif row.batch_no:
|
||||
current_qty = get_batch_qty_for_stock_reco(
|
||||
row.item_code, row.warehouse, row.batch_no, self.posting_date, self.posting_time, self.name
|
||||
@ -788,15 +802,16 @@ class StockReconciliation(StockController):
|
||||
|
||||
precesion = row.precision("current_qty")
|
||||
if flt(current_qty, precesion) != flt(row.current_qty, precesion):
|
||||
val_rate = get_valuation_rate(
|
||||
row.item_code,
|
||||
row.warehouse,
|
||||
self.doctype,
|
||||
self.name,
|
||||
company=self.company,
|
||||
batch_no=row.batch_no,
|
||||
serial_and_batch_bundle=row.current_serial_and_batch_bundle,
|
||||
)
|
||||
if not row.serial_no:
|
||||
val_rate = get_valuation_rate(
|
||||
row.item_code,
|
||||
row.warehouse,
|
||||
self.doctype,
|
||||
self.name,
|
||||
company=self.company,
|
||||
batch_no=row.batch_no,
|
||||
serial_and_batch_bundle=row.current_serial_and_batch_bundle,
|
||||
)
|
||||
|
||||
row.current_valuation_rate = val_rate
|
||||
row.current_qty = current_qty
|
||||
@ -842,11 +857,56 @@ class StockReconciliation(StockController):
|
||||
|
||||
return allow_negative_stock
|
||||
|
||||
def get_qty_for_serial_and_batch_bundle(self, row):
|
||||
def get_current_qty_for_serial_or_batch(self, row):
|
||||
doc = frappe.get_doc("Serial and Batch Bundle", row.current_serial_and_batch_bundle)
|
||||
precision = doc.entries[0].precision("qty")
|
||||
current_qty = 0.0
|
||||
if doc.has_serial_no:
|
||||
current_qty = self.get_current_qty_for_serial_nos(doc)
|
||||
elif doc.has_batch_no:
|
||||
current_qty = self.get_current_qty_for_batch_nos(doc)
|
||||
|
||||
current_qty = 0
|
||||
return abs(current_qty)
|
||||
|
||||
def get_current_qty_for_serial_nos(self, doc):
|
||||
serial_nos_details = get_available_serial_nos(
|
||||
frappe._dict(
|
||||
{
|
||||
"item_code": doc.item_code,
|
||||
"warehouse": doc.warehouse,
|
||||
"posting_date": self.posting_date,
|
||||
"posting_time": self.posting_time,
|
||||
"voucher_no": self.name,
|
||||
"ignore_warehouse": 1,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
if not serial_nos_details:
|
||||
return 0.0
|
||||
|
||||
doc.delete_serial_batch_entries()
|
||||
current_qty = 0.0
|
||||
for serial_no_row in serial_nos_details:
|
||||
current_qty += 1
|
||||
doc.append(
|
||||
"entries",
|
||||
{
|
||||
"serial_no": serial_no_row.serial_no,
|
||||
"qty": -1,
|
||||
"warehouse": doc.warehouse,
|
||||
"batch_no": serial_no_row.batch_no,
|
||||
},
|
||||
)
|
||||
|
||||
doc.set_incoming_rate(save=True)
|
||||
doc.calculate_qty_and_amount(save=True)
|
||||
doc.db_update_all()
|
||||
|
||||
return current_qty
|
||||
|
||||
def get_current_qty_for_batch_nos(self, doc):
|
||||
current_qty = 0.0
|
||||
precision = doc.entries[0].precision("qty")
|
||||
for d in doc.entries:
|
||||
qty = (
|
||||
get_batch_qty(
|
||||
@ -864,7 +924,7 @@ class StockReconciliation(StockController):
|
||||
|
||||
current_qty += qty
|
||||
|
||||
return abs(current_qty)
|
||||
return current_qty
|
||||
|
||||
|
||||
def get_batch_qty_for_stock_reco(
|
||||
|
@ -925,6 +925,74 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
|
||||
|
||||
self.assertEqual(len(serial_batch_bundle), 0)
|
||||
|
||||
def test_backdated_purchase_receipt_with_stock_reco(self):
|
||||
item_code = self.make_item(
|
||||
properties={
|
||||
"is_stock_item": 1,
|
||||
"has_serial_no": 1,
|
||||
"serial_no_series": "TEST-SERIAL-.###",
|
||||
}
|
||||
).name
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
|
||||
# Step - 1: Create a Backdated Purchase Receipt
|
||||
|
||||
pr1 = make_purchase_receipt(
|
||||
item_code=item_code, warehouse=warehouse, qty=10, rate=100, posting_date=add_days(nowdate(), -3)
|
||||
)
|
||||
pr1.reload()
|
||||
|
||||
serial_nos = sorted(get_serial_nos_from_bundle(pr1.items[0].serial_and_batch_bundle))[:5]
|
||||
|
||||
# Step - 2: Create a Stock Reconciliation
|
||||
sr1 = create_stock_reconciliation(
|
||||
item_code=item_code,
|
||||
warehouse=warehouse,
|
||||
qty=5,
|
||||
serial_no=serial_nos,
|
||||
)
|
||||
|
||||
data = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
fields=["serial_no", "actual_qty", "stock_value_difference"],
|
||||
filters={"voucher_no": sr1.name, "is_cancelled": 0},
|
||||
order_by="creation",
|
||||
)
|
||||
|
||||
for d in data:
|
||||
if d.actual_qty < 0:
|
||||
self.assertEqual(d.actual_qty, -10.0)
|
||||
self.assertAlmostEqual(d.stock_value_difference, -1000.0)
|
||||
else:
|
||||
self.assertEqual(d.actual_qty, 5.0)
|
||||
self.assertAlmostEqual(d.stock_value_difference, 500.0)
|
||||
|
||||
# Step - 3: Create a Purchase Receipt before the first Purchase Receipt
|
||||
make_purchase_receipt(
|
||||
item_code=item_code, warehouse=warehouse, qty=10, rate=200, posting_date=add_days(nowdate(), -5)
|
||||
)
|
||||
|
||||
data = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
fields=["serial_no", "actual_qty", "stock_value_difference"],
|
||||
filters={"voucher_no": sr1.name, "is_cancelled": 0},
|
||||
order_by="creation",
|
||||
)
|
||||
|
||||
for d in data:
|
||||
if d.actual_qty < 0:
|
||||
self.assertEqual(d.actual_qty, -20.0)
|
||||
self.assertAlmostEqual(d.stock_value_difference, -3000.0)
|
||||
else:
|
||||
self.assertEqual(d.actual_qty, 5.0)
|
||||
self.assertAlmostEqual(d.stock_value_difference, 500.0)
|
||||
|
||||
active_serial_no = frappe.get_all(
|
||||
"Serial No", filters={"status": "Active", "item_code": item_code}
|
||||
)
|
||||
self.assertEqual(len(active_serial_no), 5)
|
||||
|
||||
|
||||
def create_batch_item_with_batch(item_name, batch_id):
|
||||
batch_item_doc = create_item(item_name, is_stock_item=1)
|
||||
|
@ -176,7 +176,7 @@
|
||||
"description": "No stock transactions can be created or modified before this date.",
|
||||
"fieldname": "stock_frozen_upto",
|
||||
"fieldtype": "Date",
|
||||
"label": "Stock Frozen Upto"
|
||||
"label": "Stock Frozen Up To"
|
||||
},
|
||||
{
|
||||
"description": "Stock transactions that are older than the mentioned days cannot be modified.",
|
||||
@ -427,7 +427,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-18 12:35:30.068799",
|
||||
"modified": "2024-01-24 02:20:26.145996",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Stock Settings",
|
||||
|
@ -145,6 +145,7 @@ def create_material_request(material_requests):
|
||||
|
||||
mr.log_error("Unable to create material request")
|
||||
|
||||
company_wise_mr = frappe._dict({})
|
||||
for request_type in material_requests:
|
||||
for company in material_requests[request_type]:
|
||||
try:
|
||||
@ -206,17 +207,19 @@ def create_material_request(material_requests):
|
||||
mr.submit()
|
||||
mr_list.append(mr)
|
||||
|
||||
company_wise_mr.setdefault(company, []).append(mr)
|
||||
|
||||
except Exception:
|
||||
_log_exception(mr)
|
||||
|
||||
if mr_list:
|
||||
if company_wise_mr:
|
||||
if getattr(frappe.local, "reorder_email_notify", None) is None:
|
||||
frappe.local.reorder_email_notify = cint(
|
||||
frappe.db.get_single_value("Stock Settings", "reorder_email_notify")
|
||||
)
|
||||
|
||||
if frappe.local.reorder_email_notify:
|
||||
send_email_notification(mr_list)
|
||||
send_email_notification(company_wise_mr)
|
||||
|
||||
if exceptions_list:
|
||||
notify_errors(exceptions_list)
|
||||
@ -224,20 +227,56 @@ def create_material_request(material_requests):
|
||||
return mr_list
|
||||
|
||||
|
||||
def send_email_notification(mr_list):
|
||||
def send_email_notification(company_wise_mr):
|
||||
"""Notify user about auto creation of indent"""
|
||||
|
||||
email_list = frappe.db.sql_list(
|
||||
"""select distinct r.parent
|
||||
from `tabHas Role` r, tabUser p
|
||||
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
||||
and r.role in ('Purchase Manager','Stock Manager')
|
||||
and p.name not in ('Administrator', 'All', 'Guest')"""
|
||||
for company, mr_list in company_wise_mr.items():
|
||||
email_list = get_email_list(company)
|
||||
|
||||
if not email_list:
|
||||
continue
|
||||
|
||||
msg = frappe.render_template("templates/emails/reorder_item.html", {"mr_list": mr_list})
|
||||
|
||||
frappe.sendmail(
|
||||
recipients=email_list, subject=_("Auto Material Requests Generated"), message=msg
|
||||
)
|
||||
|
||||
|
||||
def get_email_list(company):
|
||||
users = get_comapny_wise_users(company)
|
||||
user_table = frappe.qb.DocType("User")
|
||||
role_table = frappe.qb.DocType("Has Role")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(user_table)
|
||||
.inner_join(role_table)
|
||||
.on(user_table.name == role_table.parent)
|
||||
.select(user_table.email)
|
||||
.where(
|
||||
(role_table.role.isin(["Purchase Manager", "Stock Manager"]))
|
||||
& (user_table.name.notin(["Administrator", "All", "Guest"]))
|
||||
& (user_table.enabled == 1)
|
||||
& (user_table.docstatus < 2)
|
||||
)
|
||||
)
|
||||
|
||||
msg = frappe.render_template("templates/emails/reorder_item.html", {"mr_list": mr_list})
|
||||
if users:
|
||||
query = query.where(user_table.name.isin(users))
|
||||
|
||||
frappe.sendmail(recipients=email_list, subject=_("Auto Material Requests Generated"), message=msg)
|
||||
emails = query.run(as_dict=True)
|
||||
|
||||
return list(set([email.email for email in emails]))
|
||||
|
||||
|
||||
def get_comapny_wise_users(company):
|
||||
users = frappe.get_all(
|
||||
"User Permission",
|
||||
filters={"allow": "Company", "for_value": company, "apply_to_all_doctypes": 1},
|
||||
fields=["user"],
|
||||
)
|
||||
|
||||
return [user.user for user in users]
|
||||
|
||||
|
||||
def notify_errors(exceptions_list):
|
||||
@ -246,7 +285,7 @@ def notify_errors(exceptions_list):
|
||||
_("Dear System Manager,")
|
||||
+ "<br>"
|
||||
+ _(
|
||||
"An error occured for certain Items while creating Material Requests based on Re-order level. Please rectify these issues :"
|
||||
"An error occurred for certain Items while creating Material Requests based on Re-order level. Please rectify these issues :"
|
||||
)
|
||||
+ "<br>"
|
||||
)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user