chore: Drop old patches

v7 backup was restored and upgraded to latest v10.x.x branch. The
patches run uptil the upgrade are removed in this change. This means
only existing v10 sites are allowed direct upgrade to v13 and newer
This commit is contained in:
Gavin D'souza 2021-06-04 11:44:40 +05:30
parent 3e92089200
commit 5bf5775b43
441 changed files with 0 additions and 9599 deletions

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
from erpnext.stock.stock_balance import set_stock_balance_as_per_serial_no
frappe.db.auto_commit_on_many_writes = 1
set_stock_balance_as_per_serial_no()
frappe.db.auto_commit_on_many_writes = 0

View File

@ -1,13 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
domain = 'Agriculture'
if not frappe.db.exists('Domain', domain):
frappe.get_doc({
'doctype': 'Domain',
'domain': domain
}).insert(ignore_permissions=True)

View File

@ -1,23 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
# create guardian role
if not frappe.get_value('Role', dict(role_name='Guardian')):
frappe.get_doc({
'doctype': 'Role',
'role_name': 'Guardian',
'desk_access': 0,
'restrict_to_domain': 'Education'
}).insert(ignore_permissions=True)
# set guardian roles in already created users
if frappe.db.exists("Doctype", "Guardian"):
for user in frappe.db.sql_list("""select u.name from `tabUser` u , `tabGuardian` g where g.email_address = u.name"""):
user = frappe.get_doc('User', user)
user.flags.ignore_validate = True
user.flags.ignore_mandatory = True
user.save()

View File

@ -1,20 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
domain = 'Non Profit'
if not frappe.db.exists('Domain', domain):
frappe.get_doc({
'doctype': 'Domain',
'domain': domain
}).insert(ignore_permissions=True)
frappe.get_doc({
'doctype': 'Role',
'role_name': 'Non Profit Portal User',
'desk_access': 0,
'restrict_to_domain': domain
}).insert(ignore_permissions=True)

View File

@ -1,23 +0,0 @@
# Copyright (c) 2019, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('buying', 'doctype', 'supplier_scorecard_criteria')
frappe.reload_doc('buying', 'doctype', 'supplier_scorecard_scoring_criteria')
frappe.reload_doc('buying', 'doctype', 'supplier_scorecard')
for criteria in frappe.get_all('Supplier Scorecard Criteria', fields=['name', 'formula'], limit_page_length=None):
frappe.db.set_value('Supplier Scorecard Criteria', criteria.name,
'formula', criteria.formula.replace('&lt;','<').replace('&gt;','>'))
for criteria in frappe.get_all('Supplier Scorecard Scoring Criteria', fields=['name', 'formula'], limit_page_length=None):
if criteria.formula: # not mandatory
frappe.db.set_value('Supplier Scorecard Scoring Criteria', criteria.name,
'formula', criteria.formula.replace('&lt;','<').replace('&gt;','>'))
for sc in frappe.get_all('Supplier Scorecard', fields=['name', 'weighting_function'], limit_page_length=None):
frappe.db.set_value('Supplier Scorecard', sc.name, 'weighting_function',
sc.weighting_function.replace('&lt;','<').replace('&gt;','>'))

View File

@ -1,13 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
""" copy data from old fields to new """
frappe.reload_doc("projects", "doctype", "project")
if frappe.db.has_column('Project', 'total_sales_cost'):
rename_field('Project', "total_sales_cost", "total_sales_amount")
if frappe.db.has_column('Project', 'total_billing_amount'):
rename_field('Project', "total_billing_amount", "total_billable_amount")

View File

@ -1,22 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
print_format_mapper = {
'India': ['GST POS Invoice', 'GST Tax Invoice'],
'Saudi Arabia': ['Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice'],
'United Arab Emirates': ['Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice']
}
frappe.db.sql(""" update `tabPrint Format` set disabled = 1 where name
in ('GST POS Invoice', 'GST Tax Invoice', 'Simplified Tax Invoice', 'Detailed Tax Invoice')""")
for d in frappe.get_all('Company', fields = ["country"],
filters={'country': ('in', ['India', 'Saudi Arabia', 'United Arab Emirates'])}):
if print_format_mapper.get(d.country):
print_formats = print_format_mapper.get(d.country)
frappe.db.sql(""" update `tabPrint Format` set disabled = 0
where name in (%s)""" % ", ".join(["%s"]*len(print_formats)), tuple(print_formats))

View File

@ -1,31 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.stock.utils import get_bin
def execute():
frappe.reload_doc("stock", "doctype", "bin")
frappe.reload_doc("buying", "doctype", "purchase_order_item_supplied")
for d in frappe.db.sql("""
select distinct rm_item_code, reserve_warehouse
from `tabPurchase Order Item Supplied`
where docstatus=1 and reserve_warehouse is not null and reserve_warehouse != ''"""):
try:
bin_doc = get_bin(d[0], d[1])
bin_doc.update_reserved_qty_for_sub_contracting()
except:
pass
for d in frappe.db.sql("""select distinct item_code, source_warehouse
from `tabWork Order Item`
where docstatus=1 and transferred_qty > required_qty
and source_warehouse is not null and source_warehouse != ''""", as_list=1):
try:
bin_doc = get_bin(d[0], d[1])
bin_doc.update_reserved_qty_for_production()
except:
pass

View File

@ -1,14 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('projects', 'doctype', 'project')
for d in frappe.db.sql(""" select name from `tabProject` where
ifnull(total_consumed_material_cost, 0 ) > 0 and ifnull(total_billed_amount, 0) > 0""", as_dict=1):
doc = frappe.get_doc("Project", d.name)
doc.calculate_gross_margin()
doc.db_set('gross_margin', doc.gross_margin)
doc.db_set('per_gross_margin', doc.per_gross_margin)

View File

@ -1,32 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
# rename the School module as Education
# rename the school module
if frappe.db.exists('Module Def', 'Schools') and not frappe.db.exists('Module Def', 'Education'):
frappe.rename_doc("Module Def", "Schools", "Education")
# delete the school module
if frappe.db.exists('Module Def', 'Schools') and frappe.db.exists('Module Def', 'Education'):
frappe.db.sql("""delete from `tabModule Def` where module_name = 'Schools'""")
# rename "School Settings" to the "Education Settings
if frappe.db.exists('DocType', 'School Settings'):
frappe.rename_doc("DocType", "School Settings", "Education Settings", force=True)
frappe.reload_doc("education", "doctype", "education_settings")
# delete the discussion web form if exists
if frappe.db.exists('Web Form', 'Discussion'):
frappe.db.sql("""delete from `tabWeb Form` where name = 'discussion'""")
# rename the select option field from "School Bus" to "Institute's Bus"
frappe.reload_doc("education", "doctype", "Program Enrollment")
if "mode_of_transportation" in frappe.db.get_table_columns("Program Enrollment"):
frappe.db.sql("""update `tabProgram Enrollment` set mode_of_transportation = "Institute's Bus"
where mode_of_transportation = "School Bus" """)

View File

@ -1,32 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, erpnext
def execute():
for company in frappe.get_all("Company"):
if not erpnext.is_perpetual_inventory_enabled(company.name):
continue
acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto") or "1900-01-01"
pr_with_rejected_warehouse = frappe.db.sql("""
select pr.name
from `tabPurchase Receipt` pr, `tabPurchase Receipt Item` pr_item
where pr.name = pr_item.parent
and pr.posting_date > %s
and pr.docstatus=1
and pr.company = %s
and pr_item.rejected_qty > 0
""", (acc_frozen_upto, company.name), as_dict=1)
for d in pr_with_rejected_warehouse:
doc = frappe.get_doc("Purchase Receipt", d.name)
doc.docstatus = 2
doc.make_gl_entries_on_cancel()
# update gl entries for submit state of PR
doc.docstatus = 1
doc.make_gl_entries()

View File

@ -1,21 +0,0 @@
# Copyright (c) 2019, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
from erpnext.stock.stock_balance import update_bin_qty, get_indented_qty
count=0
for item_code, warehouse in frappe.db.sql("""select distinct item_code, warehouse
from `tabMaterial Request Item` where docstatus = 1 and stock_uom<>uom"""):
try:
count += 1
update_bin_qty(item_code, warehouse, {
"indented_qty": get_indented_qty(item_code, warehouse),
})
if count % 200 == 0:
frappe.db.commit()
except:
frappe.db.rollback()

View File

