Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Quotation): calculate row values for alternative items #43054

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def filter_rows(self):
return items

def calculate(self):
if not len(self._items):
if not len(self.doc.items):
return

self.discount_amount_applied = False
Expand Down Expand Up @@ -96,7 +96,7 @@ def validate_item_tax_template(self):
if self.doc.get("is_return") and self.doc.get("return_against"):
return

for item in self._items:
for item in self.doc.items:
if item.item_code and item.get("item_tax_template"):
item_doc = frappe.get_cached_doc("Item", item.item_code)
args = {
Expand Down Expand Up @@ -155,7 +155,7 @@ def calculate_item_values(self):
return

if not self.discount_amount_applied:
for item in self._items:
for item in self.doc.items:
self.doc.round_floats_in(item)

if item.discount_percentage == 100:
Expand Down Expand Up @@ -259,7 +259,7 @@ def determine_exclusive_rate(self):
if not any(cint(tax.included_in_print_rate) for tax in self.doc.get("taxes")):
return

for item in self._items:
for item in self.doc.items:
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
cumulated_tax_fraction = 0
total_inclusive_tax_amount_per_qty = 0
Expand Down
6 changes: 3 additions & 3 deletions erpnext/public/js/controllers/taxes_and_totals.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
calculate_item_values() {
var me = this;
if (!this.discount_amount_applied) {
for (const item of this.frm._items || []) {
for (const item of this.frm.doc.items || []) {
frappe.model.round_floats_in(item);
item.net_rate = item.rate;
item.qty = item.qty === undefined ? (me.frm.doc.is_return ? -1 : 1) : item.qty;
Expand Down Expand Up @@ -227,7 +227,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
});
if(has_inclusive_tax==false) return;

$.each(me.frm._items || [], function(n, item) {
$.each(this.frm.doc.items || [], function(n, item) {
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
var cumulated_tax_fraction = 0.0;
var total_inclusive_tax_amount_per_qty = 0;
Expand Down Expand Up @@ -643,7 +643,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {

_cleanup() {
this.frm.doc.base_in_words = this.frm.doc.in_words = "";
let items = this.frm._items;
let items = this.frm.doc.items;

if(items && items.length) {
if(!frappe.meta.get_docfield(items[0].doctype, "item_tax_amount", this.frm.doctype)) {
Expand Down
12 changes: 10 additions & 2 deletions erpnext/selling/doctype/quotation/test_quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,20 @@ def test_alternative_items_with_service_items(self):
"description": "VAT",
"doctype": "Sales Taxes and Charges",
"rate": 10,
"included_in_print_rate": 1,
},
)
quotation.submit()

self.assertEqual(quotation.net_total, 290)
self.assertEqual(quotation.grand_total, 319)
self.assertEqual(round(quotation.items[1].net_rate, 2), 136.36)
self.assertEqual(round(quotation.items[1].amount, 2), 150)

self.assertEqual(round(quotation.items[2].net_rate, 2), 163.64)
self.assertEqual(round(quotation.items[2].amount, 2), 180)

self.assertEqual(round(quotation.net_total, 2), 263.64)
self.assertEqual(round(quotation.total_taxes_and_charges, 2), 26.36)
self.assertEqual(quotation.grand_total, 290)

def test_alternative_items_sales_order_mapping_with_stock_items(self):
from erpnext.selling.doctype.quotation.quotation import make_sales_order
Expand Down
Loading