Skip to content

Commit

Permalink
Merge branch 'develop' into crm-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
anupamvs authored Nov 23, 2021
2 parents bf9e0a7 + 5ef2330 commit 5689c5d
Show file tree
Hide file tree
Showing 63 changed files with 1,364 additions and 1,079 deletions.
3 changes: 2 additions & 1 deletion erpnext/accounts/doctype/account/account_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ frappe.treeview_settings["Account"] = {
const format = (value, currency) => format_currency(Math.abs(value), currency);

if (account.balance!==undefined) {
node.parent && node.parent.find('.balance-area').remove();
$('<span class="balance-area pull-right">'
+ (account.balance_in_account_currency ?
(format(account.balance_in_account_currency, account.account_currency) + " / ") : "")
Expand Down Expand Up @@ -175,7 +176,7 @@ frappe.treeview_settings["Account"] = {
&& node.expandable && !node.hide_add;
},
click: function() {
var me = frappe.treeview_settings['Account'].treeview;
var me = frappe.views.trees['Account'];
me.new_node();
},
btnClass: "hidden-xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def validate(self):
frappe.db.set_default("add_taxes_from_item_tax_template",
self.get("add_taxes_from_item_tax_template", 0))

frappe.db.set_default("enable_common_party_accounting",
self.get("enable_common_party_accounting", 0))

self.validate_stale_days()
self.enable_payment_schedule_in_print()
self.toggle_discount_accounting_fields()
Expand Down
14 changes: 14 additions & 0 deletions erpnext/accounts/doctype/party_link/party_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ def validate(self):
if existing_party_link:
frappe.throw(_('{} {} is already linked with another {}')
.format(self.primary_role, self.primary_party, existing_party_link[0]))


@frappe.whitelist()
def create_party_link(primary_role, primary_party, secondary_party):
party_link = frappe.new_doc('Party Link')
party_link.primary_role = primary_role
party_link.primary_party = primary_party
party_link.secondary_role = 'Customer' if primary_role == 'Supplier' else 'Supplier'
party_link.secondary_party = secondary_party

party_link.save(ignore_permissions=True)

return party_link

14 changes: 9 additions & 5 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,14 @@ def set_missing_values(source, target):

return doclist

def validate_payment(doc, method=""):
if not frappe.db.has_column(doc.reference_doctype, 'status'):
def validate_payment(doc, method=None):
if doc.reference_doctype != "Payment Request" or (
frappe.db.get_value(doc.reference_doctype, doc.reference_docname, 'status')
!= "Paid"
):
return

status = frappe.db.get_value(doc.reference_doctype, doc.reference_docname, 'status')
if status == 'Paid':
frappe.throw(_("The Payment Request {0} is already paid, cannot process payment twice").format(doc.reference_docname))
frappe.throw(
_("The Payment Request {0} is already paid, cannot process payment twice")
.format(doc.reference_docname)
)
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def get_pnl_gl_entry(self, pl_accounts):

for acc in pl_accounts:
if flt(acc.bal_in_company_currency):
cost_center = acc.cost_center if self.cost_center_wise_pnl else company_cost_center
gl_entry = self.get_gl_dict({
"account": self.closing_account_head,
"cost_center": acc.cost_center or company_cost_center,
"cost_center": cost_center,
"finance_book": acc.finance_book,
"account_currency": acc.account_currency,
"debit_in_account_currency": abs(flt(acc.bal_in_account_currency)) if flt(acc.bal_in_account_currency) > 0 else 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def test_cost_center_wise_posting(self):
company = create_company()
surplus_account = create_account()

cost_center1 = create_cost_center("Test Cost Center 1")
cost_center2 = create_cost_center("Test Cost Center 2")
cost_center1 = create_cost_center("Main")
cost_center2 = create_cost_center("Western Branch")

create_sales_invoice(
company=company,
Expand All @@ -86,7 +86,10 @@ def test_cost_center_wise_posting(self):
debit_to="Debtors - TPC"
)

pcv = self.make_period_closing_voucher()
pcv = self.make_period_closing_voucher(submit=False)
pcv.cost_center_wise_pnl = 1
pcv.save()
pcv.submit()
surplus_account = pcv.closing_account_head

expected_gle = (
Expand Down Expand Up @@ -149,7 +152,7 @@ def test_period_closing_with_finance_book_entries(self):

self.assertEqual(pcv_gle, expected_gle)

def make_period_closing_voucher(self):
def make_period_closing_voucher(self, submit=True):
surplus_account = create_account()
cost_center = create_cost_center("Test Cost Center 1")
pcv = frappe.get_doc({
Expand All @@ -163,7 +166,8 @@ def make_period_closing_voucher(self):
"remarks": "test"
})
pcv.insert()
pcv.submit()
if submit:
pcv.submit()

return pcv

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ def process_merging_into_credit_note(self, data):

def merge_pos_invoice_into(self, invoice, data):
items, payments, taxes = [], [], []

loyalty_amount_sum, loyalty_points_sum = 0, 0

rounding_adjustment, base_rounding_adjustment = 0, 0
rounded_total, base_rounded_total = 0, 0

loyalty_amount_sum, loyalty_points_sum, idx = 0, 0, 1


for doc in data:
map_doc(doc, invoice, table_map={ "doctype": invoice.doctype })

Expand Down Expand Up @@ -146,6 +152,8 @@ def merge_pos_invoice_into(self, invoice, data):
found = True
if not found:
tax.charge_type = 'Actual'
tax.idx = idx
idx += 1
tax.included_in_print_rate = 0
tax.tax_amount = tax.tax_amount_after_discount_amount
tax.base_tax_amount = tax.base_tax_amount_after_discount_amount
Expand All @@ -163,8 +171,8 @@ def merge_pos_invoice_into(self, invoice, data):
payments.append(payment)
rounding_adjustment += doc.rounding_adjustment
rounded_total += doc.rounded_total
base_rounding_adjustment += doc.rounding_adjustment
base_rounded_total += doc.rounded_total
base_rounding_adjustment += doc.base_rounding_adjustment
base_rounded_total += doc.base_rounded_total


if loyalty_points_sum:
Expand All @@ -176,9 +184,9 @@ def merge_pos_invoice_into(self, invoice, data):
invoice.set('payments', payments)
invoice.set('taxes', taxes)
invoice.set('rounding_adjustment',rounding_adjustment)
invoice.set('rounding_adjustment',base_rounding_adjustment)
invoice.set('base_rounded_total',base_rounded_total)
invoice.set('base_rounding_adjustment',base_rounding_adjustment)
invoice.set('rounded_total',rounded_total)
invoice.set('base_rounded_total',base_rounded_total)
invoice.additional_discount_percentage = 0
invoice.discount_amount = 0.0
invoice.taxes_and_charges = None
Expand Down
69 changes: 69 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,75 @@ def test_item_price_with_pricing_rule(self):
frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete()
item.delete()

def test_pricing_rule_for_different_currency(self):
make_item("Test Sanitizer Item")

pricing_rule_record = {
"doctype": "Pricing Rule",
"title": "_Test Sanitizer Rule",
"apply_on": "Item Code",
"items": [{
"item_code": "Test Sanitizer Item",
}],
"selling": 1,
"currency": "INR",
"rate_or_discount": "Rate",
"rate": 0,
"priority": 2,
"margin_type": "Percentage",
"margin_rate_or_amount": 0.0,
"company": "_Test Company"
}

rule = frappe.get_doc(pricing_rule_record)
rule.rate_or_discount = 'Rate'
rule.rate = 100.0
rule.insert()

rule1 = frappe.get_doc(pricing_rule_record)
rule1.currency = 'USD'
rule1.rate_or_discount = 'Rate'
rule1.rate = 2.0
rule1.priority = 1
rule1.insert()

args = frappe._dict({
"item_code": "Test Sanitizer Item",
"company": "_Test Company",
"price_list": "_Test Price List",
"currency": "USD",
"doctype": "Sales Invoice",
"conversion_rate": 1,
"price_list_currency": "_Test Currency",
"plc_conversion_rate": 1,
"order_type": "Sales",
"customer": "_Test Customer",
"name": None,
"transaction_date": frappe.utils.nowdate()
})

details = get_item_details(args)
self.assertEqual(details.price_list_rate, 2.0)


args = frappe._dict({
"item_code": "Test Sanitizer Item",
"company": "_Test Company",
"price_list": "_Test Price List",
"currency": "INR",
"doctype": "Sales Invoice",
"conversion_rate": 1,
"price_list_currency": "_Test Currency",
"plc_conversion_rate": 1,
"order_type": "Sales",
"customer": "_Test Customer",
"name": None,
"transaction_date": frappe.utils.nowdate()
})

details = get_item_details(args)
self.assertEqual(details.price_list_rate, 100.0)

def test_pricing_rule_for_transaction(self):
make_item("Water Flask 1")
frappe.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule')
Expand Down
5 changes: 5 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def filter_pricing_rules(args, pricing_rules, doc=None):
else:
p.variant_of = None

if len(pricing_rules) > 1:
filtered_rules = list(filter(lambda x: x.currency==args.get('currency'), pricing_rules))
if filtered_rules:
pricing_rules = filtered_rules

# find pricing rule with highest priority
if pricing_rules:
max_priority = max(cint(p.priority) for p in pricing_rules)
Expand Down
43 changes: 24 additions & 19 deletions erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
from erpnext.controllers.accounts_controller import get_payment_terms
from erpnext.controllers.buying_controller import QtyMismatchError
from erpnext.exceptions import InvalidCurrency
from erpnext.projects.doctype.project.test_project import make_project
from erpnext.stock.doctype.item.test_item import create_item
Expand All @@ -35,6 +36,27 @@ def setUpClass(self):
def tearDownClass(self):
unlink_payment_on_cancel_of_invoice(0)

def test_purchase_invoice_received_qty(self):
"""
1. Test if received qty is validated against accepted + rejected
2. Test if received qty is auto set on save
"""
pi = make_purchase_invoice(
qty=1,
rejected_qty=1,
received_qty=3,
item_code="_Test Item Home Desktop 200",
rejected_warehouse = "_Test Rejected Warehouse - _TC",
update_stock=True, do_not_save=True)
self.assertRaises(QtyMismatchError, pi.save)

pi.items[0].received_qty = 0
pi.save()
self.assertEqual(pi.items[0].received_qty, 2)

# teardown
pi.delete()

def test_gl_entries_without_perpetual_inventory(self):
frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
pi = frappe.copy_doc(test_records[0])
Expand Down Expand Up @@ -811,29 +833,12 @@ def test_purchase_invoice_with_shipping_rule(self):

pi.shipping_rule = shipping_rule.name
pi.insert()

shipping_amount = 0.0
for condition in shipping_rule.get("conditions"):
if not condition.to_value or (flt(condition.from_value) <= pi.net_total <= flt(condition.to_value)):
shipping_amount = condition.shipping_amount

shipping_charge = {
"doctype": "Purchase Taxes and Charges",
"category": "Valuation and Total",
"charge_type": "Actual",
"account_head": shipping_rule.account,
"cost_center": shipping_rule.cost_center,
"tax_amount": shipping_amount,
"description": shipping_rule.name,
"add_deduct_tax": "Add"
}
pi.append("taxes", shipping_charge)
pi.save()

self.assertEqual(pi.net_total, 1250)

self.assertEqual(pi.total_taxes_and_charges, 462.3)
self.assertEqual(pi.grand_total, 1712.3)
self.assertEqual(pi.total_taxes_and_charges, 354.1)
self.assertEqual(pi.grand_total, 1604.1)

def test_make_pi_without_terms(self):
pi = make_purchase_invoice(do_not_save=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"received_qty",
"qty",
"rejected_qty",
"stock_uom",
"col_break2",
"uom",
"conversion_factor",
"stock_uom",
"stock_qty",
"sec_break1",
"price_list_rate",
Expand Down Expand Up @@ -175,7 +175,8 @@
{
"fieldname": "received_qty",
"fieldtype": "Float",
"label": "Received Qty"
"label": "Received Qty",
"read_only": 1
},
{
"bold": 1,
Expand Down Expand Up @@ -223,7 +224,7 @@
{
"fieldname": "stock_qty",
"fieldtype": "Float",
"label": "Stock Qty",
"label": "Accepted Qty in Stock UOM",
"print_hide": 1,
"read_only": 1,
"reqd": 1
Expand Down Expand Up @@ -870,10 +871,11 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2021-09-01 16:04:03.538643",
"modified": "2021-11-15 17:04:07.191013",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
Expand Down
Loading

0 comments on commit 5689c5d

Please sign in to comment.