@ -1,56 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
serialised_items = [d.name for d in frappe.get_all("Item", filters={"has_serial_no": 1})]
if not serialised_items:
return
for dt in ["Stock Entry Detail", "Purchase Receipt Item", "Purchase Invoice Item"]:
cond = ""
if dt=="Purchase Invoice Item":
cond = """ and parent in (select name from `tabPurchase Invoice`
where `tabPurchase Invoice`.name = `tabPurchase Invoice Item`.parent and update_stock=1)"""
item_rows = frappe.db.sql("""
select name
from `tab{0}`
where conversion_factor != 1
and docstatus = 1
and ifnull(serial_no, '') = ''
and item_code in ({1})
{2}
""".format(dt, ', '.join(['%s']*len(serialised_items)), cond), tuple(serialised_items))
if item_rows:
sle_serial_nos = dict(frappe.db.sql("""
select voucher_detail_no, serial_no
from `tabStock Ledger Entry`
where ifnull(serial_no, '') != ''
and voucher_detail_no in (%s)
""".format(', '.join(['%s']*len(item_rows))),
tuple([d[0] for d in item_rows])))
batch_size = 100
for i in range(0, len(item_rows), batch_size):
batch_item_rows = item_rows[i:i + batch_size]
when_then = []
for item_row in batch_item_rows:
when_then.append('WHEN `name` = "{row_name}" THEN "{value}"'.format(
row_name=item_row[0],
value=sle_serial_nos.get(item_row[0])))
frappe.db.sql("""
update
`tab{doctype}`
set
serial_no = CASE {when_then_cond} ELSE `serial_no` END
""".format(
doctype = dt,
when_then_cond=" ".join(when_then)
))

View File

@ -1,12 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("regional", "doctype", "gst_settings")
frappe.reload_doc("accounts", "doctype", "gst_account")
gst_settings = frappe.get_doc("GST Settings")
gst_settings.b2c_limit = 250000
gst_settings.save()

View File

@ -1,37 +0,0 @@
from __future__ import unicode_literals
import frappe
from erpnext.patches.v8_10.change_default_customer_credit_days import make_payment_term, make_template
def execute():
for dt in ("Company", "Customer Group"):
frappe.reload_doc("setup", "doctype", frappe.scrub(dt))
credit_records = frappe.db.sql("""
SELECT DISTINCT `credit_days`, `credit_days_based_on`, `name`
from `tab{0}`
where
((credit_days_based_on='Fixed Days' or credit_days_based_on is null) and credit_days is not null)
or credit_days_based_on='Last Day of the Next Month'
""".format(dt), as_dict=1)
for d in credit_records:
template = create_payment_terms_template(d)
frappe.db.sql("""
update `tab{0}`
set `payment_terms` = %s
where name = %s
""".format(dt), (template.name, d.name))
def create_payment_terms_template(data):
if data.credit_days_based_on == "Fixed Days":
pyt_template_name = 'Default Payment Term - N{0}'.format(data.credit_days)
else:
pyt_template_name = 'Default Payment Term - EO2M'
if not frappe.db.exists("Payment Terms Template", pyt_template_name):
payment_term = make_payment_term(data.credit_days, data.credit_days_based_on)
template = make_template(payment_term)
else:
template = frappe.get_doc("Payment Terms Template", pyt_template_name)
return template

View File

@ -1,35 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "sales_invoice_item")
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice_item')
frappe.reload_doc('buying', 'doctype', 'purchase_order_item')
frappe.reload_doc('buying', 'doctype', 'supplier_quotation_item')
frappe.reload_doc('selling', 'doctype', 'sales_order_item')
frappe.reload_doc('selling', 'doctype', 'quotation_item')
frappe.reload_doc('stock', 'doctype', 'delivery_note_item')
frappe.reload_doc('stock', 'doctype', 'purchase_receipt_item')
selling_doctypes = ["Sales Order Item", "Sales Invoice Item", "Delivery Note Item", "Quotation Item"]
buying_doctypes = ["Purchase Order Item", "Purchase Invoice Item", "Purchase Receipt Item", "Supplier Quotation Item"]
for doctype in selling_doctypes:
frappe.db.sql('''
UPDATE
`tab%s`
SET
discount_amount = if(rate_with_margin > 0, rate_with_margin, price_list_rate) * discount_percentage / 100
WHERE
discount_percentage > 0
''' % (doctype))
for doctype in buying_doctypes:
frappe.db.sql('''
UPDATE
`tab%s`
SET
discount_amount = price_list_rate * discount_percentage / 100
WHERE
discount_percentage > 0
''' % (doctype))

View File

@ -1,35 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
item_numeric_attributes = frappe.db.sql("""
select name, numeric_values, from_range, to_range, increment
from `tabItem Attribute`
where numeric_values = 1
""", as_dict=1)
for d in item_numeric_attributes:
frappe.db.sql("""
update `tabItem Variant Attribute`
set
from_range = CASE
WHEN from_range = 0 THEN %(from_range)s
ELSE from_range
END,
to_range = CASE
WHEN to_range = 0 THEN %(to_range)s
ELSE to_range
END,
increment = CASE
WHEN increment = 0 THEN %(increment)s
ELSE increment
END,
numeric_values = %(numeric_values)s
where
attribute = %(name)s
and exists(select name from tabItem
where name=`tabItem Variant Attribute`.parent and has_variants=1)
""", d)

View File

@ -1,21 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doctype('Customer')
frappe.db.sql("""
update
`tabCustomer`, (
select `tabContact`.name, `tabContact`.mobile_no, `tabContact`.email_id,
`tabDynamic Link`.link_name from `tabContact`, `tabDynamic Link`
where `tabContact`.name = `tabDynamic Link`.parent and
`tabDynamic Link`.link_doctype = 'Customer' and `tabContact`.is_primary_contact = 1
) as contact
set
`tabCustomer`.customer_primary_contact = contact.name,
`tabCustomer`.mobile_no = contact.mobile_no, `tabCustomer`.email_id = contact.email_id
where `tabCustomer`.name = contact.link_name""")

View File

@ -1,21 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("stock", "doctype", "stock_settings")
ss = frappe.get_doc("Stock Settings")
ss.set_qty_in_transactions_based_on_serial_no_input = 1
if ss.default_warehouse \
and not frappe.db.exists("Warehouse", ss.default_warehouse):
ss.default_warehouse = None
if ss.stock_uom and not frappe.db.exists("UOM", ss.stock_uom):
ss.stock_uom = None
ss.flags.ignore_mandatory = True
ss.save()

View File

@ -1,8 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
if not frappe.db.exists("Party Type", "Student"):
party = frappe.new_doc("Party Type")
party.party_type = "Student"
party.save()

View File

@ -1,13 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.setup.doctype.company.company import install_country_fixtures
def execute():
frappe.reload_doc("accounts", "doctype", "account")
frappe.reload_doc("accounts", "doctype", "payment_schedule")
for d in frappe.get_all('Company',
filters={'country': ('in', ['Saudi Arabia', 'United Arab Emirates'])}):
install_country_fixtures(d.name)

View File

@ -1,6 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("hr", "doctype", "hr_settings")
frappe.db.set_value("HR Settings", None, "show_leaves_of_all_department_members_in_calendar", 1)

View File

@ -1,26 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for d in frappe.get_all('Sales Invoice', fields=["name"],
filters = {'is_pos':1, 'docstatus': 1, 'creation': ('>', '2018-04-23')}):
doc = frappe.get_doc('Sales Invoice', d.name)
if (not doc.taxes and doc.taxes_and_charges and doc.pos_profile and doc.outstanding_amount != 0 and
frappe.db.get_value('POS Profile', doc.pos_profile, 'taxes_and_charges', cache=True) == doc.taxes_and_charges):
doc.append_taxes_from_master()
doc.calculate_taxes_and_totals()
for d in doc.taxes:
d.db_update()
doc.db_update()
delete_gle_for_voucher(doc.name)
doc.make_gl_entries()
def delete_gle_for_voucher(voucher_no):
frappe.db.sql("""delete from `tabGL Entry` where voucher_no = %(voucher_no)s""",
{'voucher_no': voucher_no})

View File

@ -1,12 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.regional.address_template.setup import set_up_address_templates
def execute():
if frappe.db.get_value('Company', {'country': 'India'}, 'name'):
address_template = frappe.db.get_value('Address Template', 'India', 'template')
if not address_template or "gstin" not in address_template:
set_up_address_templates(default_country='India')

View File

@ -1,17 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('education', 'doctype', 'assessment_plan')
frappe.db.sql("""
UPDATE `tabAssessment Plan` as ap
INNER JOIN `tabStudent Group` as sg ON sg.name = ap.student_group
SET ap.academic_term = sg.academic_term,
ap.academic_year = sg.academic_year,
ap.program = sg.program
WHERE ap.docstatus = 1
""")

View File

