Skip to content

Commit

Permalink
Merge branch 'version-13-hotfix' into deferred_entry_freeze_v13
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Sep 20, 2021
2 parents 846d128 + 72c22a4 commit 0708e87
Show file tree
Hide file tree
Showing 56 changed files with 994 additions and 423 deletions.
6 changes: 3 additions & 3 deletions .github/helper/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def docs_link_exists(body):

if response.ok:
payload = response.json()
title = payload.get("title", "").lower().strip()
head_sha = payload.get("head", {}).get("sha")
body = payload.get("body", "").lower()
title = (payload.get("title") or "").lower().strip()
head_sha = (payload.get("head") or {}).get("sha")
body = (payload.get("body") or "").lower()

if (title.startswith("feat")
and head_sha
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
frappe.query_reports["Unpaid Expense Claim"] = {
"filters": [
{
"fieldname":"employee",
"fieldname": "employee",
"label": __("Employee"),
"fieldtype": "Link"
"fieldtype": "Link",
"options": "Employee"
}
]
}
8 changes: 4 additions & 4 deletions erpnext/buying/doctype/supplier/supplier.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@
"image_field": "image",
"links": [
{
"group": "Item Group",
"link_doctype": "Supplier Item Group",
"link_fieldname": "supplier"
"group": "Allowed Items",
"link_doctype": "Party Specific Item",
"link_fieldname": "party"
}
],
"modified": "2021-08-27 18:02:44.314077",
"modified": "2021-09-06 17:37:56.522233",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier",
Expand Down

This file was deleted.

20 changes: 0 additions & 20 deletions erpnext/buying/doctype/supplier_item_group/supplier_item_group.py

This file was deleted.

This file was deleted.

71 changes: 42 additions & 29 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,42 +985,55 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
item_allowance = {}
global_qty_allowance, global_amount_allowance = None, None

role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')
user_roles = frappe.get_roles()

total_overbilled_amt = 0.0

for item in self.get("items"):
if item.get(item_ref_dn):
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
item.get(item_ref_dn), based_on), self.precision(based_on, item))
if not ref_amt:
frappe.msgprint(
_("Warning: System will not check overbilling since amount for Item {0} in {1} is zero")
.format(item.item_code, ref_dt))
else:
already_billed = frappe.db.sql("""
select sum(%s)
from `tab%s`
where %s=%s and docstatus=1 and parent != %s
""" % (based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
(item.get(item_ref_dn), self.name))[0][0]
if not item.get(item_ref_dn):
continue

ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
item.get(item_ref_dn), based_on), self.precision(based_on, item))
if not ref_amt:
frappe.msgprint(
_("System will not check overbilling since amount for Item {0} in {1} is zero")
.format(item.item_code, ref_dt), title=_("Warning"), indicator="orange")
continue

already_billed = frappe.db.sql("""
select sum(%s)
from `tab%s`
where %s=%s and docstatus=1 and parent != %s
""" % (based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
(item.get(item_ref_dn), self.name))[0][0]

total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
self.precision(based_on, item))

total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
self.precision(based_on, item))
allowance, item_allowance, global_qty_allowance, global_amount_allowance = \
get_allowance_for(item.item_code, item_allowance, global_qty_allowance, global_amount_allowance, "amount")

allowance, item_allowance, global_qty_allowance, global_amount_allowance = \
get_allowance_for(item.item_code, item_allowance, global_qty_allowance, global_amount_allowance, "amount")
max_allowed_amt = flt(ref_amt * (100 + allowance) / 100)

max_allowed_amt = flt(ref_amt * (100 + allowance) / 100)
if total_billed_amt < 0 and max_allowed_amt < 0:
# while making debit note against purchase return entry(purchase receipt) getting overbill error
total_billed_amt = abs(total_billed_amt)
max_allowed_amt = abs(max_allowed_amt)

if total_billed_amt < 0 and max_allowed_amt < 0:
# while making debit note against purchase return entry(purchase receipt) getting overbill error
total_billed_amt = abs(total_billed_amt)
max_allowed_amt = abs(max_allowed_amt)
overbill_amt = total_billed_amt - max_allowed_amt
total_overbilled_amt += overbill_amt

role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')
if overbill_amt > 0.01 and role_allowed_to_over_bill not in user_roles:
if self.doctype != "Purchase Invoice":
self.throw_overbill_exception(item, max_allowed_amt)
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
self.throw_overbill_exception(item, max_allowed_amt)

if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles():
if self.doctype != "Purchase Invoice":
self.throw_overbill_exception(item, max_allowed_amt)
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
self.throw_overbill_exception(item, max_allowed_amt)
if role_allowed_to_over_bill in user_roles and total_overbilled_amt > 0.1:
frappe.msgprint(_("Overbilling of {} ignored because you have {} role.")
.format(total_overbilled_amt, role_allowed_to_over_bill), title=_("Warning"), indicator="orange")

def throw_overbill_exception(self, item, max_allowed_amt):
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
Expand Down
30 changes: 21 additions & 9 deletions erpnext/controllers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import defaultdict

