mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 09:54:47 +00:00
fix: Unreallized profit in Sales Register
This commit is contained in:
@@ -130,16 +130,15 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
|
|
||||||
this.set_default_print_format();
|
this.set_default_print_format();
|
||||||
if (doc.docstatus == 1 && !doc.inter_company_invoice_reference) {
|
if (doc.docstatus == 1 && !doc.inter_company_invoice_reference) {
|
||||||
frappe.model.with_doc("Customer", me.frm.doc.customer, function() {
|
let internal = me.frm.doc.is_internal_customer;
|
||||||
var customer = frappe.model.get_doc("Customer", me.frm.doc.customer);
|
if (internal) {
|
||||||
var internal = customer.is_internal_customer;
|
let button_label = (me.frm.doc.company === me.frm.doc.represents_company) ? "Internal Purchase Invoice" :
|
||||||
var disabled = customer.disabled;
|
"Inter Company Purchase Invoice";
|
||||||
if (internal == 1 && disabled == 0) {
|
|
||||||
me.frm.add_custom_button("Inter Company Invoice", function() {
|
me.frm.add_custom_button(button_label, function() {
|
||||||
me.make_inter_company_invoice();
|
me.make_inter_company_invoice();
|
||||||
}, __('Create'));
|
}, __('Create'));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ def _execute(filters, additional_table_columns=None, additional_query_columns=No
|
|||||||
return columns, invoice_list
|
return columns, invoice_list
|
||||||
|
|
||||||
invoice_income_map = get_invoice_income_map(invoice_list)
|
invoice_income_map = get_invoice_income_map(invoice_list)
|
||||||
|
internal_invoice_map = get_internal_invoice_map(invoice_list)
|
||||||
invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list,
|
invoice_income_map, invoice_tax_map = get_invoice_tax_map(invoice_list,
|
||||||
invoice_income_map, income_accounts)
|
invoice_income_map, income_accounts)
|
||||||
#Cost Center & Warehouse Map
|
#Cost Center & Warehouse Map
|
||||||
@@ -70,12 +71,24 @@ def _execute(filters, additional_table_columns=None, additional_query_columns=No
|
|||||||
# map income values
|
# map income values
|
||||||
base_net_total = 0
|
base_net_total = 0
|
||||||
for income_acc in income_accounts:
|
for income_acc in income_accounts:
|
||||||
income_amount = flt(invoice_income_map.get(inv.name, {}).get(income_acc))
|
if inv.is_internal_customer and inv.company == inv.represents_company:
|
||||||
|
income_amount = 0
|
||||||
|
else:
|
||||||
|
income_amount = flt(invoice_income_map.get(inv.name, {}).get(income_acc))
|
||||||
|
|
||||||
base_net_total += income_amount
|
base_net_total += income_amount
|
||||||
row.update({
|
row.update({
|
||||||
frappe.scrub(income_acc): income_amount
|
frappe.scrub(income_acc): income_amount
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Add amount in unrealized account
|
||||||
|
if inv.is_internal_customer and inv.company == inv.represents_company:
|
||||||
|
internal_invoice_details = internal_invoice_map.get(inv.name)
|
||||||
|
if internal_invoice_details:
|
||||||
|
row.update({
|
||||||
|
frappe.scrub(internal_invoice_details['account']): internal_invoice_details['amount']
|
||||||
|
})
|
||||||
|
|
||||||
# net total
|
# net total
|
||||||
row.update({'net_total': base_net_total or inv.base_net_total})
|
row.update({'net_total': base_net_total or inv.base_net_total})
|
||||||
|
|
||||||
@@ -230,6 +243,8 @@ def get_columns(invoice_list, additional_table_columns):
|
|||||||
tax_accounts = []
|
tax_accounts = []
|
||||||
income_columns = []
|
income_columns = []
|
||||||
tax_columns = []
|
tax_columns = []
|
||||||
|
unrealized_profit_loss_accounts = []
|
||||||
|
unrealized_profit_loss_account_columns = []
|
||||||
|
|
||||||
if invoice_list:
|
if invoice_list:
|
||||||
income_accounts = frappe.db.sql_list("""select distinct income_account
|
income_accounts = frappe.db.sql_list("""select distinct income_account
|
||||||
@@ -243,12 +258,18 @@ def get_columns(invoice_list, additional_table_columns):
|
|||||||
and parent in (%s) order by account_head""" %
|
and parent in (%s) order by account_head""" %
|
||||||
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||||
|
|
||||||
|
unrealized_profit_loss_accounts = frappe.db.sql_list("""SELECT distinct unrealized_profit_loss_account
|
||||||
|
from `tabSales Invoice` where docstatus = 1 and name in (%s)
|
||||||
|
and ifnull(unrealized_profit_loss_account, '') != ''
|
||||||
|
order by unrealized_profit_loss_account""" %
|
||||||
|
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
|
||||||
|
|
||||||
for account in income_accounts:
|
for account in income_accounts:
|
||||||
income_columns.append({
|
income_columns.append({
|
||||||
"label": account,
|
"label": account,
|
||||||
"fieldname": frappe.scrub(account),
|
"fieldname": frappe.scrub(account),
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"options": 'currency',
|
"options": "currency",
|
||||||
"width": 120
|
"width": 120
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -258,15 +279,24 @@ def get_columns(invoice_list, additional_table_columns):
|
|||||||
"label": account,
|
"label": account,
|
||||||
"fieldname": frappe.scrub(account),
|
"fieldname": frappe.scrub(account),
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"options": 'currency',
|
"options": "currency",
|
||||||
"width": 120
|
"width": 120
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for account in unrealized_profit_loss_accounts:
|
||||||
|
unrealized_profit_loss_account_columns.append({
|
||||||
|
"label": account,
|
||||||
|
"fieldname": frappe.scrub(account),
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"options": "currency",
|
||||||
|
"width": 120
|
||||||
|
})
|
||||||
|
|
||||||
net_total_column = [{
|
net_total_column = [{
|
||||||
"label": _("Net Total"),
|
"label": _("Net Total"),
|
||||||
"fieldname": "net_total",
|
"fieldname": "net_total",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"options": 'currency',
|
"options": "currency",
|
||||||
"width": 120
|
"width": 120
|
||||||
}]
|
}]
|
||||||
|
|
||||||
@@ -301,7 +331,8 @@ def get_columns(invoice_list, additional_table_columns):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
columns = columns + income_columns + net_total_column + tax_columns + total_columns
|
columns = columns + income_columns + unrealized_profit_loss_account_columns + \
|
||||||
|
net_total_column + tax_columns + total_columns
|
||||||
|
|
||||||
return columns, income_accounts, tax_accounts
|
return columns, income_accounts, tax_accounts
|
||||||
|
|
||||||
@@ -368,7 +399,8 @@ def get_invoices(filters, additional_query_columns):
|
|||||||
return frappe.db.sql("""
|
return frappe.db.sql("""
|
||||||
select name, posting_date, debit_to, project, customer,
|
select name, posting_date, debit_to, project, customer,
|
||||||
customer_name, owner, remarks, territory, tax_id, customer_group,
|
customer_name, owner, remarks, territory, tax_id, customer_group,
|
||||||
base_net_total, base_grand_total, base_rounded_total, outstanding_amount {0}
|
base_net_total, base_grand_total, base_rounded_total, outstanding_amount,
|
||||||
|
is_internal_customer, represents_company, company {0}
|
||||||
from `tabSales Invoice`
|
from `tabSales Invoice`
|
||||||
where docstatus = 1 %s order by posting_date desc, name desc""".format(additional_query_columns or '') %
|
where docstatus = 1 %s order by posting_date desc, name desc""".format(additional_query_columns or '') %
|
||||||
conditions, filters, as_dict=1)
|
conditions, filters, as_dict=1)
|
||||||
@@ -385,6 +417,22 @@ def get_invoice_income_map(invoice_list):
|
|||||||
|
|
||||||
return invoice_income_map
|
return invoice_income_map
|
||||||
|
|
||||||
|
def get_internal_invoice_map(invoice_list):
|
||||||
|
unrealized_amount_details = frappe.db.sql("""SELECT name, unrealized_profit_loss_account,
|
||||||
|
sum(base_net_total) as amount from `tabSales Invoice` where name in (%s)
|
||||||
|
and is_internal_customer = 1 and company = represents_company""" %
|
||||||
|
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
|
||||||
|
|
||||||
|
internal_invoice_map = {}
|
||||||
|
for d in unrealized_amount_details:
|
||||||
|
if d.unrealized_profit_loss_account:
|
||||||
|
internal_invoice_map.setdefault(d.name, {
|
||||||
|
'account': d.unrealized_profit_loss_account,
|
||||||
|
'amount': d.amount
|
||||||
|
})
|
||||||
|
|
||||||
|
return internal_invoice_map
|
||||||
|
|
||||||
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
||||||
tax_details = frappe.db.sql("""select parent, account_head,
|
tax_details = frappe.db.sql("""select parent, account_head,
|
||||||
sum(base_tax_amount_after_discount_amount) as tax_amount
|
sum(base_tax_amount_after_discount_amount) as tax_amount
|
||||||
|
|||||||
@@ -134,6 +134,8 @@
|
|||||||
"ref_sq",
|
"ref_sq",
|
||||||
"column_break_74",
|
"column_break_74",
|
||||||
"party_account_currency",
|
"party_account_currency",
|
||||||
|
"is_internal_supplier",
|
||||||
|
"represents_company",
|
||||||
"inter_company_order_reference"
|
"inter_company_order_reference"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
@@ -1101,13 +1103,27 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "items_col_break",
|
"fieldname": "items_col_break",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fetch_from": "supplier.is_internal_supplier",
|
||||||
|
"fieldname": "is_internal_supplier",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Is Internal Supplier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "supplier.represents_company",
|
||||||
|
"fieldname": "represents_company",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Represents Company",
|
||||||
|
"options": "Company"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-file-text",
|
"icon": "fa fa-file-text",
|
||||||
"idx": 105,
|
"idx": 105,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-12-03 16:46:44.229351",
|
"modified": "2021-01-10 20:50:41.545354",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order",
|
"name": "Purchase Order",
|
||||||
|
|||||||
Reference in New Issue
Block a user