@ -1,20 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('education', 'doctype', 'assessment_result')
frappe.db.sql("""
UPDATE `tabAssessment Result` AS ar
INNER JOIN `tabAssessment Plan` AS ap ON ap.name = ar.assessment_plan
SET ar.academic_term = ap.academic_term,
ar.academic_year = ap.academic_year,
ar.program = ap.program,
ar.course = ap.course,
ar.assessment_group = ap.assessment_group,
ar.student_group = ap.student_group
WHERE ap.docstatus = 1
""")

View File

@ -1,12 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('assets', 'doctype', 'asset')
frappe.reload_doc('assets', 'doctype', 'depreciation_schedule')
frappe.db.sql("""
update tabAsset a
set calculate_depreciation = 1
where exists(select ds.name from `tabDepreciation Schedule` ds where ds.parent=a.name)
""")

View File

@ -1,10 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
if frappe.db.table_exists("Data Migration Connector"):
frappe.db.sql("""
UPDATE `tabData Migration Connector`
SET hostname = 'https://hubmarket.org'
WHERE connector_name = 'Hub Connector'
""")

View File

@ -1,9 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.utils.nestedset import rebuild_tree
def execute():
""" assign lft and rgt appropriately """
frappe.reload_doc("hr", "doctype", "employee")
rebuild_tree("Employee", "reports_to")

View File

@ -1,15 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for doctype in ['Sales Invoice', 'Delivery Note', 'Stock Entry']:
frappe.db.sql(""" update
`tabStock Ledger Entry` sle, `tab{0}` parent_doc
set
sle.project = parent_doc.project
where
sle.voucher_no = parent_doc.name and sle.voucher_type = %s and sle.project is null
and parent_doc.project is not null and parent_doc.project != ''""".format(doctype), doctype)

View File

@ -1,53 +0,0 @@
from __future__ import unicode_literals
import frappe
from erpnext.stock.utils import get_bin
def execute():
po_item = list(frappe.db.sql(("""
select distinct po.name as poname, poitem.rm_item_code as rm_item_code, po.company
from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitem
where po.name = poitem.parent
and po.is_subcontracted = "Yes"
and po.docstatus = 1"""), as_dict=1))
if not po_item:
return
frappe.reload_doc("stock", "doctype", "bin")
frappe.reload_doc("buying", "doctype", "purchase_order_item_supplied")
company_warehouse = frappe._dict(frappe.db.sql("""select company, min(name) from `tabWarehouse`
where is_group = 0 group by company"""))
items = list(set([d.rm_item_code for d in po_item]))
item_wh = frappe._dict(frappe.db.sql("""select item_code, default_warehouse
from `tabItem` where name in ({0})""".format(", ".join(["%s"] * len(items))), items))
# Update reserved warehouse
for item in po_item:
reserve_warehouse = get_warehouse(item.rm_item_code, item.company, company_warehouse, item_wh)
frappe.db.sql("""update `tabPurchase Order Item Supplied`
set reserve_warehouse = %s
where parent = %s and rm_item_code = %s
""", (reserve_warehouse, item["poname"], item["rm_item_code"]))
# Update bin
item_wh_bin = frappe.db.sql(("""
select distinct poitemsup.rm_item_code as rm_item_code,
poitemsup.reserve_warehouse as reserve_warehouse
from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
where po.name = poitemsup.parent
and po.is_subcontracted = "Yes"
and po.docstatus = 1"""), as_dict=1)
for d in item_wh_bin:
try:
stock_bin = get_bin(d["rm_item_code"], d["reserve_warehouse"])
stock_bin.update_reserved_qty_for_sub_contracting()
except:
pass
def get_warehouse(item_code, company, company_warehouse, item_wh):
reserve_warehouse = item_wh.get(item_code)
if frappe.db.get_value("Warehouse", reserve_warehouse, "company") != company:
reserve_warehouse = None
if not reserve_warehouse:
reserve_warehouse = company_warehouse.get(company)
return reserve_warehouse

View File

@ -1,18 +0,0 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("buying", "doctype", "supplier_quotation_item")
for doctype in ['Purchase Order','Supplier Quotation']:
frappe.db.sql("""
Update
`tab{doctype} Item`, `tabMaterial Request Item`
set
`tab{doctype} Item`.sales_order = `tabMaterial Request Item`.sales_order
where
`tab{doctype} Item`.material_request= `tabMaterial Request Item`.parent
and `tab{doctype} Item`.material_request_item = `tabMaterial Request Item`.name
and `tabMaterial Request Item`.sales_order is not null""".format(doctype=doctype))

View File

@ -1,40 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
# update the sales order item in the material request
frappe.reload_doc('stock', 'doctype', 'material_request_item')
frappe.db.sql('''update `tabMaterial Request Item` mri, `tabSales Order Item` soi
set mri.sales_order_item = soi.name
where ifnull(mri.sales_order, "")!="" and soi.parent=mri.sales_order
and soi.item_code=mri.item_code and mri.docstatus=1
''')
# update the sales order item in the purchase order
frappe.db.sql('''update `tabPurchase Order Item` poi, `tabSales Order Item` soi
set poi.sales_order_item = soi.name
where ifnull(poi.sales_order, "")!="" and soi.parent=poi.sales_order
and soi.item_code=poi.item_code and poi.docstatus = 1
''')
# Update the status in material request and sales order
po_list = frappe.db.sql('''
select parent from `tabPurchase Order Item` where ifnull(material_request, "")!="" and
ifnull(sales_order, "")!="" and docstatus=1
''',as_dict=1)
for po in list(set([d.get("parent") for d in po_list if d.get("parent")])):
try:
po_doc = frappe.get_doc("Purchase Order", po)
# update the so in the status updater
po_doc.update_status_updater()
po_doc.update_qty(update_modified=False)
except Exception:
pass

View File

@ -1,8 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("stock", "doctype", "purchase_receipt")
frappe.db.sql('''
UPDATE `tabPurchase Receipt` SET status = "Completed" WHERE per_billed = 100 AND docstatus = 1
''')

View File

@ -1,29 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.model.rename_doc import get_fetch_fields
def execute():
ignore_doctypes = ["Lead", "Opportunity", "POS Profile", "Tax Rule", "Pricing Rule"]
customers = frappe.get_all('Customer', fields=["name", "customer_group"])
customer_group_fetch = get_fetch_fields('Customer', 'Customer Group', ignore_doctypes)
batch_size = 1000
for i in range(0, len(customers), batch_size):
batch_customers = customers[i:i + batch_size]
for d in customer_group_fetch:
when_then = []
for customer in batch_customers:
value = frappe.db.escape(frappe.as_unicode(customer.get("customer_group")))
when_then.append('''
WHEN `%s` = %s and %s != %s
THEN %s
'''%(d["master_fieldname"], frappe.db.escape(frappe.as_unicode(customer.name)),
d["linked_to_fieldname"], value, value))
frappe.db.sql("""
update
`tab%s`
set
%s = CASE %s ELSE `%s` END
"""%(d['doctype'], d.linked_to_fieldname, " ".join(when_then), d.linked_to_fieldname))

View File

@ -1,19 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('hr', 'doctype', 'employee')
frappe.db.sql("""
UPDATE
`tabEmployee`, `tabUser`
SET
`tabEmployee`.image = `tabUser`.user_image
WHERE
`tabEmployee`.user_id = `tabUser`.name and
`tabEmployee`.user_id is not null and
`tabEmployee`.user_id != '' and `tabEmployee`.image is null
""")

View File

@ -1,37 +0,0 @@
# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
warehouse = frappe.db.sql("""select name, email_id, phone_no, mobile_no, address_line_1,
address_line_2, city, state, pin from `tabWarehouse` where ifnull(address_line_1, '') != ''
or ifnull(mobile_no, '') != ''
or ifnull(email_id, '') != '' """, as_dict=1)
for d in warehouse:
try:
address = frappe.new_doc('Address')
address.name = d.name
address.address_title = d.name
address.address_line1 = d.address_line_1
address.city = d.city
address.state = d.state
address.pincode = d.pin
address.db_insert()
address.append('links',{'link_doctype':'Warehouse','link_name':d.name})
address.links[0].db_insert()
if d.name and (d.email_id or d.mobile_no or d.phone_no):
contact = frappe.new_doc('Contact')
contact.name = d.name
contact.first_name = d.name
contact.mobile_no = d.mobile_no
contact.email_id = d.email_id
contact.phone = d.phone_no
contact.db_insert()
contact.append('links',{'link_doctype':'Warehouse','link_name':d.name})
contact.links[0].db_insert()
except frappe.DuplicateEntryError:
pass

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,16 +0,0 @@
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
""" copy subscribe field to customer """
frappe.reload_doc("accounts","doctype","subscription")
if frappe.db.exists("DocType", "Subscriber"):
if frappe.db.has_column('Subscription','subscriber'):
frappe.db.sql("""
update `tabSubscription` s1
set customer=(select customer from tabSubscriber where name=s1.subscriber)
""")
frappe.delete_doc("DocType", "Subscriber")

