Skip to content

Commit

Permalink
Merge pull request frappe#28916 from deepeshgarg007/multicurrency_sub…
Browse files Browse the repository at this point in the history
…scription

fix: Multicurrency invoices using subscription
  • Loading branch information
deepeshgarg007 committed Dec 17, 2021
2 parents 4cb5b62 + 6ab7530 commit 238403d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions erpnext/accounts/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_accounting_dimensions,
)
from erpnext.accounts.doctype.subscription_plan.subscription_plan import get_plan_rate
from erpnext.accounts.party import get_party_account_currency


class Subscription(Document):
Expand Down Expand Up @@ -355,6 +356,9 @@ def create_invoice(self, prorate):
if frappe.db.get_value('Supplier', self.party, 'tax_withholding_category'):
invoice.apply_tds = 1

### Add party currency to invoice
invoice.currency = get_party_account_currency(self.party_type, self.party, self.company)

## Add dimensions in invoice for subscription:
accounting_dimensions = get_accounting_dimensions()

Expand Down
42 changes: 42 additions & 0 deletions erpnext/accounts/doctype/subscription/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,38 @@ def create_plan():
plan.billing_interval_count = 3
plan.insert()

if not frappe.db.exists('Subscription Plan', '_Test Plan Multicurrency'):
plan = frappe.new_doc('Subscription Plan')
plan.plan_name = '_Test Plan Multicurrency'
plan.item = '_Test Non Stock Item'
plan.price_determination = "Fixed Rate"
plan.cost = 50
plan.currency = 'USD'
plan.billing_interval = 'Month'
plan.billing_interval_count = 1
plan.insert()

def create_parties():
if not frappe.db.exists('Supplier', '_Test Supplier'):
supplier = frappe.new_doc('Supplier')
supplier.supplier_name = '_Test Supplier'
supplier.supplier_group = 'All Supplier Groups'
supplier.insert()

if not frappe.db.exists('Customer', '_Test Subscription Customer'):
customer = frappe.new_doc('Customer')
customer.customer_name = '_Test Subscription Customer'
customer.billing_currency = 'USD'
customer.append('accounts', {
'company': '_Test Company',
'account': '_Test Receivable USD - _TC'
})
customer.insert()

class TestSubscription(unittest.TestCase):
def setUp(self):
create_plan()
create_parties()

def test_create_subscription_with_trial_with_correct_period(self):
subscription = frappe.new_doc('Subscription')
Expand Down Expand Up @@ -637,3 +660,22 @@ def test_subscription_without_generate_invoice_past_due(self):

subscription.process()
self.assertEqual(len(subscription.invoices), 1)

def test_multicurrency_subscription(self):
subscription = frappe.new_doc('Subscription')
subscription.party_type = 'Customer'
subscription.party = '_Test Subscription Customer'
subscription.generate_invoice_at_period_start = 1
subscription.company = '_Test Company'
# select subscription start date as '2018-01-15'
subscription.start_date = '2018-01-01'
subscription.append('plans', {'plan': '_Test Plan Multicurrency', 'qty': 1})
subscription.save()

subscription.process()
self.assertEqual(len(subscription.invoices), 1)
self.assertEqual(subscription.status, 'Unpaid')

# Check the currency of the created invoice
currency = frappe.db.get_value('Sales Invoice', subscription.invoices[0].invoice, 'currency')
self.assertEqual(currency, 'USD')

0 comments on commit 238403d

Please sign in to comment.