Skip to content

Commit

Permalink
Merge branch 'develop' into move_taxjar_integration_new
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 committed Nov 23, 2022
2 parents 454b598 + a3c81da commit 3559fa7
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 65 deletions.
3 changes: 0 additions & 3 deletions erpnext/accounts/doctype/journal_entry/journal_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro
var party_account_field = jvd.reference_type==="Sales Invoice" ? "debit_to": "credit_to";
out.filters.push([jvd.reference_type, party_account_field, "=", jvd.account]);

if (in_list(['Debit Note', 'Credit Note'], doc.voucher_type)) {
out.filters.push([jvd.reference_type, "is_return", "=", 1]);
}
}

if(in_list(["Sales Order", "Purchase Order"], jvd.reference_type)) {
Expand Down
4 changes: 2 additions & 2 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
}

if(doc.docstatus == 1 && doc.outstanding_amount != 0
&& !(doc.is_return && doc.return_against)) {
&& !(doc.is_return && doc.return_against) && !doc.on_hold) {
this.frm.add_custom_button(__('Payment'), this.make_payment_entry, __('Create'));
cur_frm.page.set_inner_btn_group_as_primary(__('Create'));
}
Expand All @@ -99,7 +99,7 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
}
}

if (doc.outstanding_amount > 0 && !cint(doc.is_return)) {
if (doc.outstanding_amount > 0 && !cint(doc.is_return) && !doc.on_hold) {
cur_frm.add_custom_button(__('Payment Request'), function() {
me.make_payment_request()
}, __('Create'));
Expand Down
10 changes: 5 additions & 5 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"apply_tds",
"tax_withholding_category",
"amended_from",
"supplier_invoice_details",
"bill_no",
"column_break_15",
"bill_date",
"accounting_dimensions_section",
"cost_center",
"dimension_col_break",
Expand Down Expand Up @@ -151,10 +155,6 @@
"status",
"column_break_177",
"per_received",
"supplier_invoice_details",
"bill_no",
"column_break_15",
"bill_date",
"accounting_details_section",
"credit_to",
"party_account_currency",
Expand Down Expand Up @@ -1540,7 +1540,7 @@
"idx": 204,
"is_submittable": 1,
"links": [],
"modified": "2022-11-04 01:02:44.544878",
"modified": "2022-11-22 12:44:29.935567",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,42 @@ def test_tds_calculation_on_net_total_partial_tds(self):
for d in reversed(invoices):
d.cancel()

orders = []

po = create_purchase_order(supplier="Test TDS Supplier4", rate=20000, do_not_save=True)
po.extend(
"items",
[
{
"doctype": "Purchase Order Item",
"item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"),
"qty": 1,
"rate": 20000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
"apply_tds": 0,
},
{
"doctype": "Purchase Order Item",
"item_code": frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name"),
"qty": 1,
"rate": 35000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
"apply_tds": 1,
},
],
)
po.save()
po.submit()
orders.append(po)

self.assertEqual(po.taxes[0].tax_amount, 5500)

# cancel orders to avoid clashing
for d in reversed(orders):
d.cancel()

def test_multi_category_single_supplier(self):
frappe.db.set_value(
"Supplier", "Test TDS Supplier5", "tax_withholding_category", "Test Service Category"
Expand Down Expand Up @@ -348,6 +384,39 @@ def create_purchase_invoice(**args):
return pi


def create_purchase_order(**args):
# return purchase order doc object
item = frappe.db.get_value("Item", {"item_name": "TDS Item"}, "name")

args = frappe._dict(args)
po = frappe.get_doc(
{
"doctype": "Purchase Order",
"transaction_date": today(),
"schedule_date": today(),
"apply_tds": 0 if args.do_not_apply_tds else 1,
"supplier": args.supplier,
"company": "_Test Company",
"taxes_and_charges": "",
"currency": "INR",
"taxes": [],
"items": [
{
"doctype": "Purchase Order Item",
"item_code": item,
"qty": args.qty or 1,
"rate": args.rate or 10000,
"cost_center": "Main - _TC",
"expense_account": "Stock Received But Not Billed - _TC",
}
],
}
)

po.save()
return po


def create_sales_invoice(**args):
# return sales invoice doc object
item = frappe.db.get_value("Item", {"item_name": "TCS Item"}, "name")
Expand Down
29 changes: 15 additions & 14 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,22 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(
gl_map[0].company, gl_map[0].voucher_type, gl_map[0].voucher_no
)
round_off_account_exists = False
round_off_gle = frappe._dict()
for d in gl_map:
if d.account == round_off_account:
round_off_gle = d
if d.debit:
debit_credit_diff -= flt(d.debit)
else:
debit_credit_diff += flt(d.credit)
round_off_account_exists = True

if round_off_account_exists and abs(debit_credit_diff) < (1.0 / (10**precision)):
gl_map.remove(round_off_gle)
return
round_off_account_exists = False

if gl_map[0].voucher_type != "Period Closing Voucher":
for d in gl_map:
if d.account == round_off_account:
round_off_gle = d
if d.debit:
debit_credit_diff -= flt(d.debit) - flt(d.credit)
else:
debit_credit_diff += flt(d.credit)
round_off_account_exists = True

if round_off_account_exists and abs(debit_credit_diff) < (1.0 / (10**precision)):
gl_map.remove(round_off_gle)
return

if not round_off_gle:
for k in ["voucher_type", "voucher_no", "company", "posting_date", "remarks"]:
Expand All @@ -430,7 +432,6 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
)

update_accounting_dimensions(round_off_gle)

if not round_off_account_exists:
gl_map.append(round_off_gle)

Expand Down
22 changes: 22 additions & 0 deletions erpnext/buying/doctype/purchase_order/purchase_order.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"column_break_26",
"total",
"net_total",
"tax_withholding_net_total",
"base_tax_withholding_net_total",
"section_break_48",
"pricing_rules",
"raw_material_details",
Expand Down Expand Up @@ -1220,6 +1222,26 @@
"label": "Additional Info",
"oldfieldtype": "Section Break"
},
{
"default": "0",
"fieldname": "tax_withholding_net_total",
"fieldtype": "Currency",
"hidden": 1,
"label": "Tax Withholding Net Total",
"no_copy": 1,
"options": "currency",
"read_only": 1
},
{
"fieldname": "base_tax_withholding_net_total",
"fieldtype": "Currency",
"hidden": 1,
"label": "Base Tax Withholding Net Total",
"no_copy": 1,
"options": "currency",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_99",
"fieldtype": "Column Break"
Expand Down
20 changes: 11 additions & 9 deletions erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,27 +736,29 @@ def test_advance_payment_entry_unlink_against_purchase_order(self):
def test_advance_paid_upon_payment_entry_cancellation(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry

po_doc = create_purchase_order()

pe = get_payment_entry("Purchase Order", po_doc.name, bank_account="_Test Bank - _TC")
pe.reference_no = "1"
pe.reference_date = nowdate()
pe.paid_from_account_currency = po_doc.currency
pe.paid_to_account_currency = po_doc.currency
pe.source_exchange_rate = 1
po_doc = create_purchase_order(supplier="_Test Supplier USD", currency="USD", do_not_submit=1)
po_doc.conversion_rate = 80
po_doc.submit()

pe = get_payment_entry("Purchase Order", po_doc.name)
pe.mode_of_payment = "Cash"
pe.paid_from = "Cash - _TC"
pe.source_exchange_rate = 80
pe.target_exchange_rate = 1
pe.paid_amount = po_doc.grand_total
pe.save(ignore_permissions=True)
pe.submit()

po_doc.reload()
self.assertEqual(po_doc.advance_paid, po_doc.base_grand_total)
self.assertEqual(po_doc.advance_paid, po_doc.grand_total)
self.assertEqual(po_doc.party_account_currency, "USD")

pe_doc = frappe.get_doc("Payment Entry", pe.name)
pe_doc.cancel()

po_doc.reload()
self.assertEqual(po_doc.advance_paid, 0)
self.assertEqual(po_doc.party_account_currency, "USD")

def test_schedule_date(self):
po = create_purchase_order(do_not_submit=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"discount_amount",
"base_rate_with_margin",
"sec_break2",
"apply_tds",
"rate",
"amount",
"item_tax_template",
Expand Down Expand Up @@ -889,6 +890,12 @@
{
"fieldname": "column_break_54",
"fieldtype": "Column Break"
},
{
"default": "1",
"fieldname": "apply_tds",
"fieldtype": "Check",
"label": "Apply TDS"
}
],
"idx": 1,
Expand Down
4 changes: 2 additions & 2 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,12 @@ def set_total_advance_paid(self):
party = self.customer if self.doctype == "Sales Order" else self.supplier
advance = (
frappe.qb.from_(ple)
.select(ple.account_currency, Abs(Sum(ple.amount)).as_("amount"))
.select(ple.account_currency, Abs(Sum(ple.amount_in_account_currency)).as_("amount"))
.where(
(ple.against_voucher_type == self.doctype)
& (ple.against_voucher_no == self.name)
& (ple.party == party)
& (ple.delinked == 0)
& (ple.docstatus == 1)
& (ple.company == self.company)
)
.run(as_dict=True)
Expand Down
2 changes: 1 addition & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@ erpnext.patches.v14_0.fix_subcontracting_receipt_gl_entries
erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger
erpnext.patches.v13_0.update_schedule_type_in_loans
erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
erpnext.patches.v14_0.update_tds_fields
erpnext.patches.v14_0.update_partial_tds_fields
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,21 @@ def execute():
).where(
purchase_invoice.docstatus == 1
).run()

purchase_order = frappe.qb.DocType("Purchase Order")

frappe.qb.update(purchase_order).set(
purchase_order.tax_withholding_net_total, purchase_order.net_total
).set(
purchase_order.base_tax_withholding_net_total, purchase_order.base_net_total
).where(
purchase_order.company == company.name
).where(
purchase_order.apply_tds == 1
).where(
purchase_order.transaction_date >= fiscal_year_details.year_start_date
).where(
purchase_order.docstatus == 1
).run()
except FiscalYearError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ frappe.ui.form.on('Inventory Dimension', {
if (r.message && r.message.length) {
frm.set_df_property("fetch_from_parent", "options",
[""].concat(r.message));
} else {
frm.set_df_property("fetch_from_parent", "hidden", 1);
}
}
});
Expand Down
Loading

0 comments on commit 3559fa7

Please sign in to comment.