View File

@ -1 +0,0 @@
from __future__ import unicode_literals

View File

@ -1,50 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.hr.doctype.employee.employee import EmployeeUserDisabledError
def execute():
update_hr_permissions()
update_permissions()
remove_duplicate_user_permissions()
frappe.clear_cache()
def update_hr_permissions():
# add set user permissions rights to HR Manager
frappe.db.sql("""update `tabDocPerm` set `set_user_permissions`=1 where parent in ('Employee', 'Leave Application')
and role='HR Manager' and permlevel=0 and `read`=1""")
docperm_meta = frappe.get_meta('DocPerm')
if docperm_meta.get_field('apply_user_permissions'):
# apply user permissions on Employee and Leave Application
frappe.db.sql("""update `tabDocPerm` set `apply_user_permissions`=1 where parent in ('Employee', 'Leave Application')
and role in ('Employee', 'Leave Approver') and permlevel=0 and `read`=1""")
frappe.clear_cache()
# save employees to run on_update events
for employee in frappe.db.sql_list("""select name from `tabEmployee` where docstatus < 2"""):
try:
emp = frappe.get_doc("Employee", employee)
emp.flags.ignore_mandatory = True
emp.save()
except EmployeeUserDisabledError:
pass
def update_permissions():
# clear match conditions other than owner
frappe.db.sql("""update tabDocPerm set `match`=''
where ifnull(`match`,'') not in ('', 'owner')""")
def remove_duplicate_user_permissions():
# remove duplicate user_permissions (if they exist)
for d in frappe.db.sql("""select parent, defkey, defvalue,
count(*) as cnt from tabDefaultValue
where parent not in ('__global', '__default')
group by parent, defkey, defvalue""", as_dict=1):
if d.cnt > 1:
# order by parenttype so that user permission does not get removed!
frappe.db.sql("""delete from tabDefaultValue where `parent`=%s and `defkey`=%s and
`defvalue`=%s order by parenttype limit %s""", (d.parent, d.defkey, d.defvalue, d.cnt-1))

View File

@ -1,29 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("setup", 'doctype', "company")
frappe.reload_doc("accounts", 'doctype', "account")
frappe.db.sql("""update tabAccount set account_type='Cash'
where account_type='Bank or Cash' and account_name in ('Cash', 'Cash In Hand')""")
frappe.db.sql("""update tabAccount set account_type='Stock'
where account_name = 'Stock Assets'""")
ac_types = {"Fixed Asset Account": "Fixed Asset", "Bank or Cash": "Bank"}
for old, new in ac_types.items():
frappe.db.sql("""update tabAccount set account_type=%s
where account_type=%s""", (new, old))
try:
frappe.db.sql("""update `tabAccount` set report_type =
if(is_pl_account='Yes', 'Profit and Loss', 'Balance Sheet')""")
frappe.db.sql("""update `tabAccount` set balance_must_be=debit_or_credit
where ifnull(allow_negative_balance, 0) = 0""")
except:
pass

View File

@ -1,63 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field_if_values_exist
def execute():
frappe.reload_doc("stock", "doctype", "purchase_receipt")
frappe.reload_doc("hr", "doctype", "employee")
frappe.reload_doc("Payroll", "doctype", "salary_slip")
india_specific_fields = {
"Purchase Receipt": [{
"label": "Supplier Shipment No",
"fieldname": "challan_no",
"fieldtype": "Data",
"insert_after": "is_subcontracted"
}, {
"label": "Supplier Shipment Date",
"fieldname": "challan_date",
"fieldtype": "Date",
"insert_after": "is_subcontracted"
}],
"Employee": [{
"label": "PAN Number",
"fieldname": "pan_number",
"fieldtype": "Data",
"insert_after": "company_email"
}, {
"label": "Gratuity LIC Id",
"fieldname": "gratuity_lic_id",
"fieldtype": "Data",
"insert_after": "company_email"
}, {
"label": "Esic Card No",
"fieldname": "esic_card_no",
"fieldtype": "Data",
"insert_after": "bank_ac_no"
}, {
"label": "PF Number",
"fieldname": "pf_number",
"fieldtype": "Data",
"insert_after": "bank_ac_no"
}],
"Salary Slip": [{
"label": "Esic No",
"fieldname": "esic_no",
"fieldtype": "Data",
"insert_after": "letter_head",
"permlevel": 1
}, {
"label": "PF Number",
"fieldname": "pf_no",
"fieldtype": "Data",
"insert_after": "letter_head",
"permlevel": 1
}]
}
for dt, docfields in india_specific_fields.items():
for df in docfields:
create_custom_field_if_values_exist(dt, df)

View File

@ -1,35 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils.nestedset import get_root_of
def execute():
# setup not complete
if not frappe.db.sql("""select name from tabCompany limit 1"""):
return
if "shopping_cart" in frappe.get_installed_apps():
frappe.reload_doc("shopping_cart", "doctype", "shopping_cart_settings")
if not frappe.db.sql("select name from `tabPrice List` where buying=1"):
create_price_list(_("Standard Buying"), buying=1)
if not frappe.db.sql("select name from `tabPrice List` where selling=1"):
create_price_list(_("Standard Selling"), selling=1)
def create_price_list(pl_name, buying=0, selling=0):
price_list = frappe.get_doc({
"doctype": "Price List",
"price_list_name": pl_name,
"enabled": 1,
"buying": buying,
"selling": selling,
"currency": frappe.db.get_default("currency"),
"territories": [{
"territory": get_root_of("Territory")
}]
})
price_list.insert()

View File

@ -1,33 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils.nestedset import get_root_of
def execute():
frappe.reload_doc("accounts", "doctype", "pricing_rule")
frappe.db.auto_commit_on_many_writes = True
default_item_group = get_root_of("Item Group")
for d in frappe.db.sql("""select * from `tabCustomer Discount`
where ifnull(parent, '') != ''""", as_dict=1):
if not d.discount:
continue
frappe.get_doc({
"doctype": "Pricing Rule",
"apply_on": "Item Group",
"item_group": d.item_group or default_item_group,
"applicable_for": "Customer",
"customer": d.parent,
"price_or_discount": "Discount Percentage",
"discount_percentage": d.discount,
"selling": 1
}).insert()
frappe.db.auto_commit_on_many_writes = False
frappe.delete_doc("DocType", "Customer Discount")

View File

@ -1,109 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.utils.rename_field import rename_field
from frappe.modules import scrub, get_doctype_module
rename_map = {
"Quotation Item": [
["ref_rate", "price_list_rate"],
["base_ref_rate", "base_price_list_rate"],
["adj_rate", "discount_percentage"],
["export_rate", "rate"],
["basic_rate", "base_rate"],
["amount", "base_amount"],
["export_amount", "amount"]
],
"Sales Order Item": [
["ref_rate", "price_list_rate"],
["base_ref_rate", "base_price_list_rate"],
["adj_rate", "discount_percentage"],
["export_rate", "rate"],
["basic_rate", "base_rate"],
["amount", "base_amount"],
["export_amount", "amount"],
["reserved_warehouse", "warehouse"]
],
"Delivery Note Item": [
["ref_rate", "price_list_rate"],
["base_ref_rate", "base_price_list_rate"],
["adj_rate", "discount_percentage"],
["export_rate", "rate"],
["basic_rate", "base_rate"],
["amount", "base_amount"],
["export_amount", "amount"]
],
"Sales Invoice Item": [
["ref_rate", "price_list_rate"],
["base_ref_rate", "base_price_list_rate"],
["adj_rate", "discount_percentage"],
["export_rate", "rate"],
["basic_rate", "base_rate"],
["amount", "base_amount"],
["export_amount", "amount"]
],
"Supplier Quotation Item": [
["import_ref_rate", "price_list_rate"],
["purchase_ref_rate", "base_price_list_rate"],
["discount_rate", "discount_percentage"],
["import_rate", "rate"],
["purchase_rate", "base_rate"],
["amount", "base_amount"],
["import_amount", "amount"]
],
"Purchase Order Item": [
["import_ref_rate", "price_list_rate"],
["purchase_ref_rate", "base_price_list_rate"],
["discount_rate", "discount_percentage"],
["import_rate", "rate"],
["purchase_rate", "base_rate"],
["amount", "base_amount"],
["import_amount", "amount"]
],
"Purchase Receipt Item": [
["import_ref_rate", "price_list_rate"],
["purchase_ref_rate", "base_price_list_rate"],
["discount_rate", "discount_percentage"],
["import_rate", "rate"],
["purchase_rate", "base_rate"],
["amount", "base_amount"],
["import_amount", "amount"]
],
"Purchase Invoice Item": [
["import_ref_rate", "price_list_rate"],
["purchase_ref_rate", "base_price_list_rate"],
["discount_rate", "discount_percentage"],
["import_rate", "rate"],
["rate", "base_rate"],
["amount", "base_amount"],
["import_amount", "amount"],
["expense_head", "expense_account"]
],
"Item": [
["purchase_account", "expense_account"],
["default_sales_cost_center", "selling_cost_center"],
["cost_center", "buying_cost_center"],
["default_income_account", "income_account"],
],
"Item Price": [
["ref_rate", "price_list_rate"]
]
}
def execute():
for dn in rename_map:
frappe.reload_doc(get_doctype_module(dn), "doctype", scrub(dn))
for dt, field_list in rename_map.items():
for field in field_list:
rename_field(dt, field[0], field[1])

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
from __future__ import unicode_literals
import frappe
def execute():
missing_line = """{{ address_line1 }}<br>"""
for name, template in frappe.db.sql("select name, template from `tabAddress Template`"):
if missing_line not in template:
d = frappe.get_doc("Address Template", name)
d.template = missing_line + d.template
d.save()

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
from __future__ import unicode_literals
import frappe
def execute():
hr = frappe.db.get_value("Module Def", "HR")
if hr == "Hr":
frappe.rename_doc("Module Def", "Hr", "HR")
frappe.db.set_value("Module Def", "HR", "module_name", "HR")
frappe.clear_cache()
frappe.setup_module_map()

