Commit 5c0e294f authored by Charles-Henri Decultot's avatar Charles-Henri Decultot
Browse files

Merge branch 'staging'

parents 95377f1b dc8e57b4
......@@ -5,7 +5,7 @@ import frappe
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
__version__ = '1.3.15'
__version__ = '1.4.0'
def get_default_company(user=None):
'''Get default company for user'''
......
......@@ -81,6 +81,9 @@ def get():
},
_("Expenses"): {
_("Direct Expenses"): {
_("Direct Expenses Account"): {
"account_type": "Expense Account"
},
_("Stock Expenses"): {
_("Cost of Goods Sold"): {
"account_type": "Cost of Goods Sold"
......
......@@ -13,11 +13,11 @@ from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sal
class TestAccountingPeriod(unittest.TestCase):
def test_overlap(self):
ap1 = create_accounting_period(start_date = "2018-04-01",
end_date = "2018-06-30", company = "Wind Power LLC")
end_date = "2018-06-30", company = "Wind Power")
ap1.save()
ap2 = create_accounting_period(start_date = "2018-06-30",
end_date = "2018-07-10", company = "Wind Power LLC", period_name = "Test Accounting Period 1")
end_date = "2018-07-10", company = "Wind Power", period_name = "Test Accounting Period 1")
self.assertRaises(OverlapError, ap2.save)
def test_accounting_period(self):
......
......@@ -471,6 +471,7 @@ def make_payment_request(**args):
pr = frappe.new_doc("Payment Request")
pr.update({
"currency": ref_doc.currency,
"no_payment_link": args.no_payment_link,
"grand_total": grand_total,
"email_to": args.recipient_id or "",
"subject": _("Payment Request for {0}").format(args.dn),
......@@ -541,21 +542,26 @@ def get_existing_payment_request_amount(ref_dt, ref_dn):
def get_gateway_details(args):
"""return gateway and payment account of default payment gateway"""
filters = {}
if args.get("currency"):
filters.update({"currency": args.get("currency")})
if args.get("payment_gateway"):
return get_payment_gateway_account(args.get("payment_gateway"))
filters.update({"payment_gateway": args.get("payment_gateway")})
return get_payment_gateway_account(filters)
if args.order_type == "Shopping Cart":
payment_gateway_account = frappe.get_doc("Shopping Cart Settings").payment_gateway_account
return get_payment_gateway_account(payment_gateway_account)
gateway_account = get_payment_gateway_account({"is_default": 1})
filters.update({"is_default": 1})
gateway_account = get_payment_gateway_account(filters)
return gateway_account
def get_payment_gateway_account(args):
return frappe.db.get_value("Payment Gateway Account", args,
["name", "payment_gateway", "message"],
as_dict=1)
["name", "payment_gateway"], as_dict=1)
@frappe.whitelist()
def get_print_format_list(ref_doctype):
......
......@@ -1702,7 +1702,7 @@ class TestSalesInvoice(unittest.TestCase):
})
customer.append("companies", {
"company": "Wind Power LLC"
"company": "Wind Power"
})
customer.insert()
......@@ -1713,7 +1713,7 @@ class TestSalesInvoice(unittest.TestCase):
"supplier_name": "_Test Internal Supplier",
"doctype": "Supplier",
"is_internal_supplier": 1,
"represents_company": "Wind Power LLC"
"represents_company": "Wind Power"
})
supplier.append("companies", {
......@@ -1723,7 +1723,7 @@ class TestSalesInvoice(unittest.TestCase):
supplier.insert()
si = create_sales_invoice(
company = "Wind Power LLC",
company = "Wind Power",
customer = "_Test Internal Customer",
debit_to = "Debtors - WP",
warehouse = "Stores - WP",
......
......@@ -101,15 +101,18 @@ class Subscription(Document):
if not self.has_invoice_for_period():
self.generate_invoice(payment_entry=payment_entry)
self.update_subscription_period(add_days(self.current_invoice_end, 1))
self.save()
self.generate_sales_order()
else:
self.update_subscription_period(add_days(self.current_invoice_end, 1))
self.save()
self.generate_sales_order()
elif self.generate_invoice_at_period_start:
self.set_plan_details_status()
if self.has_invoice_for_period() and self.period_has_passed(self.current_invoice_end):
self.update_subscription_period(add_days(self.current_invoice_end, 1))
self.save()
self.generate_sales_order()
self.generate_invoice(payment_entry=payment_entry)
......@@ -117,8 +120,6 @@ class Subscription(Document):
self.generate_sales_order()
self.generate_invoice(payment_entry=payment_entry)
self.save()
@staticmethod
def period_has_passed(end_date):
if not end_date:
......@@ -565,7 +566,8 @@ class Subscription(Document):
filters={
"event_type": "Payment request created",
"period_start": self.current_invoice_start ,
"period_end": self.current_invoice_end
"period_end": self.current_invoice_end,
"subscription": self.name
}
):
return False
......@@ -791,7 +793,8 @@ def check_gateway_payments():
"party": doc.customer,
"submit_doc": True,
"mute_email": True,
"payment_gateway": doc.payment_gateway
"payment_gateway": doc.payment_gateway,
"currency": doc.currency
})
if pr.get("payment_gateway_account") and float(pr.get("grand_total")) > 0:
......
......@@ -78,6 +78,8 @@ def get_entries(filters):
order by si.posting_date DESC, si.name DESC""".format(conditions), filters, as_list=1)
mops = tuple([frappe.db.escape(x.parent) for x in frappe.get_all("Mode of Payment Account", {"default_account": filters.get("account")}, "parent")])
if not mops:
frappe.throw(_("Please create at least one mode of payment for this bank account first"))
expense_claims = frappe.db.sql("""SELECT
"Expense Claim", name, posting_date, remark, clearance_date, employee,
total_amount_reimbursed
......
......@@ -518,4 +518,4 @@ erpnext.asset.transfer_asset = function() {
}
}
});
};
\ No newline at end of file
};
This diff is collapsed.
......@@ -6,7 +6,7 @@ from __future__ import unicode_literals
import frappe, erpnext, math, json
from frappe import _
from six import string_types
from frappe.utils import flt, add_months, cint, nowdate, getdate, today, date_diff, month_diff, add_days
from frappe.utils import flt, add_months, cint, nowdate, getdate, today, date_diff, month_diff, add_days, get_last_day
from frappe.model.document import Document
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
from erpnext.assets.doctype.asset.depreciation \
......@@ -194,8 +194,11 @@ class Asset(AccountsController):
d.total_number_of_depreciations, d)
if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1:
schedule_date = add_months(d.depreciation_start_date,
n * cint(d.frequency_of_depreciation))
if d.depreciation_method == "Prorated Straight Line (360 Days)" and self.schedules:
schedule_date = add_months(self.schedules[-1].schedule_date, cint(d.frequency_of_depreciation))
else:
schedule_date = add_months(d.depreciation_start_date,
n * cint(d.frequency_of_depreciation))
# schedule date will be a year later from start date
# so monthly schedule date is calculated by removing 11 months from it
......@@ -220,7 +223,11 @@ class Asset(AccountsController):
monthly_schedule_date = add_months(schedule_date, 1)
schedule_date = add_days(schedule_date, days)
if d.depreciation_method == "Prorated Straight Line (360 Days)":
schedule_date = add_months(self.available_for_use_date,
n * cint(d.frequency_of_depreciation))
else:
schedule_date = add_days(schedule_date, days)
last_schedule_date = schedule_date
if not depreciation_amount: continue
......@@ -284,7 +291,10 @@ class Asset(AccountsController):
has_pro_rata = False
days = date_diff(row.depreciation_start_date, self.available_for_use_date) + 1
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation)
if row.depreciation_method == "Prorated Straight Line (360 Days)":
total_days = 360
else:
total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation)
if days < total_days:
has_pro_rata = True
......@@ -373,6 +383,8 @@ class Asset(AccountsController):
depreciation_amount = (flt(row.value_after_depreciation) -
flt(row.expected_value_after_useful_life)) / depreciation_left
elif row.depreciation_method == 'Prorated Straight Line (360 Days)':
return flt(row.value_after_depreciation) * (1.0 / cint(row.total_number_of_depreciations))
else:
depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100), precision)
......@@ -687,9 +699,15 @@ def is_cwip_accounting_enabled(asset_category):
return cint(frappe.db.get_value("Asset Category", asset_category, "enable_cwip_accounting"))
def get_pro_rata_amt(row, depreciation_amount, from_date, to_date):
days = date_diff(to_date, from_date)
months = month_diff(to_date, from_date)
total_days = get_total_days(to_date, row.frequency_of_depreciation)
if row.depreciation_method == "Prorated Straight Line (360 Days)":
todate = get_last_day(from_date) if getdate(to_date).month == 12 else to_date
fromdate = get_last_day(to_date) if getdate(from_date).month == 12 else from_date
days = date_diff(todate, fromdate) + (cint(months) - 1) * 30
total_days = min(get_total_days(to_date, row.frequency_of_depreciation), 360)
else:
total_days = get_total_days(to_date, row.frequency_of_depreciation)
days = date_diff(to_date, from_date)
return (depreciation_amount * flt(days)) / flt(total_days), days, months
......@@ -697,4 +715,4 @@ def get_total_days(date, frequency):
period_start_date = add_months(date,
cint(frequency) * -1)
return date_diff(date, period_start_date)
\ No newline at end of file
return date_diff(date, period_start_date)
......@@ -30,7 +30,6 @@ frappe.listview_settings['Asset'] = {
} else if (doc.status === "Draft") {
return [__("Draft"), "red", "status,=,Draft"];
}
},
onload: function(me) {
......@@ -50,5 +49,5 @@ frappe.listview_settings['Asset'] = {
}
});
});
}
},
}
\ No newline at end of file
{
"allow_import": 1,
"allow_rename": 1,
"autoname": "field:asset_category_name",
"creation": "2016-03-01 17:41:39.778765",
"doctype": "DocType",
"document_type": "Document",
"engine": "InnoDB",
"field_order": [
"asset_category_name",
"column_break_3",
"depreciation_options",
"enable_cwip_accounting",
"finance_book_detail",
"finance_books",
"section_break_2",
"accounts"
],
"fields": [
{
"fieldname": "asset_category_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Asset Category Name",
"reqd": 1,
"unique": 1
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "finance_book_detail",
"fieldtype": "Section Break",
"label": "Finance Book Detail"
},
{
"fieldname": "finance_books",
"fieldtype": "Table",
"label": "Finance Books",
"options": "Asset Finance Book"
},
{
"fieldname": "section_break_2",
"fieldtype": "Section Break",
"label": "Accounts"
},
{
"fieldname": "accounts",
"fieldtype": "Table",
"label": "Accounts",
"options": "Asset Category Account",
"reqd": 1
},
{
"fieldname": "depreciation_options",
"fieldtype": "Section Break",
"label": "Depreciation Options"
},
{
"default": "0",
"fieldname": "enable_cwip_accounting",
"fieldtype": "Check",
"label": "Enable Capital Work in Progress Accounting"
}
],
"modified": "2019-10-11 12:19:59.759136",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Category",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"import": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts User",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"import": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Quality Manager",
"share": 1,
"write": 1
}
],
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC"
}
\ No newline at end of file
"allow_import": 1,
"allow_rename": 1,
"autoname": "field:asset_category_name",
"creation": "2016-03-01 17:41:39.778765",
"doctype": "DocType",
"document_type": "Document",
"engine": "InnoDB",
"field_order": [
"asset_category_name",
"column_break_3",
"depreciation_options",
"enable_cwip_accounting",
"finance_book_detail",
"finance_books",
"section_break_2",
"accounts"
],
"fields": [
{
"fieldname": "asset_category_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Asset Category Name",
"reqd": 1,
"unique": 1
},
{
"fieldname": "column_break_3",
"fieldtype": "Column Break"
},
{
"fieldname": "finance_book_detail",
"fieldtype": "Section Break",
"label": "Finance Book Detail"
},
{
"fieldname": "finance_books",
"fieldtype": "Table",
"label": "Finance Books",
"options": "Asset Finance Book"
},
{
"fieldname": "section_break_2",
"fieldtype": "Section Break",
"label": "Accounts"
},
{
"fieldname": "accounts",
"fieldtype": "Table",
"label": "Accounts",
"options": "Asset Category Account",
"reqd": 1
},
{
"fieldname": "depreciation_options",
"fieldtype": "Section Break",
"label": "Depreciation Options"
},
{
"default": "0",
"fieldname": "enable_cwip_accounting",
"fieldtype": "Check",
"label": "Enable Capital Work in Progress Accounting"
}
],
"modified": "2019-10-11 12:19:59.759136",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Category",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"import": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts User",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"import": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Quality Manager",
"share": 1,
"write": 1
}
],
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC"
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ class AssetCategory(Document):
def get_asset_category_account(fieldname, item=None, asset=None, account=None, asset_category = None, company = None):
if item and frappe.db.get_value("Item", item, "is_fixed_asset"):
asset_category = frappe.db.get_value("Item", item, ["asset_category"])
elif not asset_category or not company:
if account:
if frappe.db.get_value("Account", account, "account_type") != "Fixed Asset":
......
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
"creation": "2018-05-08 14:44:37.095570",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"editable_grid": 1,
"engine": "InnoDB",
"actions": [],
"creation": "2018-05-08 14:44:37.095570",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"finance_book",
"depreciation_method",
"total_number_of_depreciations",
"column_break_5",
"frequency_of_depreciation",
"depreciation_start_date",
"expected_value_after_useful_life",
"value_after_depreciation",
"rate_of_depreciation"
],
"fields": [
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "",
"fetch_if_empty": 0,
"fieldname": "finance_book",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Finance Book",
"length": 0,