mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-17 16:45:02 +00:00
fix(Selling,E-Commerce): Shopping cart quotation without website item. (#29085)
* test: assert error if quotation contains non website item * fix(test): validate exception without website item * fix: shopping cart quotation without website item * fix: sider issues * fix: linter trilaing whitespace * fix: linter format string after translation * fix: Skip unpublished Variants with published templates in shopping cart quote validation * style: Re-run pre-commit Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b585262842
commit
ea0fe5e10c
@@ -26,6 +26,7 @@ class Quotation(SellingController):
|
|||||||
self.set_status()
|
self.set_status()
|
||||||
self.validate_uom_is_integer("stock_uom", "qty")
|
self.validate_uom_is_integer("stock_uom", "qty")
|
||||||
self.validate_valid_till()
|
self.validate_valid_till()
|
||||||
|
self.validate_shopping_cart_items()
|
||||||
self.set_customer_name()
|
self.set_customer_name()
|
||||||
if self.items:
|
if self.items:
|
||||||
self.with_items = 1
|
self.with_items = 1
|
||||||
@@ -38,6 +39,26 @@ class Quotation(SellingController):
|
|||||||
if self.valid_till and getdate(self.valid_till) < getdate(self.transaction_date):
|
if self.valid_till and getdate(self.valid_till) < getdate(self.transaction_date):
|
||||||
frappe.throw(_("Valid till date cannot be before transaction date"))
|
frappe.throw(_("Valid till date cannot be before transaction date"))
|
||||||
|
|
||||||
|
def validate_shopping_cart_items(self):
|
||||||
|
if self.order_type != "Shopping Cart":
|
||||||
|
return
|
||||||
|
|
||||||
|
for item in self.items:
|
||||||
|
has_web_item = frappe.db.exists("Website Item", {"item_code": item.item_code})
|
||||||
|
|
||||||
|
# If variant is unpublished but template is published: valid
|
||||||
|
template = frappe.get_cached_value("Item", item.item_code, "variant_of")
|
||||||
|
if template and not has_web_item:
|
||||||
|
has_web_item = frappe.db.exists("Website Item", {"item_code": template})
|
||||||
|
|
||||||
|
if not has_web_item:
|
||||||
|
frappe.throw(
|
||||||
|
_("Row #{0}: Item {1} must have a Website Item for Shopping Cart Quotations").format(
|
||||||
|
item.idx, frappe.bold(item.item_code)
|
||||||
|
),
|
||||||
|
title=_("Unpublished Item"),
|
||||||
|
)
|
||||||
|
|
||||||
def has_sales_order(self):
|
def has_sales_order(self):
|
||||||
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,15 @@ class TestQuotation(FrappeTestCase):
|
|||||||
quotation.submit()
|
quotation.submit()
|
||||||
self.assertRaises(frappe.ValidationError, make_sales_order, quotation.name)
|
self.assertRaises(frappe.ValidationError, make_sales_order, quotation.name)
|
||||||
|
|
||||||
|
def test_shopping_cart_without_website_item(self):
|
||||||
|
if frappe.db.exists("Website Item", {"item_code": "_Test Item Home Desktop 100"}):
|
||||||
|
frappe.get_last_doc("Website Item", {"item_code": "_Test Item Home Desktop 100"}).delete()
|
||||||
|
|
||||||
|
quotation = frappe.copy_doc(test_records[0])
|
||||||
|
quotation.order_type = "Shopping Cart"
|
||||||
|
quotation.valid_till = getdate()
|
||||||
|
self.assertRaises(frappe.ValidationError, quotation.validate)
|
||||||
|
|
||||||
def test_create_quotation_with_margin(self):
|
def test_create_quotation_with_margin(self):
|
||||||
from erpnext.selling.doctype.quotation.quotation import make_sales_order
|
from erpnext.selling.doctype.quotation.quotation import make_sales_order
|
||||||
from erpnext.selling.doctype.sales_order.sales_order import (
|
from erpnext.selling.doctype.sales_order.sales_order import (
|
||||||
|
|||||||
Reference in New Issue
Block a user