View File

@ -1,13 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("website", "doctype", "contact_us_settings")
address = frappe.db.get_value("Contact Us Settings", None, "address")
if address:
address = frappe.get_doc("Address", address)
contact = frappe.get_doc("Contact Us Settings", "Contact Us Settings")
for f in ("address_title", "address_line1", "address_line2", "city", "state", "country", "pincode"):
contact.set(f, address.get(f))
contact.save()

View File

@ -1,23 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import get_fullname
def execute():
for user_id in frappe.db.sql_list("""select distinct user_id from `tabEmployee`
where ifnull(user_id, '')!=''
group by user_id having count(name) > 1"""):
fullname = get_fullname(user_id)
employee = frappe.db.get_value("Employee", {"employee_name": fullname, "user_id": user_id})
if employee:
frappe.db.sql("""update `tabEmployee` set user_id=null
where user_id=%s and name!=%s""", (user_id, employee))
else:
count = frappe.db.sql("""select count(*) from `tabEmployee` where user_id=%s""", user_id)[0][0]
frappe.db.sql("""update `tabEmployee` set user_id=null
where user_id=%s limit %s""", (user_id, count - 1))

View File

@ -1,39 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from collections import Counter
from frappe.core.doctype.user.user import STANDARD_USERS
def execute():
frappe.reload_doc("core", "doctype", "system_settings")
system_settings = frappe.get_doc("System Settings")
# set values from global_defauls
global_defaults = frappe.db.get_value("Global Defaults", None,
["time_zone", "date_format", "number_format", "float_precision", "session_expiry"], as_dict=True)
if global_defaults:
for key, val in global_defaults.items():
if not system_settings.get(key):
system_settings.set(key, val)
# language
if not system_settings.get("language"):
# find most common language
lang = frappe.db.sql_list("""select language from `tabUser`
where ifnull(language, '')!='' and language not like "Loading%%" and name not in ({standard_users})""".format(
standard_users=", ".join(["%s"]*len(STANDARD_USERS))), tuple(STANDARD_USERS))
lang = Counter(lang).most_common(1)
lang = (len(lang) > 0) and lang[0][0] or "english"
system_settings.language = lang
system_settings.flags.ignore_mandatory = True
system_settings.save()
global_defaults = frappe.get_doc("Global Defaults")
global_defaults.flags.ignore_mandatory = True
global_defaults.save()

View File

@ -1,15 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.geo.country_info import get_all
from frappe.utils.install import import_country_and_currency
from six import iteritems
def execute():
frappe.reload_doc("setup", "doctype", "country")
import_country_and_currency()
for name, country in iteritems(get_all()):
frappe.set_value("Country", name, "code", country.get("code"))

View File

@ -1,16 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
# update sales cycle
for d in ['Sales Invoice', 'Sales Order', 'Quotation', 'Delivery Note']:
frappe.db.sql("""update `tab%s` set taxes_and_charges=charge""" % d)
# update purchase cycle
for d in ['Purchase Invoice', 'Purchase Order', 'Supplier Quotation', 'Purchase Receipt']:
frappe.db.sql("""update `tab%s` set taxes_and_charges=purchase_other_charges""" % d)
frappe.db.sql("""update `tabPurchase Taxes and Charges` set parentfield='other_charges'""")

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import frappe.permissions
def execute():
for warehouse, user in frappe.db.sql("""select parent, user from `tabWarehouse User`"""):
frappe.permissions.add_user_permission("Warehouse", warehouse, user)
frappe.delete_doc_if_exists("DocType", "Warehouse User")
frappe.reload_doc("stock", "doctype", "warehouse")

View File

@ -1,14 +0,0 @@
from __future__ import print_function, unicode_literals
import frappe
def execute():
frappe.reload_doc("utilities", "doctype", "address_template")
if not frappe.db.sql("select name from `tabAddress Template`"):
try:
d = frappe.new_doc("Address Template")
d.update({"country":frappe.db.get_default("country") or
frappe.db.get_value("Global Defaults", "Global Defaults", "country")})
d.insert()
except:
print(frappe.get_traceback())

View File

@ -1,8 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('accounts', 'Print Format', 'POS Invoice')

View File

@ -1,18 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import frappe.permissions
def execute():
for user in frappe.db.sql_list("select distinct parent from `tabHas Role` where role='Employee'"):
# if employee record does not exists, remove employee role!
if not frappe.db.get_value("Employee", {"user_id": user}):
try:
user = frappe.get_doc("User", user)
for role in user.get("roles", {"role": "Employee"}):
user.get("roles").remove(role)
user.save()
except frappe.DoesNotExistError:
pass

View File

@ -1,10 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for page in ("accounts-home", "website-home", "support-home", "stock-home", "selling-home", "projects-home",
"manufacturing-home", "hr-home", "buying-home"):
frappe.delete_doc("Page", page)

View File

@ -1,17 +0,0 @@
from __future__ import unicode_literals
import frappe
import frappe.model
def execute():
frappe.reload_doc("setup", "doctype", "item_group")
frappe.reload_doc("stock", "doctype", "item")
frappe.reload_doc("setup", "doctype", "sales_partner")
try:
frappe.model.rename_field("Item Group", "parent_website_sitemap", "parent_website_route")
frappe.model.rename_field("Item", "parent_website_sitemap", "parent_website_route")
frappe.model.rename_field("Sales Partner", "parent_website_sitemap",
"parent_website_route")
except Exception as e:
if e.args[0]!=1054:
raise

View File

@ -1,20 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
from frappe.permissions import reset_perms
def execute():
for doctype in ("About Us Settings", "Accounts Settings", "Activity Type",
"Blog Category", "Blog Settings", "Blogger", "Branch", "Brand", "Buying Settings",
"Communication", "Company", "Contact Us Settings",
"Country", "Currency", "Currency Exchange", "Deduction Type", "Department",
"Designation", "Earning Type", "Event", "Feed", "File", "Fiscal Year",
"HR Settings", "Industry Type", "Leave Type", "Letter Head",
"Mode of Payment", "Module Def", "Naming Series", "POS Setting", "Print Heading",
"Report", "Role", "Selling Settings", "Stock Settings", "Supplier Type", "UOM"):
try:
reset_perms(doctype)
except:
print("Error resetting perms for", doctype)
raise

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
"""save default letterhead to set default_letter_head_content"""
try:
letter_head = frappe.get_doc("Letter Head", {"is_default": 1})
letter_head.save()
except frappe.DoesNotExistError:
pass

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "pricing_rule")
frappe.db.sql("""update `tabPricing Rule` set selling=1 where ifnull(applicable_for, '') in
('', 'Customer', 'Customer Group', 'Territory', 'Sales Partner', 'Campaign')""")
frappe.db.sql("""update `tabPricing Rule` set buying=1 where ifnull(applicable_for, '') in
('', 'Supplier', 'Supplier Type')""")

View File

