+
+ {{__('Note: On checking Is Mandatory the accounting dimension will become mandatory against that specific account for all accounting transactions')}}
+
+
+
`;
+
+ frm.set_df_property('dimension_filter_help', 'options', help_content);
},
onload: function(frm) {
frm.set_query('applicable_on_account', 'accounts', function() {
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
index 7736b2dffb2..0f3fbc0b8d3 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
@@ -14,7 +14,9 @@
"section_break_4",
"accounts",
"column_break_6",
- "dimensions"
+ "dimensions",
+ "section_break_10",
+ "dimension_filter_help"
],
"fields": [
{
@@ -89,11 +91,24 @@
"reqd": 1,
"show_days": 1,
"show_seconds": 1
+ },
+ {
+ "fieldname": "dimension_filter_help",
+ "fieldtype": "HTML",
+ "label": "Dimension Filter Help",
+ "show_days": 1,
+ "show_seconds": 1
+ },
+ {
+ "fieldname": "section_break_10",
+ "fieldtype": "Section Break",
+ "show_days": 1,
+ "show_seconds": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2020-11-24 12:34:42.458713",
+ "modified": "2021-02-03 12:04:58.678402",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounting Dimension Filter",
@@ -110,6 +125,30 @@
"role": "System Manager",
"share": 1,
"write": 1
+ },
+ {
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts User",
+ "share": 1,
+ "write": 1
+ },
+ {
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "export": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Accounts Manager",
+ "share": 1,
+ "write": 1
}
],
"quick_entry": 1,
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
index fa700e115ce..7877abd0263 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
@@ -13,17 +13,21 @@ class TestAccountingDimensionFilter(unittest.TestCase):
def setUp(self):
create_dimension()
create_accounting_dimension_filter()
+ self.invoice_list = []
def test_allowed_dimension_validation(self):
si = create_sales_invoice(do_not_save=1)
si.items[0].cost_center = 'Main - _TC'
+ si.department = 'Accounts - _TC'
si.location = 'Block 1'
si.save()
self.assertRaises(InvalidAccountDimensionError, si.submit)
+ self.invoice_list.append(si)
def test_mandatory_dimension_validation(self):
si = create_sales_invoice(do_not_save=1)
+ si.department = ''
si.location = 'Block 1'
# Test with no department for Sales Account
@@ -32,11 +36,17 @@ class TestAccountingDimensionFilter(unittest.TestCase):
si.save()
self.assertRaises(MandatoryAccountDimensionError, si.submit)
+ self.invoice_list.append(si)
def tearDown(self):
disable_dimension_filter()
disable_dimension()
+ for si in self.invoice_list:
+ si.load_from_db()
+ if si.docstatus == 1:
+ si.cancel()
+
def create_accounting_dimension_filter():
if not frappe.db.get_value('Accounting Dimension Filter',
{'accounting_dimension': 'Cost Center'}):
@@ -71,7 +81,7 @@ def create_accounting_dimension_filter():
}],
'dimensions': [{
'accounting_dimension': 'Department',
- 'dimension_value': '_Test Department - _TC'
+ 'dimension_value': 'Accounts - _TC'
}]
}).insert()
else:
diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
index bbcfde6f368..e05408606f9 100644
--- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
+++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json
@@ -22,6 +22,7 @@
"book_asset_depreciation_entry_automatically",
"add_taxes_from_item_tax_template",
"automatically_fetch_payment_terms",
+ "delete_linked_ledger_entries",
"deferred_accounting_settings_section",
"automatically_process_deferred_accounting_entry",
"book_deferred_entries_based_on",
@@ -268,4 +269,4 @@
"sort_field": "modified",
"sort_order": "ASC",
"track_changes": 1
-}
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/bank/bank.js b/erpnext/accounts/doctype/bank/bank.js
index de9498e0752..49b2b186c4b 100644
--- a/erpnext/accounts/doctype/bank/bank.js
+++ b/erpnext/accounts/doctype/bank/bank.js
@@ -1,5 +1,6 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
+frappe.provide('erpnext.integrations');
frappe.ui.form.on('Bank', {
onload: function(frm) {
@@ -20,7 +21,12 @@ frappe.ui.form.on('Bank', {
frm.set_df_property('address_and_contact', 'hidden', 0);
frappe.contacts.render_address_and_contact(frm);
}
- },
+ if (frm.doc.plaid_access_token) {
+ frm.add_custom_button(__('Refresh Plaid Link'), () => {
+ new erpnext.integrations.refreshPlaidLink(frm.doc.plaid_access_token);
+ });
+ }
+ }
});
@@ -40,4 +46,79 @@ let add_fields_to_mapping_table = function (frm) {
frm.doc.name).options = options;
frm.fields_dict.bank_transaction_mapping.grid.refresh();
-};
\ No newline at end of file
+};
+
+erpnext.integrations.refreshPlaidLink = class refreshPlaidLink {
+ constructor(access_token) {
+ this.access_token = access_token;
+ this.plaidUrl = 'https://cdn.plaid.com/link/v2/stable/link-initialize.js';
+ this.init_config();
+ }
+
+ async init_config() {
+ this.plaid_env = await frappe.db.get_single_value('Plaid Settings', 'plaid_env');
+ this.token = await this.get_link_token_for_update();
+ this.init_plaid();
+ }
+
+ async get_link_token_for_update() {
+ const token = frappe.xcall(
+ 'erpnext.erpnext_integrations.doctype.plaid_settings.plaid_settings.get_link_token_for_update',
+ { access_token: this.access_token }
+ )
+ if (!token) {
+ frappe.throw(__('Cannot retrieve link token for update. Check Error Log for more information'));
+ }
+ return token;
+ }
+
+ init_plaid() {
+ const me = this;
+ me.loadScript(me.plaidUrl)
+ .then(() => {
+ me.onScriptLoaded(me);
+ })
+ .then(() => {
+ if (me.linkHandler) {
+ me.linkHandler.open();
+ }
+ })
+ .catch((error) => {
+ me.onScriptError(error);
+ });
+ }
+
+ loadScript(src) {
+ return new Promise(function (resolve, reject) {
+ if (document.querySelector("script[src='" + src + "']")) {
+ resolve();
+ return;
+ }
+ const el = document.createElement('script');
+ el.type = 'text/javascript';
+ el.async = true;
+ el.src = src;
+ el.addEventListener('load', resolve);
+ el.addEventListener('error', reject);
+ el.addEventListener('abort', reject);
+ document.head.appendChild(el);
+ });
+ }
+
+ onScriptLoaded(me) {
+ me.linkHandler = Plaid.create({
+ env: me.plaid_env,
+ token: me.token,
+ onSuccess: me.plaid_success
+ });
+ }
+
+ onScriptError(error) {
+ frappe.msgprint(__("There was an issue connecting to Plaid's authentication server. Check browser console for more information"));
+ console.log(error);
+ }
+
+ plaid_success(token, response) {
+ frappe.show_alert({ message: __('Plaid Link Updated'), indicator: 'green' });
+ }
+};
diff --git a/erpnext/accounts/doctype/budget/budget.js b/erpnext/accounts/doctype/budget/budget.js
index e60bc60475e..e162e3222d3 100644
--- a/erpnext/accounts/doctype/budget/budget.js
+++ b/erpnext/accounts/doctype/budget/budget.js
@@ -11,7 +11,7 @@ frappe.ui.form.on('Budget', {
report_type: "Profit and Loss",
is_group: 0
}
- }
+ };
});
frm.set_query("monthly_distribution", function() {
@@ -19,7 +19,7 @@ frappe.ui.form.on('Budget', {
filters: {
fiscal_year: frm.doc.fiscal_year
}
- }
+ };
});
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py
index 0f115f9cc20..c5ec23c8295 100644
--- a/erpnext/accounts/doctype/budget/test_budget.py
+++ b/erpnext/accounts/doctype/budget/test_budget.py
@@ -122,8 +122,10 @@ class TestBudget(unittest.TestCase):
frappe.db.set_value("Budget", budget.name, "action_if_accumulated_monthly_budget_exceeded", "Stop")
+ project = frappe.get_value("Project", {"project_name": "_Test Project"})
+
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
- "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project="_Test Project", posting_date=nowdate())
+ "_Test Bank - _TC", 40000, "_Test Cost Center - _TC", project=project, posting_date=nowdate())
self.assertRaises(BudgetError, jv.submit)
@@ -147,8 +149,11 @@ class TestBudget(unittest.TestCase):
budget = make_budget(budget_against="Project")
+ project = frappe.get_value("Project", {"project_name": "_Test Project"})
+
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
- "_Test Bank - _TC", 250000, "_Test Cost Center - _TC", project="_Test Project", posting_date=nowdate())
+ "_Test Bank - _TC", 250000, "_Test Cost Center - _TC",
+ project=project, posting_date=nowdate())
self.assertRaises(BudgetError, jv.submit)
@@ -159,10 +164,10 @@ class TestBudget(unittest.TestCase):
budget = make_budget(budget_against="Cost Center")
month = now_datetime().month
- if month > 10:
- month = 10
+ if month > 9:
+ month = 9
- for i in range(month):
+ for i in range(month+1):
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
"_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True)
@@ -181,12 +186,14 @@ class TestBudget(unittest.TestCase):
budget = make_budget(budget_against="Project")
month = now_datetime().month
- if month > 10:
- month = 10
+ if month > 9:
+ month = 9
- for i in range(month):
+ project = frappe.get_value("Project", {"project_name": "_Test Project"})
+ for i in range(month + 1):
jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC",
- "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True, project="_Test Project")
+ "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True,
+ project=project)
self.assertTrue(frappe.db.get_value("GL Entry",
{"voucher_type": "Journal Entry", "voucher_no": jv.name}))
@@ -289,7 +296,7 @@ def make_budget(**args):
budget = frappe.new_doc("Budget")
if budget_against == "Project":
- budget.project = "_Test Project"
+ budget.project = frappe.get_value("Project", {"project_name": "_Test Project"})
else:
budget.cost_center =cost_center or "_Test Cost Center - _TC"
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index 329d6e5aa75..ce76d0a39cc 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -27,30 +27,30 @@ class GLEntry(Document):
def validate(self):
self.flags.ignore_submit_comment = True
- self.check_mandatory()
self.validate_and_set_fiscal_year()
self.pl_must_have_cost_center()
- self.validate_cost_center()
if not self.flags.from_repost:
+ self.check_mandatory()
+ self.validate_cost_center()
self.check_pl_account()
self.validate_party()
self.validate_currency()
- def on_update_with_args(self, adv_adj, update_outstanding = 'Yes', from_repost=False):
- if not from_repost:
+ def on_update(self):
+ adv_adj = self.flags.adv_adj
+ if not self.flags.from_repost:
self.validate_account_details(adv_adj)
self.validate_dimensions_for_pl_and_bs()
self.validate_allowed_dimensions()
+ validate_balance_type(self.account, adv_adj)
+ validate_frozen_account(self.account, adv_adj)
- validate_frozen_account(self.account, adv_adj)
- validate_balance_type(self.account, adv_adj)
-
- # Update outstanding amt on against voucher
- if self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice', 'Fees'] \
- and self.against_voucher and update_outstanding == 'Yes' and not from_repost:
- update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type,
- self.against_voucher)
+ # Update outstanding amt on against voucher
+ if (self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice', 'Fees']
+ and self.against_voucher and self.flags.update_outstanding == 'Yes'):
+ update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type,
+ self.against_voucher)
def check_mandatory(self):
mandatory = ['account','voucher_type','voucher_no','company']
@@ -58,7 +58,7 @@ class GLEntry(Document):
if not self.get(k):
frappe.throw(_("{0} is required").format(_(self.meta.get_label(k))))
- account_type = frappe.db.get_value("Account", self.account, "account_type")
+ account_type = frappe.get_cached_value("Account", self.account, "account_type")
if not (self.party_type and self.party):
if account_type == "Receivable":
frappe.throw(_("{0} {1}: Customer is required against Receivable account {2}")
@@ -73,7 +73,7 @@ class GLEntry(Document):
.format(self.voucher_type, self.voucher_no, self.account))
def pl_must_have_cost_center(self):
- if frappe.db.get_value("Account", self.account, "report_type") == "Profit and Loss":
+ if frappe.get_cached_value("Account", self.account, "report_type") == "Profit and Loss":
if not self.cost_center and self.voucher_type != 'Period Closing Voucher':
frappe.throw(_("{0} {1}: Cost Center is required for 'Profit and Loss' account {2}. Please set up a default Cost Center for the Company.")
.format(self.voucher_type, self.voucher_no, self.account))
@@ -107,12 +107,12 @@ class GLEntry(Document):
if value['allow_or_restrict'] == 'Allow':
if self.get(dimension) and self.get(dimension) not in value['allowed_dimensions']:
- frappe.throw(_("Invalid value {0} for account {1}").format(
- frappe.bold(self.get(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
+ frappe.throw(_("Invalid value {0} for {1} against account {2}").format(
+ frappe.bold(self.get(dimension)), frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
else:
if self.get(dimension) and self.get(dimension) in value['allowed_dimensions']:
- frappe.throw(_("Invalid value {0} for account {1}").format(
- frappe.bold(self.get(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
+ frappe.throw(_("Invalid value {0} for {1} against account {2}").format(
+ frappe.bold(self.get(dimension)), frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account)), InvalidAccountDimensionError)
def check_pl_account(self):
if self.is_opening=='Yes' and \
@@ -140,26 +140,18 @@ class GLEntry(Document):
.format(self.voucher_type, self.voucher_no, self.account, self.company))
def validate_cost_center(self):
- if not hasattr(self, "cost_center_company"):
- self.cost_center_company = {}
+ if not self.cost_center: return
- def _get_cost_center_company():
- if not self.cost_center_company.get(self.cost_center):
- self.cost_center_company[self.cost_center] = frappe.db.get_value(
- "Cost Center", self.cost_center, "company")
+ is_group, company = frappe.get_cached_value('Cost Center',
+ self.cost_center, ['is_group', 'company'])
- return self.cost_center_company[self.cost_center]
-
- def _check_is_group():
- return cint(frappe.get_cached_value('Cost Center', self.cost_center, 'is_group'))
-
- if self.cost_center and _get_cost_center_company() != self.company:
+ if company != self.company:
frappe.throw(_("{0} {1}: Cost Center {2} does not belong to Company {3}")
.format(self.voucher_type, self.voucher_no, self.cost_center, self.company))
- if self.cost_center and _check_is_group():
- frappe.throw(_("""{0} {1}: Cost Center {2} is a group cost center and group cost centers cannot be used in transactions""")
- .format(self.voucher_type, self.voucher_no, frappe.bold(self.cost_center)))
+ if (self.voucher_type != 'Period Closing Voucher' and is_group):
+ frappe.throw(_("""{0} {1}: Cost Center {2} is a group cost center and group cost centers cannot be used in transactions""").format(
+ self.voucher_type, self.voucher_no, frappe.bold(self.cost_center)))
def validate_party(self):
validate_party_frozen_disabled(self.party_type, self.party)
@@ -169,7 +161,7 @@ class GLEntry(Document):
account_currency = get_account_currency(self.account)
if not self.account_currency:
- self.account_currency = company_currency
+ self.account_currency = account_currency or company_currency
if account_currency != self.account_currency:
frappe.throw(_("{0} {1}: Accounting Entry for {2} can only be made in currency: {3}")
@@ -183,7 +175,6 @@ class GLEntry(Document):
if not self.fiscal_year:
self.fiscal_year = get_fiscal_year(self.posting_date, company=self.company)[0]
-
def validate_balance_type(account, adv_adj=False):
if not adv_adj and account:
balance_must_be = frappe.db.get_value("Account", account, "balance_must_be")
@@ -249,7 +240,7 @@ def update_outstanding_amt(account, party_type, party, against_voucher_type, aga
def validate_frozen_account(account, adv_adj=None):
- frozen_account = frappe.db.get_value("Account", account, "freeze_account")
+ frozen_account = frappe.get_cached_value("Account", account, "freeze_account")
if frozen_account == 'Yes' and not adv_adj:
frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,
'frozen_accounts_modifier')
diff --git a/erpnext/accounts/doctype/item_tax_template/item_tax_template_dashboard.py b/erpnext/accounts/doctype/item_tax_template/item_tax_template_dashboard.py
index acc308e0e68..3d80a9785f0 100644
--- a/erpnext/accounts/doctype/item_tax_template/item_tax_template_dashboard.py
+++ b/erpnext/accounts/doctype/item_tax_template/item_tax_template_dashboard.py
@@ -20,7 +20,8 @@ def get_data():
'items': ['Purchase Invoice', 'Purchase Order', 'Purchase Receipt']
},
{
- 'items': ['Item']
+ 'label': _('Stock'),
+ 'items': ['Item Groups', 'Item']
}
]
}
diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
index b56f8e5fe2f..5f003e022a0 100644
--- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
@@ -160,7 +160,7 @@ class TestJournalEntry(unittest.TestCase):
self.assertFalse(gle)
def test_reverse_journal_entry(self):
- from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
+ from erpnext.accounts.doctype.journal_entry.journal_entry import make_reverse_journal_entry
jv = make_journal_entry("_Test Bank USD - _TC",
"Sales - _TC", 100, exchange_rate=50, save=False)
@@ -299,15 +299,20 @@ class TestJournalEntry(unittest.TestCase):
def test_jv_with_project(self):
from erpnext.projects.doctype.project.test_project import make_project
- project = make_project({
- 'project_name': 'Journal Entry Project',
- 'project_template_name': 'Test Project Template',
- 'start_date': '2020-01-01'
- })
+
+ if not frappe.db.exists("Project", {"project_name": "Journal Entry Project"}):
+ project = make_project({
+ 'project_name': 'Journal Entry Project',
+ 'project_template_name': 'Test Project Template',
+ 'start_date': '2020-01-01'
+ })
+ project_name = project.name
+ else:
+ project_name = frappe.get_value("Project", {"project_name": "_Test Project"})
jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, save=False)
for d in jv.accounts:
- d.project = project.project_name
+ d.project = project_name
jv.voucher_type = "Bank Entry"
jv.multi_currency = 0
jv.cheque_no = "112233"
@@ -317,10 +322,10 @@ class TestJournalEntry(unittest.TestCase):
expected_values = {
"_Test Cash - _TC": {
- "project": project.project_name
+ "project": project_name
},
"_Test Bank - _TC": {
- "project": project.project_name
+ "project": project_name
}
}
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 4318aea2bda..f5c488d0f97 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -396,6 +396,8 @@ frappe.ui.form.on('Payment Entry', {
set_account_currency_and_balance: function(frm, account, currency_field,
balance_field, callback_function) {
+
+ var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
if (frm.doc.posting_date && account) {
frappe.call({
method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_account_details",
@@ -422,6 +424,14 @@ frappe.ui.form.on('Payment Entry', {
if(!frm.doc.paid_amount && frm.doc.received_amount)
frm.events.received_amount(frm);
+
+ if (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency
+ && frm.doc.paid_amount != frm.doc.received_amount) {
+ if (company_currency != frm.doc.paid_from_account_currency &&
+ frm.doc.payment_type == "Pay") {
+ frm.doc.paid_amount = frm.doc.received_amount;
+ }
+ }
}
},
() => {
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index 1b97050eb13..53ac996290b 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -3,6 +3,7 @@
# For license information, please see license.txt
from __future__ import unicode_literals
+import json
import frappe
from frappe import _
from frappe.model.document import Document
@@ -82,18 +83,37 @@ class PaymentRequest(Document):
self.make_communication_entry()
elif self.payment_channel == "Phone":
- controller = get_payment_gateway_controller(self.payment_gateway)
- payment_record = dict(
- reference_doctype="Payment Request",
- reference_docname=self.name,
- payment_reference=self.reference_name,
- grand_total=self.grand_total,
- sender=self.email_to,
- currency=self.currency,
- payment_gateway=self.payment_gateway
- )
- controller.validate_transaction_currency(self.currency)
- controller.request_for_payment(**payment_record)
+ self.request_phone_payment()
+
+ def request_phone_payment(self):
+ controller = get_payment_gateway_controller(self.payment_gateway)
+ request_amount = self.get_request_amount()
+
+ payment_record = dict(
+ reference_doctype="Payment Request",
+ reference_docname=self.name,
+ payment_reference=self.reference_name,
+ request_amount=request_amount,
+ sender=self.email_to,
+ currency=self.currency,
+ payment_gateway=self.payment_gateway
+ )
+
+ controller.validate_transaction_currency(self.currency)
+ controller.request_for_payment(**payment_record)
+
+ def get_request_amount(self):
+ data_of_completed_requests = frappe.get_all("Integration Request", filters={
+ 'reference_doctype': self.doctype,
+ 'reference_docname': self.name,
+ 'status': 'Completed'
+ }, pluck="data")
+
+ if not data_of_completed_requests:
+ return self.grand_total
+
+ request_amounts = sum([json.loads(d).get('request_amount') for d in data_of_completed_requests])
+ return request_amounts
def on_cancel(self):
self.check_if_payment_entry_exists()
@@ -351,8 +371,8 @@ def make_payment_request(**args):
if args.order_type == "Shopping Cart" or args.mute_email:
pr.flags.mute_email = True
+ pr.insert(ignore_permissions=True)
if args.submit_doc:
- pr.insert(ignore_permissions=True)
pr.submit()
if args.order_type == "Shopping Cart":
@@ -412,8 +432,8 @@ def get_existing_payment_request_amount(ref_dt, ref_dn):
def get_gateway_details(args):
"""return gateway and payment account of default payment gateway"""
- if args.get("payment_gateway"):
- return get_payment_gateway_account(args.get("payment_gateway"))
+ if args.get("payment_gateway_account"):
+ return get_payment_gateway_account(args.get("payment_gateway_account"))
if args.order_type == "Shopping Cart":
payment_gateway_account = frappe.get_doc("Shopping Cart Settings").payment_gateway_account
diff --git a/erpnext/accounts/doctype/payment_request/test_payment_request.py b/erpnext/accounts/doctype/payment_request/test_payment_request.py
index 8a10e2cbd95..5eba62c0b31 100644
--- a/erpnext/accounts/doctype/payment_request/test_payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/test_payment_request.py
@@ -45,7 +45,8 @@ class TestPaymentRequest(unittest.TestCase):
def test_payment_request_linkings(self):
so_inr = make_sales_order(currency="INR")
- pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com")
+ pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com",
+ payment_gateway_account="_Test Gateway - INR")
self.assertEqual(pr.reference_doctype, "Sales Order")
self.assertEqual(pr.reference_name, so_inr.name)
@@ -54,7 +55,8 @@ class TestPaymentRequest(unittest.TestCase):
conversion_rate = get_exchange_rate("USD", "INR")
si_usd = create_sales_invoice(currency="USD", conversion_rate=conversion_rate)
- pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com")
+ pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com",
+ payment_gateway_account="_Test Gateway - USD")
self.assertEqual(pr.reference_doctype, "Sales Invoice")
self.assertEqual(pr.reference_name, si_usd.name)
@@ -68,7 +70,7 @@ class TestPaymentRequest(unittest.TestCase):
so_inr = make_sales_order(currency="INR")
pr = make_payment_request(dt="Sales Order", dn=so_inr.name, recipient_id="saurabh@erpnext.com",
- mute_email=1, submit_doc=1, return_doc=1)
+ mute_email=1, payment_gateway_account="_Test Gateway - INR", submit_doc=1, return_doc=1)
pe = pr.set_as_paid()
so_inr = frappe.get_doc("Sales Order", so_inr.name)
@@ -79,7 +81,7 @@ class TestPaymentRequest(unittest.TestCase):
currency="USD", conversion_rate=50)
pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com",
- mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1)
+ mute_email=1, payment_gateway_account="_Test Gateway - USD", submit_doc=1, return_doc=1)
pe = pr.set_as_paid()
@@ -106,7 +108,7 @@ class TestPaymentRequest(unittest.TestCase):
currency="USD", conversion_rate=50)
pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com",
- mute_email=1, payment_gateway="_Test Gateway - USD", submit_doc=1, return_doc=1)
+ mute_email=1, payment_gateway_account="_Test Gateway - USD", submit_doc=1, return_doc=1)
pe = pr.create_payment_entry()
pr.load_from_db()
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
index 57baac76819..9ea616f8e77 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
@@ -3,6 +3,7 @@
frappe.ui.form.on('POS Closing Entry', {
onload: function(frm) {
+ frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log'];
frm.set_query("pos_profile", function(doc) {
return {
filters: { 'user': doc.user }
@@ -20,7 +21,7 @@ frappe.ui.form.on('POS Closing Entry', {
return { filters: { 'status': 'Open', 'docstatus': 1 } };
});
- if (frm.doc.docstatus === 0) frm.set_value("period_end_date", frappe.datetime.now_datetime());
+ if (frm.doc.docstatus === 0 && !frm.doc.amended_from) frm.set_value("period_end_date", frappe.datetime.now_datetime());
if (frm.doc.docstatus === 1) set_html_data(frm);
},
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json
index 32bca3b8407..18d430f59f8 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.json
@@ -11,6 +11,7 @@
"column_break_3",
"posting_date",
"pos_opening_entry",
+ "status",
"section_break_5",
"company",
"column_break_7",
@@ -184,11 +185,27 @@
"label": "POS Opening Entry",
"options": "POS Opening Entry",
"reqd": 1
+ },
+ {
+ "allow_on_submit": 1,
+ "default": "Draft",
+ "fieldname": "status",
+ "fieldtype": "Select",
+ "hidden": 1,
+ "label": "Status",
+ "options": "Draft\nSubmitted\nQueued\nCancelled",
+ "print_hide": 1,
+ "read_only": 1
}
],
"is_submittable": 1,
- "links": [],
- "modified": "2020-05-29 15:03:22.226113",
+ "links": [
+ {
+ "link_doctype": "POS Invoice Merge Log",
+ "link_fieldname": "pos_closing_entry"
+ }
+ ],
+ "modified": "2021-01-12 12:21:05.388650",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Closing Entry",
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py
index 2b91c74ce6d..edf3d5a5748 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py
@@ -6,13 +6,12 @@ from __future__ import unicode_literals
import frappe
import json
from frappe import _
-from frappe.model.document import Document
-from frappe.utils import getdate, get_datetime, flt
-from collections import defaultdict
+from frappe.utils import get_datetime, flt
+from erpnext.controllers.status_updater import StatusUpdater
from erpnext.controllers.taxes_and_totals import get_itemised_tax_breakup_data
-from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices
+from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices, unconsolidate_pos_invoices
-class POSClosingEntry(Document):
+class POSClosingEntry(StatusUpdater):
def validate(self):
if frappe.db.get_value("POS Opening Entry", self.pos_opening_entry, "status") != "Open":
frappe.throw(_("Selected POS Opening Entry should be open."), title=_("Invalid Opening Entry"))
@@ -57,20 +56,29 @@ class POSClosingEntry(Document):
if not invalid_rows:
return
- error_list = [_("Row #{}: {}").format(row.get('idx'), row.get('msg')) for row in invalid_rows]
- frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True)
+ error_list = []
+ for row in invalid_rows:
+ for msg in row.get('msg'):
+ error_list.append(_("Row #{}: {}").format(row.get('idx'), msg))
- def on_submit(self):
- merge_pos_invoices(self.pos_transactions)
- opening_entry = frappe.get_doc("POS Opening Entry", self.pos_opening_entry)
- opening_entry.pos_closing_entry = self.name
- opening_entry.set_status()
- opening_entry.save()
+ frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True)
def get_payment_reconciliation_details(self):
currency = frappe.get_cached_value('Company', self.company, "default_currency")
return frappe.render_template("erpnext/accounts/doctype/pos_closing_entry/closing_voucher_details.html",
{"data": self, "currency": currency})
+
+ def on_submit(self):
+ consolidate_pos_invoices(closing_entry=self)
+
+ def on_cancel(self):
+ unconsolidate_pos_invoices(closing_entry=self)
+
+ def update_opening_entry(self, for_cancel=False):
+ opening_entry = frappe.get_doc("POS Opening Entry", self.pos_opening_entry)
+ opening_entry.pos_closing_entry = self.name if not for_cancel else None
+ opening_entry.set_status()
+ opening_entry.save()
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js
new file mode 100644
index 00000000000..20fd610899e
--- /dev/null
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry_list.js
@@ -0,0 +1,16 @@
+// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
+
+// render
+frappe.listview_settings['POS Closing Entry'] = {
+ get_indicator: function(doc) {
+ var status_color = {
+ "Draft": "red",
+ "Submitted": "blue",
+ "Queued": "orange",
+ "Cancelled": "red"
+
+ };
+ return [__(doc.status), status_color[doc.status], "status,=,"+doc.status];
+ }
+};
diff --git a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
index 8de54d5bdef..40db09ec3be 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
+++ b/erpnext/accounts/doctype/pos_closing_entry/test_pos_closing_entry.py
@@ -13,7 +13,6 @@ from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profi
class TestPOSClosingEntry(unittest.TestCase):
def test_pos_closing_entry(self):
test_user, pos_profile = init_user_and_profile()
-
opening_entry = create_opening_entry(pos_profile, test_user.name)
pos_inv1 = create_pos_invoice(rate=3500, do_not_submit=1)
@@ -45,6 +44,49 @@ class TestPOSClosingEntry(unittest.TestCase):
frappe.set_user("Administrator")
frappe.db.sql("delete from `tabPOS Profile`")
+ def test_cancelling_of_pos_closing_entry(self):
+ test_user, pos_profile = init_user_and_profile()
+ opening_entry = create_opening_entry(pos_profile, test_user.name)
+
+ pos_inv1 = create_pos_invoice(rate=3500, do_not_submit=1)
+ pos_inv1.append('payments', {
+ 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3500
+ })
+ pos_inv1.submit()
+
+ pos_inv2 = create_pos_invoice(rate=3200, do_not_submit=1)
+ pos_inv2.append('payments', {
+ 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 3200
+ })
+ pos_inv2.submit()
+
+ pcv_doc = make_closing_entry_from_opening(opening_entry)
+ payment = pcv_doc.payment_reconciliation[0]
+
+ self.assertEqual(payment.mode_of_payment, 'Cash')
+
+ for d in pcv_doc.payment_reconciliation:
+ if d.mode_of_payment == 'Cash':
+ d.closing_amount = 6700
+
+ pcv_doc.submit()
+
+ pos_inv1.load_from_db()
+ self.assertRaises(frappe.ValidationError, pos_inv1.cancel)
+
+ si_doc = frappe.get_doc("Sales Invoice", pos_inv1.consolidated_invoice)
+ self.assertRaises(frappe.ValidationError, si_doc.cancel)
+
+ pcv_doc.load_from_db()
+ pcv_doc.cancel()
+ si_doc.load_from_db()
+ pos_inv1.load_from_db()
+ self.assertEqual(si_doc.docstatus, 2)
+ self.assertEqual(pos_inv1.status, 'Paid')
+
+ frappe.set_user("Administrator")
+ frappe.db.sql("delete from `tabPOS Profile`")
+
def init_user_and_profile(**args):
user = 'test@example.com'
test_user = frappe.get_doc('User', user)
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js
index 86062d1e7cc..493bd448024 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js
@@ -2,6 +2,7 @@
// For license information, please see license.txt
{% include 'erpnext/selling/sales_common.js' %};
+frappe.provide("erpnext.accounts");
erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend({
setup(doc) {
@@ -9,12 +10,19 @@ erpnext.selling.POSInvoiceController = erpnext.selling.SellingController.extend(
this._super(doc);
},
+ company: function() {
+ erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype);
+ },
+
onload(doc) {
this._super();
+ this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log'];
if(doc.__islocal && doc.is_pos && frappe.get_route_str() !== 'point-of-sale') {
this.frm.script_manager.trigger("is_pos");
this.frm.refresh_fields();
}
+
+ erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
},
refresh(doc) {
@@ -187,18 +195,43 @@ frappe.ui.form.on('POS Invoice', {
},
request_for_payment: function (frm) {
+ if (!frm.doc.contact_mobile) {
+ frappe.throw(__('Please enter mobile number first.'));
+ }
+ frm.dirty();
frm.save().then(() => {
- frappe.dom.freeze();
- frappe.call({
- method: 'create_payment_request',
- doc: frm.doc,
- })
+ frappe.dom.freeze(__('Waiting for payment...'));
+ frappe
+ .call({
+ method: 'create_payment_request',
+ doc: frm.doc
+ })
.fail(() => {
frappe.dom.unfreeze();
- frappe.msgprint('Payment request failed');
+ frappe.msgprint(__('Payment request failed'));
})
- .then(() => {
- frappe.msgprint('Payment request sent successfully');
+ .then(({ message }) => {
+ const payment_request_name = message.name;
+ setTimeout(() => {
+ frappe.db.get_value('Payment Request', payment_request_name, ['status', 'grand_total']).then(({ message }) => {
+ if (message.status != 'Paid') {
+ frappe.dom.unfreeze();
+ frappe.msgprint({
+ message: __('Payment Request took too long to respond. Please try requesting for payment again.'),
+ title: __('Request Timeout')
+ });
+ } else if (frappe.dom.freeze_count != 0) {
+ frappe.dom.unfreeze();
+ cur_frm.reload_doc();
+ cur_pos.payment.events.submit_invoice();
+
+ frappe.show_alert({
+ message: __("Payment of {0} received successfully.", [format_currency(message.grand_total, frm.doc.currency, 0)]),
+ indicator: 'green'
+ });
+ }
+ });
+ }, 60000);
});
});
}
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
index a3fcd0c739a..0c1406c1ce8 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
@@ -6,10 +6,9 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
-from erpnext.controllers.selling_controller import SellingController
-from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate
from erpnext.accounts.utils import get_account_currency
from erpnext.accounts.party import get_party_account, get_due_date
+from frappe.utils import cint, flt, getdate, nowdate, get_link_to_form
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points
from erpnext.stock.doctype.serial_no.serial_no import get_pos_reserved_serial_nos, get_serial_nos
@@ -58,6 +57,22 @@ class POSInvoice(SalesInvoice):
self.apply_loyalty_points()
self.check_phone_payments()
self.set_status(update=True)
+
+ def before_cancel(self):
+ if self.consolidated_invoice and frappe.db.get_value('Sales Invoice', self.consolidated_invoice, 'docstatus') == 1:
+ pos_closing_entry = frappe.get_all(
+ "POS Invoice Reference",
+ ignore_permissions=True,
+ filters={ 'pos_invoice': self.name },
+ pluck="parent",
+ limit=1
+ )
+ frappe.throw(
+ _('You need to cancel POS Closing Entry {} to be able to cancel this document.').format(
+ get_link_to_form("POS Closing Entry", pos_closing_entry[0])
+ ),
+ title=_('Not Allowed')
+ )
def on_cancel(self):
# run on cancel method of selling controller
@@ -78,7 +93,7 @@ class POSInvoice(SalesInvoice):
mode_of_payment=pay.mode_of_payment, status="Paid"),
fieldname="grand_total")
- if pay.amount != paid_amt:
+ if paid_amt and pay.amount != paid_amt:
return frappe.throw(_("Payment related to {0} is not completed").format(pay.mode_of_payment))
def validate_stock_availablility(self):
@@ -266,6 +281,8 @@ class POSInvoice(SalesInvoice):
from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile
if not self.pos_profile:
pos_profile = get_pos_profile(self.company) or {}
+ if not pos_profile:
+ frappe.throw(_("No POS Profile found. Please create a New POS Profile first"))
self.pos_profile = pos_profile.get('name')
profile = {}
@@ -294,14 +311,21 @@ class POSInvoice(SalesInvoice):
self.set(fieldname, profile.get(fieldname))
if self.customer:
- customer_price_list, customer_group = frappe.db.get_value("Customer", self.customer, ['default_price_list', 'customer_group'])
+ customer_price_list, customer_group, customer_currency = frappe.db.get_value(
+ "Customer", self.customer, ['default_price_list', 'customer_group', 'default_currency']
+ )
customer_group_price_list = frappe.db.get_value("Customer Group", customer_group, 'default_price_list')
selling_price_list = customer_price_list or customer_group_price_list or profile.get('selling_price_list')
+ if customer_currency != profile.get('currency'):
+ self.set('currency', customer_currency)
+
else:
selling_price_list = profile.get('selling_price_list')
if selling_price_list:
self.set('selling_price_list', selling_price_list)
+ if customer_currency != profile.get('currency'):
+ self.set('currency', customer_currency)
# set pos values in items
for item in self.get("items"):
@@ -361,22 +385,48 @@ class POSInvoice(SalesInvoice):
if not self.contact_mobile:
frappe.throw(_("Please enter the phone number first"))
- payment_gateway = frappe.db.get_value("Payment Gateway Account", {
- "payment_account": pay.account,
- })
- record = {
- "payment_gateway": payment_gateway,
- "dt": "POS Invoice",
- "dn": self.name,
- "payment_request_type": "Inward",
- "party_type": "Customer",
- "party": self.customer,
- "mode_of_payment": pay.mode_of_payment,
- "recipient_id": self.contact_mobile,
- "submit_doc": True
- }
+ pay_req = self.get_existing_payment_request(pay)
+ if not pay_req:
+ pay_req = self.get_new_payment_request(pay)
+ pay_req.submit()
+ else:
+ pay_req.request_phone_payment()
- return make_payment_request(**record)
+ return pay_req
+
+ def get_new_payment_request(self, mop):
+ payment_gateway_account = frappe.db.get_value("Payment Gateway Account", {
+ "payment_account": mop.account,
+ }, ["name"])
+
+ args = {
+ "dt": "POS Invoice",
+ "dn": self.name,
+ "recipient_id": self.contact_mobile,
+ "mode_of_payment": mop.mode_of_payment,
+ "payment_gateway_account": payment_gateway_account,
+ "payment_request_type": "Inward",
+ "party_type": "Customer",
+ "party": self.customer,
+ "return_doc": True
+ }
+ return make_payment_request(**args)
+
+ def get_existing_payment_request(self, pay):
+ payment_gateway_account = frappe.db.get_value("Payment Gateway Account", {
+ "payment_account": pay.account,
+ }, ["name"])
+
+ args = {
+ 'doctype': 'Payment Request',
+ 'reference_doctype': 'POS Invoice',
+ 'reference_name': self.name,
+ 'payment_gateway_account': payment_gateway_account,
+ 'email_to': self.contact_mobile
+ }
+ pr = frappe.db.exists(args)
+ if pr:
+ return frappe.get_doc('Payment Request', pr[0][0])
def add_return_modes(doc, pos_profile):
def append_payment(payment_mode):
diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
index c179360b017..57a23af8af0 100644
--- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
@@ -290,7 +290,7 @@ class TestPOSInvoice(unittest.TestCase):
def test_merging_into_sales_invoice_with_discount(self):
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
- from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices
+ from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices
frappe.db.sql("delete from `tabPOS Invoice`")
test_user, pos_profile = init_user_and_profile()
@@ -306,7 +306,7 @@ class TestPOSInvoice(unittest.TestCase):
})
pos_inv2.submit()
- merge_pos_invoices()
+ consolidate_pos_invoices()
pos_inv.load_from_db()
rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total")
@@ -315,7 +315,7 @@ class TestPOSInvoice(unittest.TestCase):
def test_merging_into_sales_invoice_with_discount_and_inclusive_tax(self):
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
- from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices
+ from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices
frappe.db.sql("delete from `tabPOS Invoice`")
test_user, pos_profile = init_user_and_profile()
@@ -348,7 +348,7 @@ class TestPOSInvoice(unittest.TestCase):
})
pos_inv2.submit()
- merge_pos_invoices()
+ consolidate_pos_invoices()
pos_inv.load_from_db()
rounded_total = frappe.db.get_value("Sales Invoice", pos_inv.consolidated_invoice, "rounded_total")
@@ -357,7 +357,7 @@ class TestPOSInvoice(unittest.TestCase):
def test_merging_with_validate_selling_price(self):
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
- from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices
+ from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices
if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
frappe.db.set_value("Selling Settings", "Selling Settings", "validate_selling_price", 1)
@@ -393,7 +393,7 @@ class TestPOSInvoice(unittest.TestCase):
})
pos_inv2.submit()
- merge_pos_invoices()
+ consolidate_pos_invoices()
pos_inv2.load_from_db()
rounded_total = frappe.db.get_value("Sales Invoice", pos_inv2.consolidated_invoice, "rounded_total")
diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json
index 8f97639bbc9..da2984f05af 100644
--- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json
+++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.json
@@ -7,6 +7,8 @@
"field_order": [
"posting_date",
"customer",
+ "column_break_3",
+ "pos_closing_entry",
"section_break_3",
"pos_invoices",
"references_section",
@@ -76,11 +78,22 @@
"label": "Consolidated Credit Note",
"options": "Sales Invoice",
"read_only": 1
+ },
+ {
+ "fieldname": "column_break_3",
+ "fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "pos_closing_entry",
+ "fieldtype": "Link",
+ "label": "POS Closing Entry",
+ "options": "POS Closing Entry"
}
],
+ "index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2020-05-29 15:08:41.317100",
+ "modified": "2020-12-01 11:53:57.267579",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Invoice Merge Log",
diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
index add27e9dffb..58409cd3c6d 100644
--- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
+++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py
@@ -5,10 +5,13 @@
from __future__ import unicode_literals
import frappe
from frappe import _
-from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate
-from frappe.model.document import Document
-from frappe.model.mapper import map_doc
from frappe.model import default_fields
+from frappe.model.document import Document
+from frappe.utils import flt, getdate, nowdate
+from frappe.utils.background_jobs import enqueue
+from frappe.model.mapper import map_doc, map_child_doc
+from frappe.utils.scheduler import is_scheduler_inactive
+from frappe.core.page.background_jobs.background_jobs import get_info
from six import iteritems
@@ -61,7 +64,13 @@ class POSInvoiceMergeLog(Document):
self.save() # save consolidated_sales_invoice & consolidated_credit_note ref in merge log
- self.update_pos_invoices(sales_invoice, credit_note)
+ self.update_pos_invoices(pos_invoice_docs, sales_invoice, credit_note)
+
+ def on_cancel(self):
+ pos_invoice_docs = [frappe.get_doc("POS Invoice", d.pos_invoice) for d in self.pos_invoices]
+
+ self.update_pos_invoices(pos_invoice_docs)
+ self.cancel_linked_invoices()
def process_merging_into_sales_invoice(self, data):
sales_invoice = self.get_new_sales_invoice()
@@ -83,7 +92,7 @@ class POSInvoiceMergeLog(Document):
credit_note.is_consolidated = 1
# TODO: return could be against multiple sales invoice which could also have been consolidated?
- credit_note.return_against = self.consolidated_invoice
+ # credit_note.return_against = self.consolidated_invoice
credit_note.save()
credit_note.submit()
self.consolidated_credit_note = credit_note.name
@@ -111,7 +120,9 @@ class POSInvoiceMergeLog(Document):
i.qty = i.qty + item.qty
if not found:
item.rate = item.net_rate
- items.append(item)
+ item.price_list_rate = 0
+ si_item = map_child_doc(item, invoice, {"doctype": "Sales Invoice Item"})
+ items.append(si_item)
for tax in doc.get('taxes'):
found = False
@@ -147,6 +158,8 @@ class POSInvoiceMergeLog(Document):
invoice.set('taxes', taxes)
invoice.additional_discount_percentage = 0
invoice.discount_amount = 0.0
+ invoice.taxes_and_charges = None
+ invoice.ignore_pricing_rule = 1
return invoice
@@ -159,17 +172,21 @@ class POSInvoiceMergeLog(Document):
return sales_invoice
- def update_pos_invoices(self, sales_invoice, credit_note):
- for d in self.pos_invoices:
- doc = frappe.get_doc('POS Invoice', d.pos_invoice)
- if not doc.is_return:
- doc.update({'consolidated_invoice': sales_invoice})
- else:
- doc.update({'consolidated_invoice': credit_note})
+ def update_pos_invoices(self, invoice_docs, sales_invoice='', credit_note=''):
+ for doc in invoice_docs:
+ doc.load_from_db()
+ doc.update({ 'consolidated_invoice': None if self.docstatus==2 else (credit_note if doc.is_return else sales_invoice) })
doc.set_status(update=True)
doc.save()
-def get_all_invoices():
+ def cancel_linked_invoices(self):
+ for si_name in [self.consolidated_invoice, self.consolidated_credit_note]:
+ if not si_name: continue
+ si = frappe.get_doc('Sales Invoice', si_name)
+ si.flags.ignore_validate = True
+ si.cancel()
+
+def get_all_unconsolidated_invoices():
filters = {
'consolidated_invoice': [ 'in', [ '', None ]],
'status': ['not in', ['Consolidated']],
@@ -180,7 +197,7 @@ def get_all_invoices():
return pos_invoices
-def get_invoices_customer_map(pos_invoices):
+def get_invoice_customer_map(pos_invoices):
# pos_invoice_customer_map = { 'Customer 1': [{}, {}, {}], 'Custoemr 2' : [{}] }
pos_invoice_customer_map = {}
for invoice in pos_invoices:
@@ -190,20 +207,82 @@ def get_invoices_customer_map(pos_invoices):
return pos_invoice_customer_map
-def merge_pos_invoices(pos_invoices=[]):
- if not pos_invoices:
- pos_invoices = get_all_invoices()
-
- pos_invoice_map = get_invoices_customer_map(pos_invoices)
- create_merge_logs(pos_invoice_map)
+def consolidate_pos_invoices(pos_invoices=[], closing_entry={}):
+ invoices = pos_invoices or closing_entry.get('pos_transactions') or get_all_unconsolidated_invoices()
+ invoice_by_customer = get_invoice_customer_map(invoices)
-def create_merge_logs(pos_invoice_customer_map):
- for customer, invoices in iteritems(pos_invoice_customer_map):
+ if len(invoices) >= 5 and closing_entry:
+ enqueue_job(create_merge_logs, invoice_by_customer, closing_entry)
+ closing_entry.set_status(update=True, status='Queued')
+ else:
+ create_merge_logs(invoice_by_customer, closing_entry)
+
+def unconsolidate_pos_invoices(closing_entry):
+ merge_logs = frappe.get_all(
+ 'POS Invoice Merge Log',
+ filters={ 'pos_closing_entry': closing_entry.name },
+ pluck='name'
+ )
+
+ if len(merge_logs) >= 5:
+ enqueue_job(cancel_merge_logs, merge_logs, closing_entry)
+ closing_entry.set_status(update=True, status='Queued')
+ else:
+ cancel_merge_logs(merge_logs, closing_entry)
+
+def create_merge_logs(invoice_by_customer, closing_entry={}):
+ for customer, invoices in iteritems(invoice_by_customer):
merge_log = frappe.new_doc('POS Invoice Merge Log')
merge_log.posting_date = getdate(nowdate())
merge_log.customer = customer
+ merge_log.pos_closing_entry = closing_entry.get('name', None)
merge_log.set('pos_invoices', invoices)
merge_log.save(ignore_permissions=True)
merge_log.submit()
+
+ if closing_entry:
+ closing_entry.set_status(update=True, status='Submitted')
+ closing_entry.update_opening_entry()
+def cancel_merge_logs(merge_logs, closing_entry={}):
+ for log in merge_logs:
+ merge_log = frappe.get_doc('POS Invoice Merge Log', log)
+ merge_log.flags.ignore_permissions = True
+ merge_log.cancel()
+
+ if closing_entry:
+ closing_entry.set_status(update=True, status='Cancelled')
+ closing_entry.update_opening_entry(for_cancel=True)
+
+def enqueue_job(job, invoice_by_customer, closing_entry):
+ check_scheduler_status()
+
+ job_name = closing_entry.get("name")
+ if not job_already_enqueued(job_name):
+ enqueue(
+ job,
+ queue="long",
+ timeout=10000,
+ event="processing_merge_logs",
+ job_name=job_name,
+ closing_entry=closing_entry,
+ invoice_by_customer=invoice_by_customer,
+ now=frappe.conf.developer_mode or frappe.flags.in_test
+ )
+
+ if job == create_merge_logs:
+ msg = _('POS Invoices will be consolidated in a background process')
+ else:
+ msg = _('POS Invoices will be unconsolidated in a background process')
+
+ frappe.msgprint(msg, alert=1)
+
+def check_scheduler_status():
+ if is_scheduler_inactive() and not frappe.flags.in_test:
+ frappe.throw(_("Scheduler is inactive. Cannot enqueue job."), title=_("Scheduler Inactive"))
+
+def job_already_enqueued(job_name):
+ enqueued_jobs = [d.get("job_name") for d in get_info()]
+ if job_name in enqueued_jobs:
+ return True
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py
index 0f34272eb49..db046c98008 100644
--- a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py
+++ b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py
@@ -7,7 +7,7 @@ import frappe
import unittest
from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_invoice
from erpnext.accounts.doctype.pos_invoice.pos_invoice import make_sales_return
-from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices
+from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import consolidate_pos_invoices
from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
class TestPOSInvoiceMergeLog(unittest.TestCase):
@@ -34,7 +34,7 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
})
pos_inv3.submit()
- merge_pos_invoices()
+ consolidate_pos_invoices()
pos_inv.load_from_db()
self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice))
@@ -79,7 +79,7 @@ class TestPOSInvoiceMergeLog(unittest.TestCase):
pos_inv_cn.paid_amount = -300
pos_inv_cn.submit()
- merge_pos_invoices()
+ consolidate_pos_invoices()
pos_inv.load_from_db()
self.assertTrue(frappe.db.exists("Sales Invoice", pos_inv.consolidated_invoice))
diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py
index acac1c4072e..cb5b3a58fe9 100644
--- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py
+++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry.py
@@ -6,7 +6,6 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import cint, get_link_to_form
-from frappe.model.document import Document
from erpnext.controllers.status_updater import StatusUpdater
class POSOpeningEntry(StatusUpdater):
diff --git a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js
index 6c26dedc54b..1ad3c919b71 100644
--- a/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js
+++ b/erpnext/accounts/doctype/pos_opening_entry/pos_opening_entry_list.js
@@ -5,7 +5,7 @@
frappe.listview_settings['POS Opening Entry'] = {
get_indicator: function(doc) {
var status_color = {
- "Draft": "grey",
+ "Draft": "red",
"Open": "orange",
"Closed": "green",
"Cancelled": "red"
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index 750ed82d154..4b69f6e2efe 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -12,8 +12,6 @@
"company",
"country",
"column_break_9",
- "update_stock",
- "ignore_pricing_rule",
"warehouse",
"campaign",
"company_address",
@@ -25,8 +23,14 @@
"hide_images",
"hide_unavailable_items",
"auto_add_item_to_cart",
- "item_groups",
"column_break_16",
+ "update_stock",
+ "ignore_pricing_rule",
+ "allow_rate_change",
+ "allow_discount_change",
+ "section_break_23",
+ "item_groups",
+ "column_break_25",
"customer_groups",
"section_break_16",
"print_format",
@@ -309,6 +313,7 @@
"default": "1",
"fieldname": "update_stock",
"fieldtype": "Check",
+ "hidden": 1,
"label": "Update Stock",
"read_only": 1
},
@@ -329,13 +334,34 @@
"fieldname": "auto_add_item_to_cart",
"fieldtype": "Check",
"label": "Automatically Add Filtered Item To Cart"
+ },
+ {
+ "default": "0",
+ "fieldname": "allow_rate_change",
+ "fieldtype": "Check",
+ "label": "Allow User to Edit Rate"
+ },
+ {
+ "default": "0",
+ "fieldname": "allow_discount_change",
+ "fieldtype": "Check",
+ "label": "Allow User to Edit Discount"
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "section_break_23",
+ "fieldtype": "Section Break"
+ },
+ {
+ "fieldname": "column_break_25",
+ "fieldtype": "Column Break"
}
],
"icon": "icon-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2020-12-20 13:59:28.877572",
+ "modified": "2021-01-06 14:42:41.713864",
"modified_by": "Administrator",
"module": "Accounts",
"name": "POS Profile",
diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
index af8d21d9ce4..f28cee7c5af 100644
--- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
@@ -56,6 +56,7 @@ class TestPricingRule(unittest.TestCase):
self.assertEqual(details.get("discount_percentage"), 10)
prule = frappe.get_doc(test_record.copy())
+ prule.priority = 1
prule.applicable_for = "Customer"
prule.title = "_Test Pricing Rule for Customer"
self.assertRaises(MandatoryError, prule.insert)
@@ -261,6 +262,7 @@ class TestPricingRule(unittest.TestCase):
"rate_or_discount": "Discount Percentage",
"rate": 0,
"discount_percentage": 17.5,
+ "priority": 1,
"company": "_Test Company"
}).insert()
@@ -557,6 +559,7 @@ def make_pricing_rule(**args):
"rate": args.rate or 0.0,
"margin_rate_or_amount": args.margin_rate_or_amount or 0.0,
"condition": args.condition or '',
+ "priority": 1,
"apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0
})
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index fb1fbe484ed..d1633359963 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -41,10 +41,11 @@ def get_pricing_rules(args, doc=None):
if not pricing_rules: return []
if apply_multiple_pricing_rules(pricing_rules):
- pricing_rules = sorted_by_priority(pricing_rules)
+ pricing_rules = sorted_by_priority(pricing_rules, args, doc)
for pricing_rule in pricing_rules:
- pricing_rule = filter_pricing_rules(args, pricing_rule, doc)
- if pricing_rule:
+ if isinstance(pricing_rule, list):
+ rules.extend(pricing_rule)
+ else:
rules.append(pricing_rule)
else:
pricing_rule = filter_pricing_rules(args, pricing_rules, doc)
@@ -53,17 +54,22 @@ def get_pricing_rules(args, doc=None):
return rules
-def sorted_by_priority(pricing_rules):
+def sorted_by_priority(pricing_rules, args, doc=None):
# If more than one pricing rules, then sort by priority
pricing_rules_list = []
pricing_rule_dict = {}
- for pricing_rule in pricing_rules:
- if not pricing_rule.get("priority"): continue
- pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
+ for pricing_rule in pricing_rules:
+ pricing_rule = filter_pricing_rules(args, pricing_rule, doc)
+ if pricing_rule:
+ if not pricing_rule.get('priority'):
+ pricing_rule['priority'] = 1
+
+ if pricing_rule.get('apply_multiple_pricing_rules'):
+ pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
for key in sorted(pricing_rule_dict):
- pricing_rules_list.append(pricing_rule_dict.get(key))
+ pricing_rules_list.extend(pricing_rule_dict.get(key))
return pricing_rules_list or pricing_rules
@@ -144,9 +150,7 @@ def apply_multiple_pricing_rules(pricing_rules):
if not apply_multiple_rule: return False
- if (apply_multiple_rule
- and len(apply_multiple_rule) == len(pricing_rules)):
- return True
+ return True
def _get_tree_conditions(args, parenttype, table, allow_blank=True):
field = frappe.scrub(parenttype)
@@ -264,18 +268,6 @@ def filter_pricing_rules(args, pricing_rules, doc=None):
if max_priority:
pricing_rules = list(filter(lambda x: cint(x.priority)==max_priority, pricing_rules))
- # apply internal priority
- all_fields = ["item_code", "item_group", "brand", "customer", "customer_group", "territory",
- "supplier", "supplier_group", "campaign", "sales_partner", "variant_of"]
-
- if len(pricing_rules) > 1:
- for field_set in [["item_code", "variant_of", "item_group", "brand"],
- ["customer", "customer_group", "territory"], ["supplier", "supplier_group"]]:
- remaining_fields = list(set(all_fields) - set(field_set))
- if if_all_rules_same(pricing_rules, remaining_fields):
- pricing_rules = apply_internal_priority(pricing_rules, field_set, args)
- break
-
if pricing_rules and not isinstance(pricing_rules, list):
pricing_rules = list(pricing_rules)
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index dd7b2395c33..06aa20bfc5a 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -508,7 +508,7 @@ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
frappe.ui.form.on("Purchase Invoice", {
setup: function(frm) {
frm.custom_make_buttons = {
- 'Purchase Invoice': 'Debit Note',
+ 'Purchase Invoice': 'Return / Debit Note',
'Payment Entry': 'Payment'
}
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index d1eb5ed4037..d60381a18c4 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -611,7 +611,8 @@ class PurchaseInvoice(BuyingController):
"against": item.expense_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
- "credit": flt(amount),
+ "credit": flt(amount["base_amount"]),
+ "credit_in_account_currency": flt(amount["amount"]),
"project": item.project or self.project
}, item=item))
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index c0506ba97f6..ded293b88d5 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -426,32 +426,37 @@ class TestPurchaseInvoice(unittest.TestCase):
)
def test_total_purchase_cost_for_project(self):
- make_project({'project_name':'_Test Project'})
+ if not frappe.db.exists("Project", {"project_name": "_Test Project for Purchase"}):
+ project = make_project({'project_name':'_Test Project for Purchase'})
+ else:
+ project = frappe.get_doc("Project", {"project_name": "_Test Project for Purchase"})
existing_purchase_cost = frappe.db.sql("""select sum(base_net_amount)
- from `tabPurchase Invoice Item` where project = '_Test Project' and docstatus=1""")
+ from `tabPurchase Invoice Item`
+ where project = '{0}'
+ and docstatus=1""".format(project.name))
existing_purchase_cost = existing_purchase_cost and existing_purchase_cost[0][0] or 0
- pi = make_purchase_invoice(currency="USD", conversion_rate=60, project="_Test Project")
- self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
+ pi = make_purchase_invoice(currency="USD", conversion_rate=60, project=project.name)
+ self.assertEqual(frappe.db.get_value("Project", project.name, "total_purchase_cost"),
existing_purchase_cost + 15000)
- pi1 = make_purchase_invoice(qty=10, project="_Test Project")
- self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
+ pi1 = make_purchase_invoice(qty=10, project=project.name)
+ self.assertEqual(frappe.db.get_value("Project", project.name, "total_purchase_cost"),
existing_purchase_cost + 15500)
pi1.cancel()
- self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
+ self.assertEqual(frappe.db.get_value("Project", project.name, "total_purchase_cost"),
existing_purchase_cost + 15000)
pi.cancel()
- self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), existing_purchase_cost)
+ self.assertEqual(frappe.db.get_value("Project", project.name, "total_purchase_cost"), existing_purchase_cost)
def test_return_purchase_invoice_with_perpetual_inventory(self):
pi = make_purchase_invoice(company = "_Test Company with perpetual inventory", warehouse= "Stores - TCP1",
cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1")
- return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2,
+ return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2,
company = "_Test Company with perpetual inventory", warehouse= "Stores - TCP1",
cost_center = "Main - TCP1", expense_account ="_Test Account Cost for Goods Sold - TCP1")
@@ -860,17 +865,17 @@ class TestPurchaseInvoice(unittest.TestCase):
})
pi = make_purchase_invoice(credit_to="Creditors - _TC" ,do_not_save=1)
- pi.items[0].project = item_project.project_name
- pi.project = project.project_name
+ pi.items[0].project = item_project.name
+ pi.project = project.name
pi.submit()
expected_values = {
"Creditors - _TC": {
- "project": project.project_name
+ "project": project.name
},
"_Test Account Cost for Goods Sold - _TC": {
- "project": item_project.project_name
+ "project": item_project.name
}
}
@@ -1026,7 +1031,7 @@ def make_purchase_invoice_against_cost_center(**args):
pi.is_return = args.is_return
pi.credit_to = args.return_against or "Creditors - _TC"
pi.is_subcontracted = args.is_subcontracted or "No"
- if args.supplier_warehouse:
+ if args.supplier_warehouse:
pi.supplier_warehouse = "_Test Warehouse 1 - _TC"
pi.append("items", {
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 1f7853dbf71..07e75acb418 100644
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -40,6 +40,7 @@
"base_rate",
"base_amount",
"pricing_rules",
+ "stock_uom_rate",
"is_free_item",
"section_break_22",
"net_rate",
@@ -783,6 +784,14 @@
"print_hide": 1,
"read_only": 1
},
+ {
+ "depends_on": "eval: doc.uom != doc.stock_uom",
+ "fieldname": "stock_uom_rate",
+ "fieldtype": "Currency",
+ "label": "Rate of Stock UOM",
+ "options": "currency",
+ "read_only": 1
+ },
{
"fieldname": "sales_invoice_item",
"fieldtype": "Data",
@@ -795,7 +804,7 @@
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2020-12-26 17:20:36.415791",
+ "modified": "2021-01-30 21:43:21.488258",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 962839f3d39..8341456d9e7 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -20,6 +20,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
var me = this;
this._super();
+ this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice'];
if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
// show debit_to in print format
this.frm.set_df_property("debit_to", "print_hide", 0);
@@ -574,15 +575,6 @@ frappe.ui.form.on('Sales Invoice', {
};
});
- frm.set_query("cost_center", function() {
- return {
- filters: {
- company: frm.doc.company,
- is_group: 0
- }
- };
- });
-
frm.set_query("unrealized_profit_loss_account", function() {
return {
filters: {
@@ -595,7 +587,7 @@ frappe.ui.form.on('Sales Invoice', {
frm.custom_make_buttons = {
'Delivery Note': 'Delivery',
- 'Sales Invoice': 'Sales Return',
+ 'Sales Invoice': 'Return / Credit Note',
'Payment Request': 'Payment Request',
'Payment Entry': 'Payment'
},
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 447cee42a75..018bc7e6419 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -1987,8 +1987,15 @@
"icon": "fa fa-file-text",
"idx": 181,
"is_submittable": 1,
- "links": [],
- "modified": "2020-12-25 22:57:32.555067",
+ "links": [
+ {
+ "custom": 1,
+ "group": "Reference",
+ "link_doctype": "POS Invoice",
+ "link_fieldname": "consolidated_invoice"
+ }
+ ],
+ "modified": "2021-01-12 12:16:15.192520",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index bb395fc092c..8efc4b0af72 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe, erpnext
import frappe.defaults
-from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate, get_link_to_form
+from frappe.utils import cint, flt, getdate, add_days, cstr, nowdate, get_link_to_form, formatdate
from frappe import _, msgprint, throw
from erpnext.accounts.party import get_party_account, get_due_date, get_party_details
from frappe.model.mapper import get_mapped_doc
@@ -212,6 +212,9 @@ class SalesInvoice(SellingController):
# this sequence because outstanding may get -ve
self.make_gl_entries()
+ if self.update_stock == 1:
+ self.repost_future_sle_and_gle()
+
if self.update_stock == 1:
self.repost_future_sle_and_gle()
@@ -263,7 +266,25 @@ class SalesInvoice(SellingController):
if len(self.payments) == 0 and self.is_pos:
frappe.throw(_("At least one mode of payment is required for POS invoice."))
+ def check_if_consolidated_invoice(self):
+ # since POS Invoice extends Sales Invoice, we explicitly check if doctype is Sales Invoice
+ if self.doctype == "Sales Invoice" and self.is_consolidated:
+ invoice_or_credit_note = "consolidated_credit_note" if self.is_return else "consolidated_invoice"
+ pos_closing_entry = frappe.get_all(
+ "POS Invoice Merge Log",
+ filters={ invoice_or_credit_note: self.name },
+ pluck="pos_closing_entry"
+ )
+ if pos_closing_entry:
+ msg = _("To cancel a {} you need to cancel the POS Closing Entry {}. ").format(
+ frappe.bold("Consolidated Sales Invoice"),
+ get_link_to_form("POS Closing Entry", pos_closing_entry[0])
+ )
+ frappe.throw(msg, title=_("Not Allowed"))
+
def before_cancel(self):
+ self.check_if_consolidated_invoice()
+
super(SalesInvoice, self).before_cancel()
self.update_time_sheet(None)
@@ -465,7 +486,9 @@ class SalesInvoice(SellingController):
if not for_validate and not self.customer:
self.customer = pos.customer
- self.ignore_pricing_rule = pos.ignore_pricing_rule
+ if not for_validate:
+ self.ignore_pricing_rule = pos.ignore_pricing_rule
+
if pos.get('account_for_change_amount'):
self.account_for_change_amount = pos.get('account_for_change_amount')
@@ -1891,6 +1914,7 @@ def get_mode_of_payment_info(mode_of_payment, company):
where mpa.parent = mp.name and mpa.company = %s and mp.enabled = 1 and mp.name = %s""",
(company, mode_of_payment), as_dict=1)
+@frappe.whitelist()
def create_dunning(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
from erpnext.accounts.doctype.dunning.dunning import get_dunning_letter_text, calculate_interest_and_amount
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 99fbb113b16..346bff4c4fa 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -1574,17 +1574,17 @@ class TestSalesInvoice(unittest.TestCase):
})
sales_invoice = create_sales_invoice(do_not_save=1)
- sales_invoice.items[0].project = item_project.project_name
- sales_invoice.project = project.project_name
+ sales_invoice.items[0].project = item_project.name
+ sales_invoice.project = project.name
sales_invoice.submit()
expected_values = {
"Debtors - _TC": {
- "project": project.project_name
+ "project": project.name
},
"Sales - _TC": {
- "project": item_project.project_name
+ "project": item_project.name
}
}
@@ -1885,23 +1885,6 @@ class TestSalesInvoice(unittest.TestCase):
def test_einvoice_json(self):
from erpnext.regional.india.e_invoice.utils import make_einvoice
- customer_gstin = '27AACCM7806M1Z3'
- customer_gstin_dtls = {
- 'LegalName': '_Test Customer', 'TradeName': '_Test Customer', 'AddrLoc': '_Test City',
- 'StateCode': '27', 'AddrPncd': '410038', 'AddrBno': '_Test Bldg',
- 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street'
- }
- company_gstin = '27AAECE4835E1ZR'
- company_gstin_dtls = {
- 'LegalName': '_Test Company', 'TradeName': '_Test Company', 'AddrLoc': '_Test City',
- 'StateCode': '27', 'AddrPncd': '401108', 'AddrBno': '_Test Bldg',
- 'AddrBnm': '100', 'AddrFlno': '200', 'AddrSt': '_Test Street'
- }
- # set cache gstin details to avoid fetching details which will require connection to GSP servers
- frappe.local.gstin_cache = {}
- frappe.local.gstin_cache[customer_gstin] = customer_gstin_dtls
- frappe.local.gstin_cache[company_gstin] = company_gstin_dtls
-
si = make_sales_invoice_for_ewaybill()
si.naming_series = 'INV-2020-.#####'
si.items = []
@@ -1909,8 +1892,8 @@ class TestSalesInvoice(unittest.TestCase):
"item_code": "_Test Item",
"uom": "Nos",
"warehouse": "_Test Warehouse - _TC",
- "qty": 2,
- "rate": 100,
+ "qty": 2000,
+ "rate": 12,
"income_account": "Sales - _TC",
"expense_account": "Cost of Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
@@ -1919,31 +1902,52 @@ class TestSalesInvoice(unittest.TestCase):
"item_code": "_Test Item 2",
"uom": "Nos",
"warehouse": "_Test Warehouse - _TC",
- "qty": 4,
- "rate": 150,
+ "qty": 420,
+ "rate": 15,
"income_account": "Sales - _TC",
"expense_account": "Cost of Goods Sold - _TC",
"cost_center": "_Test Cost Center - _TC",
})
+ si.discount_amount = 100
si.save()
einvoice = make_einvoice(si)
- total_item_ass_value = sum([d['AssAmt'] for d in einvoice['ItemList']])
- total_item_cgst_value = sum([d['CgstAmt'] for d in einvoice['ItemList']])
- total_item_sgst_value = sum([d['SgstAmt'] for d in einvoice['ItemList']])
- total_item_igst_value = sum([d['IgstAmt'] for d in einvoice['ItemList']])
- total_item_value = sum([d['TotItemVal'] for d in einvoice['ItemList']])
+ total_item_ass_value = 0
+ total_item_cgst_value = 0
+ total_item_sgst_value = 0
+ total_item_igst_value = 0
+ total_item_value = 0
+
+ for item in einvoice['ItemList']:
+ total_item_ass_value += item['AssAmt']
+ total_item_cgst_value += item['CgstAmt']
+ total_item_sgst_value += item['SgstAmt']
+ total_item_igst_value += item['IgstAmt']
+ total_item_value += item['TotItemVal']
+
+ self.assertTrue(item['AssAmt'], item['TotAmt'] - item['Discount'])
+ self.assertTrue(item['TotItemVal'], item['AssAmt'] + item['CgstAmt'] + item['SgstAmt'] + item['IgstAmt'])
+
+ value_details = einvoice['ValDtls']
self.assertEqual(einvoice['Version'], '1.1')
- self.assertEqual(einvoice['ValDtls']['AssVal'], total_item_ass_value)
- self.assertEqual(einvoice['ValDtls']['CgstVal'], total_item_cgst_value)
- self.assertEqual(einvoice['ValDtls']['SgstVal'], total_item_sgst_value)
- self.assertEqual(einvoice['ValDtls']['IgstVal'], total_item_igst_value)
- self.assertEqual(einvoice['ValDtls']['TotInvVal'], total_item_value)
+ self.assertEqual(value_details['AssVal'], total_item_ass_value)
+ self.assertEqual(value_details['CgstVal'], total_item_cgst_value)
+ self.assertEqual(value_details['SgstVal'], total_item_sgst_value)
+ self.assertEqual(value_details['IgstVal'], total_item_igst_value)
+
+ calculated_invoice_value = \
+ value_details['AssVal'] + value_details['CgstVal'] \
+ + value_details['SgstVal'] + value_details['IgstVal'] \
+ + value_details['OthChrg'] - value_details['Discount']
+
+ self.assertTrue(value_details['TotInvVal'] - calculated_invoice_value < 0.1)
+
+ self.assertEqual(value_details['TotInvVal'], si.base_grand_total)
self.assertTrue(einvoice['EwbDtls'])
-def make_sales_invoice_for_ewaybill():
+def make_test_address_for_ewaybill():
if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'):
address = frappe.get_doc({
"address_line1": "_Test Address Line 1",
@@ -1992,6 +1996,7 @@ def make_sales_invoice_for_ewaybill():
address.save()
+def make_test_transporter_for_ewaybill():
if not frappe.db.exists('Supplier', '_Test Transporter'):
frappe.get_doc({
"doctype": "Supplier",
@@ -2002,12 +2007,17 @@ def make_sales_invoice_for_ewaybill():
"is_transporter": 1
}).insert()
+def make_sales_invoice_for_ewaybill():
+ make_test_address_for_ewaybill()
+ make_test_transporter_for_ewaybill()
+
gst_settings = frappe.get_doc("GST Settings")
gst_account = frappe.get_all(
"GST Account",
fields=["cgst_account", "sgst_account", "igst_account"],
- filters = {"company": "_Test Company"})
+ filters = {"company": "_Test Company"}
+ )
if not gst_account:
gst_settings.append("gst_accounts", {
@@ -2019,7 +2029,7 @@ def make_sales_invoice_for_ewaybill():
gst_settings.save()
- si = create_sales_invoice(do_not_save =1, rate = '60000')
+ si = create_sales_invoice(do_not_save=1, rate='60000')
si.distance = 2000
si.company_address = "_Test Address for Eway bill-Billing"
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 7a98afff364..b403c7b2375 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -45,6 +45,7 @@
"base_rate",
"base_amount",
"pricing_rules",
+ "stock_uom_rate",
"is_free_item",
"section_break_21",
"net_rate",
@@ -811,12 +812,20 @@
"no_copy": 1,
"print_hide": 1,
"read_only": 1
+ },
+ {
+ "depends_on": "eval: doc.uom != doc.stock_uom",
+ "fieldname": "stock_uom_rate",
+ "fieldtype": "Currency",
+ "label": "Rate of Stock UOM",
+ "options": "currency",
+ "read_only": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2020-12-26 17:25:04.090630",
+ "modified": "2021-01-30 21:42:37.796771",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
index b46de6c85bb..429a9f3591d 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
@@ -34,6 +34,9 @@ def valdiate_taxes_and_charges_template(doc):
validate_disabled(doc)
+ # Validate with existing taxes and charges template for unique tax category
+ validate_for_tax_category(doc)
+
for tax in doc.get("taxes"):
validate_taxes_and_charges(tax)
validate_inclusive_tax(tax, doc)
@@ -41,3 +44,7 @@ def valdiate_taxes_and_charges_template(doc):
def validate_disabled(doc):
if doc.is_default and doc.disabled:
frappe.throw(_("Disabled template must not be default template"))
+
+def validate_for_tax_category(doc):
+ if frappe.db.exists(doc.doctype, {"company": doc.company, "tax_category": doc.tax_category, "disabled": 0}):
+ frappe.throw(_("A template with tax category {0} already exists. Only one template is allowed with each tax category").format(frappe.bold(doc.tax_category)))
diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py
index 552a5d476b0..e023b47caca 100644
--- a/erpnext/accounts/doctype/subscription/subscription.py
+++ b/erpnext/accounts/doctype/subscription/subscription.py
@@ -446,7 +446,7 @@ class Subscription(Document):
if not self.generate_invoice_at_period_start:
return False
- if self.is_new_subscription():
+ if self.is_new_subscription() and getdate() >= getdate(self.current_invoice_start):
return True
# Check invoice dates and make sure it doesn't have outstanding invoices
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 287c79f13fe..b42c0c61d9e 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -44,9 +44,9 @@ def validate_accounting_period(gl_map):
frappe.throw(_("You cannot create or cancel any accounting entries with in the closed Accounting Period {0}")
.format(frappe.bold(accounting_periods[0].name)), ClosedAccountingPeriod)
-def process_gl_map(gl_map, merge_entries=True):
+def process_gl_map(gl_map, merge_entries=True, precision=None):
if merge_entries:
- gl_map = merge_similar_entries(gl_map)
+ gl_map = merge_similar_entries(gl_map, precision)
for entry in gl_map:
# toggle debit, credit if negative entry
if flt(entry.debit) < 0:
@@ -69,7 +69,7 @@ def process_gl_map(gl_map, merge_entries=True):
return gl_map
-def merge_similar_entries(gl_map):
+def merge_similar_entries(gl_map, precision=None):
merged_gl_map = []
accounting_dimensions = get_accounting_dimensions()
for entry in gl_map:
@@ -88,7 +88,9 @@ def merge_similar_entries(gl_map):
company = gl_map[0].company if gl_map else erpnext.get_default_company()
company_currency = erpnext.get_company_currency(company)
- precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency)
+
+ if not precision:
+ precision = get_field_precision(frappe.get_meta("GL Entry").get_field("debit"), company_currency)
# filter zero debit and credit entries
merged_gl_map = filter(lambda x: flt(x.debit, precision)!=0 or flt(x.credit, precision)!=0, merged_gl_map)
@@ -132,8 +134,8 @@ def make_entry(args, adv_adj, update_outstanding, from_repost=False):
gle.update(args)
gle.flags.ignore_permissions = 1
gle.flags.from_repost = from_repost
- gle.insert()
- gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost)
+ gle.flags.adv_adj = adv_adj
+ gle.flags.update_outstanding = update_outstanding or 'Yes'
gle.submit()
if not from_repost:
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 64268b8064e..38b228477f7 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -39,7 +39,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
party_details = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype))
party = party_details[party_type.lower()]
- if not ignore_permissions and not frappe.has_permission(party_type, "read", party):
+ if not ignore_permissions and not (frappe.has_permission(party_type, "read", party) or frappe.has_permission(party_type, "select", party)):
frappe.throw(_("Not permitted for {0}").format(party), frappe.PermissionError)
party = frappe.get_doc(party_type, party)
diff --git a/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html
index 9827e00b71b..8eef2adce3e 100644
--- a/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html
+++ b/erpnext/accounts/print_format/gst_e_invoice/gst_e_invoice.html
@@ -152,7 +152,7 @@
"
continue
+
#on other field types add label and value to html
if not df.hidden and not df.print_hide and doc.get(df.fieldname) and df.fieldname not in exclude_fields:
- html += ' {0} : {1}'.format(df.label or df.fieldname, \
- doc.get(df.fieldname))
+ if doc.get(df.fieldname):
+ formatted_value = format_value(doc.get(df.fieldname), meta.get_field(df.fieldname), doc)
+ html += ' {0} : {1}'.format(df.label or df.fieldname, formatted_value)
+
if not has_data : has_data = True
+
if sec_on and col_on and has_data:
doc_html += section_html + html + '
PAYER'S name, street address, city or town, state or province, country, ZIP or foreign postal code, and telephone no. \n\t{{company if company else \"\"}} \n\t{{payer_street_address if payer_street_address else \"\"}}\n
\n
1 Rents
\n
OMB No. 1545-0115 2018 Form 1099-MISC
\n
Miscellaneous Income
\n
\n
\n
2 Royalties
\n
\n
\n
3 Other Income \n\t{{payments if payments else \"\"}}\n\t
\n
4 Federal Income tax withheld
\n
Copy A For Internal Revenue Service Center
File with Form 1096
\n
\n
\n
PAYER'S TIN \n\t{{company_tin if company_tin else \"\"}}\n\t
\n \n
RECIPIENT'S TIN
\n {{tax_id if tax_id else \"None\"}}\n
\n
Fishing boat proceeds
\n
6 Medical and health care payments
\n
\n
\n
RECIPIENT'S name \n {{supplier if supplier else \"\"}}\n
\n
7 Nonemployee compensation \n\t
\n
Substitute payments in lieu of dividends or interest
\n
For Privacy Act and Paperwork Reduction Act Notice, see the 2018 General Instructions for Certain Information Returns.
\n
\n
\n
Street address (including apt. no.) \n\t{{recipient_street_address if recipient_street_address else \"\"}}\n\t
\n
$___________
\n
$___________
\n
\n
\n
9 Payer made direct sales of $5,000 or more of consumer products to a buyer (recipient) for resale
\n
10 Crop insurance proceeds
\n
\n
\n
City or town, state or province, country, and ZIP or foreign postal code \n\t{{recipient_city_state if recipient_city_state else \"\"}}\n
\n
$___________
\n
\n
\n
11
\n
12
\n
\n
\n
Account number (see instructions)
\n
FACTA filing requirement
\n
2nd TIN not.
\n
13 Excess golden parachute payments $___________
\n
14 Gross proceeds paid to an attorney $___________
\n
\n
\n
15a Section 409A deferrals
\n
15b Section 409 income
\n
16 State tax withheld
\n
17 State/Payer's state no.
\n
18 State income
\n
\n
\n
$
\n
$
\n
$
\n
\n
$
\n
\n\n
\n
Form 1099-MISC Cat. No. 14425J www.irs.gov/Form1099MISC Department of the Treasury - Internal Revenue Service
\n
\n\n \n
\n
\n
\n
\n \n
\n
PAYER'S name, street address, city or town, state or province, country, ZIP or foreign postal code, and telephone no. \n {{company if company else \"\"}} \n \t{{payer_street_address if payer_street_address else \"\"}}
\n
1 Rents
\n
OMB No. 1545-0115 2018 Form 1099-MISC
\n
Miscellaneous Income
\n
\n
\n
2 Royalties
\n
\n
\n
3 Other Income \n\t{{payments if payments else \"\"}}\n\t
\n
4 Federal Income tax withheld
\n
Copy 1 For State Tax Department
\n
\n
\n
PAYER'S TIN \n\t{{company_tin if company_tin else \"\"}}\n\t
\n
RECIPIENT'S TIN \n\t{{tax_id if tax_id else \"\"}}\n\t
\n
Fishing boat proceeds
\n
6 Medical and health care payments
\n
\n
\n
RECIPIENT'S name
\n {{supplier if supplier else \"\"}}\n
7 Nonemployee compensation \n\t
\n
Substitute payments in lieu of dividends or interest
\n
\n
\n
\n
Street address (including apt. no.) \n\t{{recipient_street_address if recipient_street_address else \"\"}}\n\t
\n
$___________
\n
$___________
\n
\n
\n
9 Payer made direct sales of $5,000 or more of consumer products to a buyer (recipient) for resale
\n
10 Crop insurance proceeds
\n
\n
\n
City or town, state or province, country, and ZIP or foreign postal code \n\t{{recipient_city_state if recipient_city_state else \"\"}}\n\t
\n
$___________
\n
\n
\n
11
\n
12
\n
\n
\n
Account number (see instructions)
\n
FACTA filing requirement
\n
2nd TIN not.
\n
13 Excess golden parachute payments $___________
\n
14 Gross proceeds paid to an attorney $___________
\n
\n
\n
15a Section 409A deferrals
\n
15b Section 409 income
\n
16 State tax withheld
\n
17 State/Payer's state no.
\n
18 State income
\n
\n
\n
$
\n
$
\n
$
\n
\n
$
\n
\n\n
\n
Form 1099-MISC Cat. No. 14425J www.irs.gov/Form1099MISC Department of the Treasury - Internal Revenue Service
PAYER'S name, street address,\n city or town, state or province, country, ZIP or foreign postal code, and telephone no. \n {{ company or \"\" }} \n {{ payer_street_address or \"\" }}\n
Substitute payments in lieu of dividends or interest
\n
For Privacy Act and Paperwork Reduction Act Notice, see\n the 2018 General Instructions for Certain Information Returns.
\n
\n
\n
Street address (including apt. no.) \n {{ recipient_street_address or \"\" }}\n
\n
$___________
\n
$___________
\n
\n
\n
9 Payer made direct sales of $5,000 or more of consumer\n products to a buyer (recipient) for resale
\n
10 Crop insurance proceeds
\n
\n
\n
City or town, state or province, country, and ZIP or\n foreign postal code \n {{ recipient_city_state or \"\" }}\n
\n
$___________
\n
\n
\n
11
\n
12
\n
\n
\n
Account number (see instructions)
\n
FACTA filing requirement
\n
2nd TIN not.
\n
13 Excess golden parachute payments $___________
\n
14 Gross proceeds paid to an attorney $___________
\n
\n
\n
15a Section 409A deferrals
\n
15b Section 409 income
\n
16 State tax withheld
\n
17 State/Payer's state no.
\n
18 State income
\n
\n
\n
$
\n
$
\n
$
\n
\n
$
\n
\n\n
\n
Form 1099-MISC Cat. No. 14425J www.irs.gov/Form1099MISC Department of the\n Treasury - Internal Revenue Service
\n
\n\n \n
\n
\n
\n
\n \n
\n
PAYER'S name, street address,\n city or town, state or province, country, ZIP or foreign postal code, and telephone no. \n {{ company or \"\"}}\n {{ payer_street_address or \"\" }}\n