import frappe
from frappe import scrub
from frappe.desk.reportview import get_filters_cond, get_match_cond
from frappe.utils import nowdate, unique

Expand Down Expand Up @@ -223,18 +224,29 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
if not field in searchfields]
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])

if filters and isinstance(filters, dict) and filters.get('supplier'):
item_group_list = frappe.get_all('Supplier Item Group',
filters = {'supplier': filters.get('supplier')}, fields = ['item_group'])
if filters and isinstance(filters, dict):
if filters.get('customer') or filters.get('supplier'):
party = filters.get('customer') or filters.get('supplier')
item_rules_list = frappe.get_all('Party Specific Item',
filters = {'party': party}, fields = ['restrict_based_on', 'based_on_value'])

item_groups = []
for i in item_group_list:
item_groups.append(i.item_group)
filters_dict = {}
for rule in item_rules_list:
if rule['restrict_based_on'] == 'Item':
rule['restrict_based_on'] = 'name'
filters_dict[rule.restrict_based_on] = []

del filters['supplier']
for rule in item_rules_list:
filters_dict[rule.restrict_based_on].append(rule.based_on_value)

for filter in filters_dict:
filters[scrub(filter)] = ['in', filters_dict[filter]]

if filters.get('customer'):
del filters['customer']
else:
del filters['supplier']

if item_groups:
filters['item_group'] = ['in', item_groups]

description_cond = ''
if frappe.db.count('Item', cache=True) < 50000:
Expand Down
4 changes: 1 addition & 3 deletions erpnext/e_commerce/doctype/website_item/website_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from frappe.website.website_generator import WebsiteGenerator

from erpnext.e_commerce.doctype.item_review.item_review import get_item_reviews

# SEARCH
from erpnext.e_commerce.redisearch import (
delete_item_from_index,
insert_item_to_index,
Expand Down Expand Up @@ -138,10 +136,10 @@ def validate_website_image(self):
self.website_image = None

def make_thumbnail(self):
"""Make a thumbnail of `website_image`"""
if frappe.flags.in_import or frappe.flags.in_migrate:
return

"""Make a thumbnail of `website_image`"""
import requests.exceptions

if not self.is_new() and self.website_image != frappe.db.get_value(self.doctype, self.name, "website_image"):
Expand Down
16 changes: 9 additions & 7 deletions erpnext/e_commerce/redisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def get_indexable_web_fields():
return [df.fieldname for df in valid_fields]

def is_search_module_loaded():
cache = frappe.cache()
out = cache.execute_command('MODULE LIST')

parsed_output = " ".join(
(" ".join([s.decode() for s in o if not isinstance(s, int)]) for o in out)
)
try:
cache = frappe.cache()
out = cache.execute_command('MODULE LIST')

return "search" in parsed_output
parsed_output = " ".join(
(" ".join([s.decode() for s in o if not isinstance(s, int)]) for o in out)
)
return "search" in parsed_output
except Exception:
return False

def if_redisearch_loaded(function):
"Decorator to check if Redisearch is loaded."
Expand Down
6 changes: 4 additions & 2 deletions erpnext/e_commerce/shopping_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def place_order():
if is_stock_item:
item_stock = get_web_item_qty_in_stock(item.item_code, "website_warehouse")
if not cint(item_stock.in_stock):
throw(_("{1} Not in Stock").format(item.item_code))
throw(_("{0} Not in Stock").format(item.item_code))
if item.qty > item_stock.stock_qty[0][0]:
throw(_("Only {0} in Stock for item {1}").format(item_stock.stock_qty[0][0], item.item_code))

Expand Down Expand Up @@ -168,8 +168,10 @@ def update_cart(item_code, qty, additional_notes=None, with_items=False):
return {
"items": frappe.render_template("templates/includes/cart/cart_items.html",
context),
"taxes": frappe.render_template("templates/includes/order/order_taxes.html",
"total": frappe.render_template("templates/includes/cart/cart_items_total.html",
context),
"taxes_and_totals": frappe.render_template("templates/includes/cart/cart_payment_summary.html",
context)
}
else:
return {
Expand Down
8 changes: 6 additions & 2 deletions erpnext/e_commerce/variant_selector/item_variants_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ def build_cache(self):
as_list=1
)

disabled_items = set([i.name for i in frappe.db.get_all('Item', {'disabled': 1})])
unpublished_items = set([i.item_code for i in frappe.db.get_all('Website Item', filters={'published': 0}, fields=["item_code"])])

attribute_value_item_map = frappe._dict({})
item_attribute_value_map = frappe._dict({})

item_variants_data = [r for r in item_variants_data if r[0] not in disabled_items]
# dont consider variants that are unpublished
# (either have no Website Item or are unpublished in Website Item)
item_variants_data = [r for r in item_variants_data if r[0] not in unpublished_items]
item_variants_data = [r for r in item_variants_data if frappe.db.exists("Website Item", {"item_code": r[0]})]

for row in item_variants_data:
item_code, attribute, attribute_value = row
# (attr, value) => [item1, item2]
Expand Down
Loading

0 comments on commit 0708e87

Please sign in to comment.