@ -1,67 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
def execute():
print("WARNING!!!! Email Settings not migrated. Please setup your email again.")
# this will happen if you are migrating very old accounts
# comment out this line below and remember to create new Email Accounts
# for incoming and outgoing mails
raise Exception
return
frappe.reload_doc("core", "doctype", "outgoing_email_settings")
frappe.reload_doc("support", "doctype", "support_email_settings")
email_settings = get_email_settings()
map_outgoing_email_settings(email_settings)
map_support_email_settings(email_settings)
def map_outgoing_email_settings(email_settings):
outgoing_email_settings = frappe.get_doc("Outgoing Email Settings")
for fieldname in (("outgoing_mail_server", "mail_server"),
"use_ssl", "mail_port", "mail_login", "mail_password",
"always_use_login_id_as_sender", "auto_email_id"):
if isinstance(fieldname, tuple):
from_fieldname, to_fieldname = fieldname
else:
from_fieldname = to_fieldname = fieldname
outgoing_email_settings.set(to_fieldname, email_settings.get(from_fieldname))
outgoing_email_settings._fix_numeric_types()
outgoing_email_settings.save()
def map_support_email_settings(email_settings):
support_email_settings = frappe.get_doc("Support Email Settings")
for fieldname in ("sync_support_mails", "support_email",
("support_host", "mail_server"),
("support_use_ssl", "use_ssl"),
("support_username", "mail_login"),
("support_password", "mail_password"),
"support_signature", "send_autoreply", "support_autoreply"):
if isinstance(fieldname, tuple):
from_fieldname, to_fieldname = fieldname
else:
from_fieldname = to_fieldname = fieldname
support_email_settings.set(to_fieldname, email_settings.get(from_fieldname))
support_email_settings._fix_numeric_types()
support_email_settings.save()
def get_email_settings():
ret = {}
for field, value in frappe.db.sql("select field, value from tabSingles where doctype='Email Settings'"):
ret[field] = value
return ret

View File

@ -1,34 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "account")
account_table_columns = frappe.db.get_table_columns("Account")
if "debit_or_credit" in account_table_columns and "is_pl_account" in account_table_columns:
frappe.db.sql("""UPDATE tabAccount
SET root_type = CASE
WHEN (debit_or_credit='Debit' and is_pl_account = 'No') THEN 'Asset'
WHEN (debit_or_credit='Credit' and is_pl_account = 'No') THEN 'Liability'
WHEN (debit_or_credit='Debit' and is_pl_account = 'Yes') THEN 'Expense'
WHEN (debit_or_credit='Credit' and is_pl_account = 'Yes') THEN 'Income'
END
WHERE ifnull(parent_account, '') = ''
""")
else:
for key, root_type in (("asset", "Asset"), ("liabilities", "Liability"), ("expense", "Expense"),
("income", "Income")):
frappe.db.sql("""update tabAccount set root_type=%s where name like %s
and ifnull(parent_account, '')=''""", (root_type, "%" + key + "%"))
for root in frappe.db.sql("""SELECT name, lft, rgt, root_type FROM `tabAccount`
WHERE ifnull(parent_account, '')=''""", as_dict=True):
if root.root_type:
frappe.db.sql("""UPDATE tabAccount SET root_type=%s WHERE lft>%s and rgt<%s""",
(root.root_type, root.lft, root.rgt))
else:
print(b"Root type not found for {0}".format(root.name.encode("utf-8")))

View File

@ -1,36 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import re
def execute():
# NOTE: sequence is important
fields_list = (
("amount", "base_amount"),
("ref_rate", "price_list_rate"),
("base_ref_rate", "base_price_list_rate"),
("adj_rate", "discount_percentage"),
("export_rate", "rate"),
("basic_rate", "base_rate"),
("export_amount", "amount"),
("reserved_warehouse", "warehouse"),
("import_ref_rate", "price_list_rate"),
("purchase_ref_rate", "base_price_list_rate"),
("discount_rate", "discount_percentage"),
("import_rate", "rate"),
("purchase_rate", "base_rate"),
("import_amount", "amount")
)
condition = " or ".join("""html like "%%{}%%" """.format(d[0].replace("_", "\\_")) for d in fields_list
if d[0] != "amount")
for name, html in frappe.db.sql("""select name, html from `tabPrint Format`
where standard = 'No' and ({}) and html not like '%%frappe.%%'""".format(condition)):
html = html.replace("wn.", "frappe.")
for from_field, to_field in fields_list:
html = re.sub(r"\b{}\b".format(from_field), to_field, html)
frappe.db.set_value("Print Format", name, "html", html)

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("support", "doctype", "schedules")
frappe.reload_doc("support", "doctype", "maintenance_schedule_item")
frappe.db.sql("""update `tabMaintenance Schedule Detail` set sales_person=incharge_name""")
frappe.db.sql("""update `tabMaintenance Schedule Item` set sales_person=incharge_name""")

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import re
def execute():
for name, html in frappe.db.sql("""select name, html from `tabPrint Format`
where standard = 'No' and html like '%%purchase\\_tax\\_details%%'"""):
html = re.sub(r"\bpurchase_tax_details\b", "taxes", html)
frappe.db.set_value("Print Format", name, "html", html)

View File

@ -1,20 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "sales_taxes_and_charges")
docs_with_discount_amount = frappe._dict()
for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
records = frappe.db.sql_list("""select name from `tab%s`
where ifnull(discount_amount, 0) > 0 and docstatus=1""" % dt)
docs_with_discount_amount[dt] = records
for dt, discounted_records in docs_with_discount_amount.items():
frappe.db.sql("""update `tabSales Taxes and Charges`
set tax_amount_after_discount_amount = tax_amount
where parenttype = %s and parent not in (%s)""" %
('%s', ', '.join(['%s']*(len(discounted_records)+1))),
tuple([dt, ''] + discounted_records))

View File

@ -1,51 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import frappe.permissions
import frappe.defaults
def execute():
frappe.reload_doc("core", "doctype", "docfield")
frappe.reload_doc("hr", "doctype", "employee")
set_print_email_permissions()
migrate_user_properties_to_user_permissions()
frappe.clear_cache()
def migrate_user_properties_to_user_permissions():
for d in frappe.db.sql("""select parent, defkey, defvalue from tabDefaultValue
where parent not in ('__global', '__default')""", as_dict=True):
df = frappe.db.sql("""select options from tabDocField
where fieldname=%s and fieldtype='Link'""", d.defkey, as_dict=True)
if df:
frappe.db.sql("""update tabDefaultValue
set defkey=%s, parenttype='User Permission'
where defkey=%s and
parent not in ('__global', '__default')""", (df[0].options, d.defkey))
def set_print_email_permissions():
# reset Page perms
from frappe.core.page.permission_manager.permission_manager import reset
reset("Page")
reset("Report")
if "allow_print" not in frappe.db.get_table_columns("DocType"):
return
# patch to move print, email into DocPerm
# NOTE: allow_print and allow_email are misnamed. They were used to hide print / hide email
for doctype, hide_print, hide_email in frappe.db.sql("""select name, ifnull(allow_print, 0), ifnull(allow_email, 0)
from `tabDocType` where ifnull(issingle, 0)=0 and ifnull(istable, 0)=0 and
(ifnull(allow_print, 0)=0 or ifnull(allow_email, 0)=0)"""):
if not hide_print:
frappe.db.sql("""update `tabDocPerm` set `print`=1
where permlevel=0 and `read`=1 and parent=%s""", doctype)
if not hide_email:
frappe.db.sql("""update `tabDocPerm` set `email`=1
where permlevel=0 and `read`=1 and parent=%s""", doctype)

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
from frappe.model.utils.rename_field import update_users_report_view_settings
from erpnext.patches.v4_0.fields_to_be_renamed import rename_map
def execute():
for dt, field_list in rename_map.items():
for field in field_list:
update_users_report_view_settings(dt, field[0], field[1])

View File

@ -1,11 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
from frappe.modules.patch_handler import executed
last_v3_patch = 'patches.1401.fix_pos_outstanding'
if not executed(last_v3_patch):
raise Exception("site not ready to migrate to version 4")

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.db.sql("""update `tabSales Order` set delivery_status = 'Not Delivered'
where delivery_status = 'Delivered' and ifnull(per_delivered, 0) = 0 and ifnull(docstatus, 0) in (0, 1)""")
frappe.db.sql("""update `tabSales Order` set billing_status = 'Not Billed'
where billing_status = 'Billed' and ifnull(per_billed, 0) = 0 and ifnull(docstatus, 0) in (0, 1)""")

View File

