Skip to content

Commit

Permalink
Merge pull request #31137 from frappe/version-13-hotfix
Browse files Browse the repository at this point in the history
chore: Weekly release for version-13
  • Loading branch information
deepeshgarg007 authored May 26, 2022
2 parents d9f7647 + 8c2f203 commit 63288fc
Show file tree
Hide file tree
Showing 47 changed files with 725 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ def test_cost_center_wise_posting(self):
expense_account="Cost of Goods Sold - TPC",
rate=400,
debit_to="Debtors - TPC",
currency="USD",
customer="_Test Customer USD",
)

create_sales_invoice(
company=company,
cost_center=cost_center2,
income_account="Sales - TPC",
expense_account="Cost of Goods Sold - TPC",
rate=200,
debit_to="Debtors - TPC",
currency="USD",
customer="_Test Customer USD",
)

pcv = self.make_period_closing_voucher(submit=False)
Expand Down Expand Up @@ -119,14 +124,17 @@ def test_period_closing_with_finance_book_entries(self):
surplus_account = create_account()
cost_center = create_cost_center("Test Cost Center 1")

create_sales_invoice(
si = create_sales_invoice(
company=company,
income_account="Sales - TPC",
expense_account="Cost of Goods Sold - TPC",
cost_center=cost_center,
rate=400,
debit_to="Debtors - TPC",
currency="USD",
customer="_Test Customer USD",
)

jv = make_journal_entry(
account1="Cash - TPC",
account2="Sales - TPC",
Expand Down
10 changes: 6 additions & 4 deletions erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ frappe.ui.form.on('POS Closing Entry', {
pos_opening_entry(frm) {
if (frm.doc.pos_opening_entry && frm.doc.period_start_date && frm.doc.period_end_date && frm.doc.user) {
reset_values(frm);
frm.trigger("set_opening_amounts");
frm.trigger("get_pos_invoices");
frappe.run_serially([
() => frm.trigger("set_opening_amounts"),
() => frm.trigger("get_pos_invoices")
]);
}
},

set_opening_amounts(frm) {
frappe.db.get_doc("POS Opening Entry", frm.doc.pos_opening_entry)
return frappe.db.get_doc("POS Opening Entry", frm.doc.pos_opening_entry)
.then(({ balance_details }) => {
balance_details.forEach(detail => {
frm.add_child("payment_reconciliation", {
Expand All @@ -83,7 +85,7 @@ frappe.ui.form.on('POS Closing Entry', {
},

get_pos_invoices(frm) {
frappe.call({
return frappe.call({
method: 'erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices',
args: {
start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date),
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def test_multiple_pricing_rules_with_min_qty(self):
title="_Test Pricing Rule with Min Qty - 2",
)

si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1, currency="USD")
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1)
item = si.items[0]
item.stock_qty = 1
si.save()
Expand Down
49 changes: 33 additions & 16 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
let row = frappe.get_doc(d.doctype, d.name)
set_timesheet_detail_rate(row.doctype, row.name, me.frm.doc.currency, row.timesheet_detail)
});
frm.trigger("calculate_timesheet_totals");
this.frm.trigger("calculate_timesheet_totals");
}
}
});
Expand Down Expand Up @@ -885,27 +885,44 @@ frappe.ui.form.on('Sales Invoice', {

set_timesheet_data: function(frm, timesheets) {
frm.clear_table("timesheets")
timesheets.forEach(timesheet => {
timesheets.forEach(async (timesheet) => {
if (frm.doc.currency != timesheet.currency) {
frappe.call({
method: "erpnext.setup.utils.get_exchange_rate",
args: {
from_currency: timesheet.currency,
to_currency: frm.doc.currency
},
callback: function(r) {
if (r.message) {
exchange_rate = r.message;
frm.events.append_time_log(frm, timesheet, exchange_rate);
}
}
});
const exchange_rate = await frm.events.get_exchange_rate(
frm, timesheet.currency, frm.doc.currency
)
frm.events.append_time_log(frm, timesheet, exchange_rate)
} else {
frm.events.append_time_log(frm, timesheet, 1.0);
}
});
},

async get_exchange_rate(frm, from_currency, to_currency) {
if (
frm.exchange_rates
&& frm.exchange_rates[from_currency]
&& frm.exchange_rates[from_currency][to_currency]
) {
return frm.exchange_rates[from_currency][to_currency];
}

return frappe.call({
method: "erpnext.setup.utils.get_exchange_rate",
args: {
from_currency,
to_currency
},
callback: function(r) {
if (r.message) {
// cache exchange rates
frm.exchange_rates = frm.exchange_rates || {};
frm.exchange_rates[from_currency] = frm.exchange_rates[from_currency] || {};
frm.exchange_rates[from_currency][to_currency] = r.message;
}
}
});
},

append_time_log: function(frm, time_log, exchange_rate) {
const row = frm.add_child("timesheets");
row.activity_type = time_log.activity_type;
Expand All @@ -916,7 +933,7 @@ frappe.ui.form.on('Sales Invoice', {
row.billing_hours = time_log.billing_hours;
row.billing_amount = flt(time_log.billing_amount) * flt(exchange_rate);
row.timesheet_detail = time_log.name;
row.project_name = time_log.project_name;
row.project_name = time_log.project_name;

frm.refresh_field("timesheets");
frm.trigger("calculate_timesheet_totals");
Expand Down
15 changes: 15 additions & 0 deletions erpnext/accounts/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,18 @@ def get_default_contact(doctype, name):
return None
else:
return None


def add_party_account(party_type, party, company, account):
doc = frappe.get_doc(party_type, party)
account_exists = False
for d in doc.get("accounts"):
if d.account == account:
account_exists = True

if not account_exists:
accounts = {"company": company, "account": account}

doc.append("accounts", accounts)

doc.save()
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ def get_loan_entries(filters):
amount_field = (loan_doc.disbursed_amount).as_("credit")
posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else:
amount_field = (loan_doc.amount_paid).as_("debit")
posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account
salary_condition = loan_doc.repay_from_salary == 0

query = (
frappe.qb.from_(loan_doc)
Expand All @@ -214,14 +216,12 @@ def get_loan_entries(filters):
posting_date,
)
.where(loan_doc.docstatus == 1)
.where(salary_condition)
.where(account == filters.get("account"))
.where(posting_date <= getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") > getdate(filters.get("report_date")))
)

if doctype == "Loan Repayment":
query.where(loan_doc.repay_from_salary == 0)

entries = query.run(as_dict=1)
loan_docs.extend(entries)

Expand Down Expand Up @@ -267,15 +267,17 @@ def get_loan_amount(filters):
amount_field = Sum(loan_doc.disbursed_amount)
posting_date = (loan_doc.disbursement_date).as_("posting_date")
account = loan_doc.disbursement_account
salary_condition = loan_doc.docstatus == 1
else:
amount_field = Sum(loan_doc.amount_paid)
posting_date = (loan_doc.posting_date).as_("posting_date")
account = loan_doc.payment_account

salary_condition = loan_doc.repay_from_salary == 0
amount = (
frappe.qb.from_(loan_doc)
.select(amount_field)
.where(loan_doc.docstatus == 1)
.where(salary_condition)
.where(account == filters.get("account"))
.where(posting_date > getdate(filters.get("report_date")))
.where(ifnull(loan_doc.clearance_date, "4000-01-01") <= getdate(filters.get("report_date")))
Expand Down
5 changes: 4 additions & 1 deletion erpnext/accounts/report/cash_flow/cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ def get_report_summary(summary_data, currency):
def get_chart_data(columns, data):
labels = [d.get("label") for d in columns[2:]]
datasets = [
{"name": account.get("account").replace("'", ""), "values": [account.get("total")]}
{
"name": account.get("account").replace("'", ""),
"values": [account.get(d.get("fieldname")) for d in columns[2:]],
}
for account in data
if account.get("parent_account") == None and account.get("currency")
]
Expand Down
23 changes: 23 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from erpnext.accounts.party import (
get_party_account,
get_party_account_currency,
get_party_gle_currency,
validate_party_frozen_disabled,
)
from erpnext.accounts.utils import get_account_currency, get_fiscal_years, validate_fiscal_year
Expand Down Expand Up @@ -169,6 +170,7 @@ def validate(self):

self.validate_party()
self.validate_currency()
self.validate_party_account_currency()

if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
pos_check_field = "is_pos" if self.doctype == "Sales Invoice" else "is_paid"
Expand Down Expand Up @@ -1445,6 +1447,27 @@ def validate_currency(self):
# at quotation / sales order level and we shouldn't stop someone
# from creating a sales invoice if sales order is already created

def validate_party_account_currency(self):
if self.doctype not in ("Sales Invoice", "Purchase Invoice"):
return

if self.is_opening == "Yes":
return

party_type, party = self.get_party()
party_gle_currency = get_party_gle_currency(party_type, party, self.company)
party_account = (
self.get("debit_to") if self.doctype == "Sales Invoice" else self.get("credit_to")
)
party_account_currency = get_account_currency(party_account)

if not party_gle_currency and (party_account_currency != self.currency):
frappe.throw(
_("Party Account {0} currency and document currency should be same").format(
frappe.bold(party_account)
)
)

def delink_advance_entries(self, linked_doc_name):
total_allocated_amount = 0
for adv in self.advances:
Expand Down
6 changes: 6 additions & 0 deletions erpnext/erpnext_integrations/connectors/shopify_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from frappe import _
from frappe.utils import cint, cstr, flt, get_datetime, get_request_session, getdate, nowdate

from erpnext import get_company_currency
from erpnext.erpnext_integrations.doctype.shopify_log.shopify_log import (
dump_request_data,
make_shopify_log,
Expand Down Expand Up @@ -143,6 +144,10 @@ def create_sales_order(shopify_order, shopify_settings, company=None):
"taxes": get_order_taxes(shopify_order, shopify_settings),
"apply_discount_on": "Grand Total",
"discount_amount": get_discounted_amount(shopify_order),
"currency": frappe.get_value(
"Customer", customer or shopify_settings.default_customer, "default_currency"
)
or get_company_currency(shopify_settings.company),
}
)

Expand Down Expand Up @@ -178,6 +183,7 @@ def create_sales_invoice(shopify_order, shopify_settings, so, old_order_sync=Fal
si.set_posting_time = 1
si.posting_date = posting_date
si.due_date = posting_date
si.currency = so.currency
si.naming_series = shopify_settings.sales_invoice_series or "SI-Shopify-"
si.flags.ignore_mandatory = True
set_cost_center(si.items, shopify_settings.cost_center)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def setup_shopify(cls):
"warehouse": "_Test Warehouse - _TC",
"cash_bank_account": "Cash - _TC",
"account": "Cash - _TC",
"company": "_Test Company",
"customer_group": "_Test Customer Group",
"cost_center": "Main - _TC",
"taxes": [{"shopify_tax": "International Shipping", "tax_account": "Legal Expenses - _TC"}],
Expand Down
1 change: 1 addition & 0 deletions erpnext/healthcare/doctype/lab_test/test_lab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def create_sales_invoice():
sales_invoice.customer = frappe.db.get_value("Patient", patient, "customer")
sales_invoice.due_date = getdate()
sales_invoice.company = "_Test Company"
sales_invoice.currency = "INR"
sales_invoice.debit_to = get_receivable_account("_Test Company")

tests = [insulin_resistance_template, blood_test_template]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from frappe.model.mapper import get_mapped_doc
from frappe.utils import flt, get_link_to_form, get_time, getdate

from erpnext import get_company_currency
from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import (
get_income_account,
get_receivable_account,
Expand Down Expand Up @@ -252,6 +253,10 @@ def create_sales_invoice(appointment_doc):
sales_invoice = frappe.new_doc("Sales Invoice")
sales_invoice.patient = appointment_doc.patient
sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer")
sales_invoice.currency = frappe.get_value(
"Customer", sales_invoice.customer, "default_currency"
) or get_company_currency(appointment_doc.company)

sales_invoice.appointment = appointment_doc.name
sales_invoice.due_date = getdate()
sales_invoice.company = appointment_doc.company
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def create_patient(
patient.mobile = mobile
patient.email = email
patient.customer = customer
patient.default_currency = "INR"
patient.invite_user = create_user
patient.save(ignore_permissions=True)

Expand Down
5 changes: 5 additions & 0 deletions erpnext/healthcare/doctype/therapy_plan/therapy_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from frappe.model.document import Document
from frappe.utils import flt

from erpnext import get_company_currency


class TherapyPlan(Document):
def validate(self):
Expand Down Expand Up @@ -72,6 +74,9 @@ def make_sales_invoice(reference_name, patient, company, therapy_plan_template):
si.company = company
si.patient = patient
si.customer = frappe.db.get_value("Patient", patient, "customer")
si.currency = frappe.get_value(
"Customer", si.customer, "default_currency"
) or get_company_currency(si.company)

item = frappe.db.get_value("Therapy Plan Template", therapy_plan_template, "linked_item")
price_list, price_list_currency = frappe.db.get_values(
Expand Down
7 changes: 4 additions & 3 deletions erpnext/hr/doctype/employee_advance/employee_advance.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"actions": [],
"allow_import": 1,
"autoname": "naming_series:",
"creation": "2017-10-09 14:26:29.612365",
"creation": "2022-01-17 18:36:51.450395",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
Expand Down Expand Up @@ -121,7 +121,7 @@
"fieldtype": "Select",
"label": "Status",
"no_copy": 1,
"options": "Draft\nPaid\nUnpaid\nClaimed\nCancelled",
"options": "Draft\nPaid\nUnpaid\nClaimed\nReturned\nPartly Claimed and Returned\nCancelled",
"read_only": 1
},
{
Expand Down Expand Up @@ -200,7 +200,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2021-09-11 18:38:38.617478",
"modified": "2022-05-23 19:33:52.345823",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Advance",
Expand Down Expand Up @@ -236,5 +236,6 @@
"search_fields": "employee,employee_name",
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "employee_name",
"track_changes": 1
}
Loading

0 comments on commit 63288fc

Please sign in to comment.