@ -1,21 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
reference_date = guess_reference_date()
for name in frappe.db.sql_list("""select name from `tabJournal Entry`
where date(creation)>=%s""", reference_date):
jv = frappe.get_doc("Journal Entry", name)
try:
jv.create_remarks()
except frappe.MandatoryError:
pass
else:
frappe.db.set_value("Journal Entry", jv.name, "remark", jv.remark)
def guess_reference_date():
return (frappe.db.get_value("Patch Log", {"patch": "erpnext.patches.v4_0.validate_v3_patch"}, "creation")
or "2014-05-06")

View File

@ -1,15 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for si in frappe.db.sql_list("""select name
from `tabSales Invoice`
where ifnull(update_stock,0) = 1 and docstatus = 1 and exists(
select name from `tabSales Invoice Item` where parent=`tabSales Invoice`.name and
ifnull(so_detail, "") != "")"""):
invoice = frappe.get_doc("Sales Invoice", si)
invoice.update_qty()

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.setup.install import default_mail_footer
def execute():
return
mail_footer = frappe.db.get_default('mail_footer') or ''
mail_footer += default_mail_footer
frappe.db.set_value("Outgoing Email Settings", "Outgoing Email Settings", "footer", mail_footer)

View File

@ -1,10 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
return
# country = get_country_info(country="Turkey")
# add_country_and_currency("Turkey", country)

View File

@ -1,11 +0,0 @@
from __future__ import unicode_literals
import frappe
def execute():
return
# frappe.reload_doc('website', 'doctype', 'style_settings')
# style_settings = frappe.get_doc("Style Settings", "Style Settings")
# if not style_settings.apply_style:
# style_settings.update(default_properties)
# style_settings.apply_style = 1
# style_settings.save()

View File

@ -1,14 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
cancelled_invoices = frappe.db.sql_list("""select name from `tabSales Invoice`
where docstatus = 2 and ifnull(update_stock, 0) = 1""")
if cancelled_invoices:
frappe.db.sql("""delete from `tabGL Entry`
where voucher_type = 'Sales Invoice' and voucher_no in (%s)"""
% (', '.join(['%s']*len(cancelled_invoices))), tuple(cancelled_invoices))

View File

@ -1,23 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
old_formats = ("Sales Invoice", "Sales Invoice Spartan", "Sales Invoice Modern",
"Sales Invoice Classic",
"Sales Order Spartan", "Sales Order Modern", "Sales Order Classic",
"Purchase Order Spartan", "Purchase Order Modern", "Purchase Order Classic",
"Quotation Spartan", "Quotation Modern", "Quotation Classic",
"Delivery Note Spartan", "Delivery Note Modern", "Delivery Note Classic")
for fmt in old_formats:
# update property setter
for ps in frappe.db.sql_list("""select name from `tabProperty Setter`
where property='default_print_format' and value=%s""", fmt):
ps = frappe.get_doc("Property Setter", ps)
ps.value = "Standard"
ps.save(ignore_permissions = True)
frappe.delete_doc_if_exists("Print Format", fmt)

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.modules import scrub, get_doctype_module
def execute():
for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
frappe.db.sql("""update `tab{0}` set base_discount_amount=discount_amount,
discount_amount=discount_amount/conversion_rate""".format(dt))

View File

@ -1,12 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for d in frappe.db.sql("""select name from `tabAccount`
where ifnull(master_type, '') not in ('Customer', 'Supplier', 'Employee', '') and docstatus=0"""):
ac = frappe.get_doc("Account", d[0])
ac.master_type = None
ac.save()

View File

@ -1,54 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
from frappe.utils import flt
def execute():
from erpnext.stock.stock_balance import repost
repost(allow_zero_rate=True, only_actual=True)
frappe.reload_doctype("Account")
warehouse_account = frappe.db.sql("""select name, master_name from tabAccount
where ifnull(account_type, '') = 'Warehouse'""")
if warehouse_account:
warehouses = [d[1] for d in warehouse_account]
accounts = [d[0] for d in warehouse_account]
stock_vouchers = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
from `tabStock Ledger Entry` sle
where sle.warehouse in (%s)
order by sle.posting_date""" %
', '.join(['%s']*len(warehouses)), tuple(warehouses))
rejected = []
for voucher_type, voucher_no in stock_vouchers:
stock_bal = frappe.db.sql("""select sum(stock_value_difference) from `tabStock Ledger Entry`
where voucher_type=%s and voucher_no =%s and warehouse in (%s)""" %
('%s', '%s', ', '.join(['%s']*len(warehouses))), tuple([voucher_type, voucher_no] + warehouses))
account_bal = frappe.db.sql("""select ifnull(sum(ifnull(debit, 0) - ifnull(credit, 0)), 0)
from `tabGL Entry`
where voucher_type=%s and voucher_no =%s and account in (%s)
group by voucher_type, voucher_no""" %
('%s', '%s', ', '.join(['%s']*len(accounts))), tuple([voucher_type, voucher_no] + accounts))
if stock_bal and account_bal and abs(flt(stock_bal[0][0]) - flt(account_bal[0][0])) > 0.1:
try:
print(voucher_type, voucher_no, stock_bal[0][0], account_bal[0][0])
frappe.db.sql("""delete from `tabGL Entry`
where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
voucher = frappe.get_doc(voucher_type, voucher_no)
voucher.make_gl_entries()
frappe.db.commit()
except Exception as e:
print(frappe.get_traceback())
rejected.append([voucher_type, voucher_no])
frappe.db.rollback()
print("Failed to repost: ")
print(rejected)

View File

@ -1,41 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
sales_orders = frappe.db.sql("""select name from `tabSales Order`
where docstatus = 1 and ifnull(is_recurring, 0) = 1
and (per_delivered > 0 or per_billed > 0)""", as_dict=1)
for so in sales_orders:
if not frappe.db.exists("Delivery Note Item", {"against_sales_order": so.name, "docstatus": 1}):
frappe.db.sql("""update `tabSales Order` set per_delivered = 0,
delivery_status = 'Not Delivered' where name = %s""", so.name)
frappe.db.sql("""update `tabSales Order Item` set delivered_qty = 0
where parent = %s""", so.name)
if not frappe.db.exists("Sales Invoice Item", {"sales_order": so.name, "docstatus": 1}):
frappe.db.sql("""update `tabSales Order` set per_billed = 0,
billing_status = 'Not Billed' where name = %s""", so.name)
frappe.db.sql("""update `tabSales Order Item` set billed_amt = 0
where parent = %s""", so.name)
purchase_orders = frappe.db.sql("""select name from `tabPurchase Order`
where docstatus = 1 and ifnull(is_recurring, 0) = 1
and (per_received > 0 or per_billed > 0)""", as_dict=1)
for po in purchase_orders:
if not frappe.db.exists("Purchase Receipt Item", {"prevdoc_doctype": "Purchase Order",
"prevdoc_docname": po.name, "docstatus": 1}):
frappe.db.sql("""update `tabPurchase Order` set per_received = 0
where name = %s""", po.name)
frappe.db.sql("""update `tabPurchase Order Item` set received_qty = 0
where parent = %s""", po.name)
if not frappe.db.exists("Purchase Invoice Item", {"purchase_order": po.name, "docstatus": 1}):
frappe.db.sql("""update `tabPurchase Order` set per_billed = 0
where name = %s""", po.name)
frappe.db.sql("""update `tabPurchase Order Item` set billed_amt = 0
where parent = %s""", po.name)

View File

@ -1,117 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
def execute():
frappe.reload_doc("accounts", "doctype", "account")
frappe.reload_doc("setup", "doctype", "company")
frappe.reload_doc("accounts", "doctype", "gl_entry")
frappe.reload_doc("accounts", "doctype", "journal_entry_account")
receivable_payable_accounts = create_receivable_payable_account()
if receivable_payable_accounts:
set_party_in_jv_and_gl_entry(receivable_payable_accounts)
delete_individual_party_account()
remove_customer_supplier_account_report()
def create_receivable_payable_account():
receivable_payable_accounts = frappe._dict()
def _create_account(args):
if args["parent_account"] and frappe.db.exists("Account", args["parent_account"]):
account_id = frappe.db.get_value("Account",
{"account_name": args["account_name"], "company": args["company"]})
if not account_id:
account = frappe.new_doc("Account")
account.is_group = 0
account.update(args)
account.insert()
account_id = account.name
frappe.db.set_value("Company", args["company"], ("default_receivable_account"
if args["account_type"]=="Receivable" else "default_payable_account"), account_id)
receivable_payable_accounts.setdefault(args["company"], {}).setdefault(args["account_type"], account_id)
for company in frappe.db.sql_list("select name from tabCompany"):
_create_account({
"account_name": "Debtors",
"account_type": "Receivable",
"company": company,
"parent_account": get_parent_account(company, "Customer")
})
_create_account({
"account_name": "Creditors",
"account_type": "Payable",
"company": company,
"parent_account": get_parent_account(company, "Supplier")
})
return receivable_payable_accounts
def get_parent_account(company, master_type):
parent_account = None
if "receivables_group" in frappe.db.get_table_columns("Company"):
parent_account = frappe.get_cached_value('Company', company,
"receivables_group" if master_type=="Customer" else "payables_group")
if not parent_account:
parent_account = frappe.db.get_value("Account", {"company": company,
"account_name": "Accounts Receivable" if master_type=="Customer" else "Accounts Payable"})
if not parent_account:
parent_account = frappe.db.sql_list("""select parent_account from tabAccount
where company=%s and ifnull(master_type, '')=%s and ifnull(master_name, '')!='' limit 1""",
(company, master_type))
parent_account = parent_account[0][0] if parent_account else None
return parent_account
def set_party_in_jv_and_gl_entry(receivable_payable_accounts):
accounts = frappe.db.sql("""select name, master_type, master_name, company from `tabAccount`
where ifnull(master_type, '') in ('Customer', 'Supplier') and ifnull(master_name, '') != ''""", as_dict=1)
account_map = frappe._dict()
for d in accounts:
account_map.setdefault(d.name, d)
if not account_map:
return
for dt in ["Journal Entry Account", "GL Entry"]:
records = frappe.db.sql("""select name, account from `tab%s`
where account in (%s) and ifnull(party, '') = '' and docstatus < 2""" %
(dt, ", ".join(['%s']*len(account_map))), tuple(account_map.keys()), as_dict=1)
for i, d in enumerate(records):
account_details = account_map.get(d.account, {})
account_type = "Receivable" if account_details.get("master_type")=="Customer" else "Payable"
new_account = receivable_payable_accounts[account_details.get("company")][account_type]
frappe.db.sql("update `tab{0}` set account=%s, party_type=%s, party=%s where name=%s".format(dt),
(new_account, account_details.get("master_type"), account_details.get("master_name"), d.name))
if i%500 == 0:
frappe.db.commit()
def delete_individual_party_account():
frappe.db.sql("""delete from `tabAccount`
where ifnull(master_type, '') in ('Customer', 'Supplier')
and ifnull(master_name, '') != ''
and not exists(select gle.name from `tabGL Entry` gle
where gle.account = tabAccount.name)""")
accounts_not_deleted = frappe.db.sql_list("""select tabAccount.name from `tabAccount`
where ifnull(master_type, '') in ('Customer', 'Supplier')
and ifnull(master_name, '') != ''
and exists(select gle.name from `tabGL Entry` gle where gle.account = tabAccount.name)""")
if accounts_not_deleted:
print("Accounts not deleted: " + "\n".join(accounts_not_deleted))
def remove_customer_supplier_account_report():
for d in ["Customer Account Head", "Supplier Account Head"]:
frappe.delete_doc("Report", d)

View File

@ -1,16 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for d in frappe.db.sql("select name from `tabBOM` where docstatus < 2"):
try:
document = frappe.get_doc('BOM', d[0])
if document.docstatus == 1:
document.flags.ignore_validate_update_after_submit = True
document.calculate_cost()
document.save()
except:
pass

View File

@ -1,34 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
from erpnext.stock.stock_ledger import NegativeStockError
def execute():
si_list = frappe.db.sql("""select distinct si.name
from `tabSales Invoice Item` si_item, `tabSales Invoice` si
where si.name = si_item.parent and si.modified > '2015-02-16' and si.docstatus=1
and ifnull(si_item.warehouse, '') = '' and ifnull(si.update_stock, 0) = 1
order by posting_date, posting_time""", as_dict=1)
failed_list = []
for si in si_list:
try:
si_doc = frappe.get_doc("Sales Invoice", si.name)
si_doc.docstatus = 2
si_doc.on_cancel()
si_doc.docstatus = 1
si_doc.set_missing_item_details()
si_doc.on_submit()
frappe.db.commit()
except:
failed_list.append(si.name)
frappe.local.stockledger_exceptions = None
frappe.db.rollback()
print("Failed to repost: ", failed_list)

View File

@ -1,31 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import json
def execute():
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"]
stock_reco_to_be_reposted = []
for d in frappe.db.sql("""select name, reconciliation_json from `tabStock Reconciliation`
where docstatus=1 and creation > '2014-03-01'""", as_dict=1):
data = json.loads(d.reconciliation_json)
for row in data[data.index(head_row)+1:]:
if row[3] in ["", None]:
stock_reco_to_be_reposted.append(d.name)
break
for dn in stock_reco_to_be_reposted:
reco = frappe.get_doc("Stock Reconciliation", dn)
reco.docstatus = 2
reco.on_cancel()
reco.docstatus = 1
reco.validate()
reco.on_submit()
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)

View File

@ -1,17 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.reload_doc('manufacturing', 'doctype', 'bom_operation')
for d in frappe.db.sql("""select name from `tabBOM` where docstatus < 2""", as_dict=1):
try:
bom = frappe.get_doc('BOM', d.name)
bom.flags.ignore_validate_update_after_submit = True
bom.calculate_cost()
bom.save()
frappe.db.commit()
except:
frappe.db.rollback()

View File

@ -1,9 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.db.sql("""update `tabStock Entry` set purpose='Manufacture' where purpose='Manufacture/Repack' and ifnull(work_order,"")!="" """)
frappe.db.sql("""update `tabStock Entry` set purpose='Repack' where purpose='Manufacture/Repack' and ifnull(work_order,"")="" """)

View File

@ -1,15 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import print_function, unicode_literals
import frappe
def execute():
country = frappe.db.get_single_value("Global Defaults", "country")
if not country:
print("Country not specified in Global Defaults")
return
for company in frappe.db.sql_list("""select name from `tabCompany`
where ifnull(country, '')=''"""):
frappe.db.set_value("Company", company, "country", country)

View File

@ -1,65 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
frappe.db.sql("update tabItem set has_batch_no = 0 where ifnull(has_batch_no, '') = ''")
frappe.db.sql("update tabItem set has_serial_no = 0 where ifnull(has_serial_no, '') = ''")
item_list = frappe.db.sql("""select name, has_batch_no, has_serial_no from tabItem
where is_stock_item = 1""", as_dict=1)
sle_count = get_sle_count()
sle_with_batch = get_sle_with_batch()
sle_with_serial = get_sle_with_serial()
batch_items = get_items_with_batch()
serialized_items = get_items_with_serial()
for d in item_list:
if d.has_batch_no == 1:
if d.name not in batch_items and sle_count.get(d.name) and sle_count.get(d.name) != sle_with_batch.get(d.name):
frappe.db.set_value("Item", d.name, "has_batch_no", 0)
else:
if d.name in batch_items or (sle_count.get(d.name) and sle_count.get(d.name) == sle_with_batch.get(d.name)):
frappe.db.set_value("Item", d.name, "has_batch_no", 1)
if d.has_serial_no == 1:
if d.name not in serialized_items and sle_count.get(d.name) and sle_count.get(d.name) != sle_with_serial.get(d.name):
frappe.db.set_value("Item", d.name, "has_serial_no", 0)
else:
if d.name in serialized_items or (sle_count.get(d.name) and sle_count.get(d.name) == sle_with_serial.get(d.name)):
frappe.db.set_value("Item", d.name, "has_serial_no", 1)
def get_sle_count():
sle_count = {}
for d in frappe.db.sql("""select item_code, count(name) as cnt from `tabStock Ledger Entry` group by item_code""", as_dict=1):
sle_count.setdefault(d.item_code, d.cnt)
return sle_count
def get_sle_with_batch():
sle_with_batch = {}
for d in frappe.db.sql("""select item_code, count(name) as cnt from `tabStock Ledger Entry`
where ifnull(batch_no, '') != '' group by item_code""", as_dict=1):
sle_with_batch.setdefault(d.item_code, d.cnt)
return sle_with_batch
def get_sle_with_serial():
sle_with_serial = {}
for d in frappe.db.sql("""select item_code, count(name) as cnt from `tabStock Ledger Entry`
where ifnull(serial_no, '') != '' group by item_code""", as_dict=1):
sle_with_serial.setdefault(d.item_code, d.cnt)
return sle_with_serial
def get_items_with_batch():
return frappe.db.sql_list("select item from tabBatch")
def get_items_with_serial():
return frappe.db.sql_list("select item_code from `tabSerial No`")

View File

@ -1,9 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
global_defaults = frappe.get_doc("Global Defaults", "Global Defaults")
global_defaults.toggle_rounded_total()

Some files were not shown because too many files have changed in this diff Show More