fix(shopping-cart): address is made mandatory to place order
This commit is contained in:
parent
6ec4618914
commit
4635ff9368
@ -38,14 +38,14 @@ def get_cart_quotation(doc=None):
|
||||
addresses = get_address_docs(party=party)
|
||||
|
||||
if not doc.customer_address and addresses:
|
||||
update_cart_address("customer_address", addresses[0].name)
|
||||
update_cart_address("billing", addresses[0].name)
|
||||
|
||||
return {
|
||||
"doc": decorate_quotation_doc(doc),
|
||||
"shipping_addresses": [{"name": address.name, "display": address.display}
|
||||
for address in addresses],
|
||||
for address in addresses if address.address_type == "Shipping"],
|
||||
"billing_addresses": [{"name": address.name, "display": address.display}
|
||||
for address in addresses],
|
||||
for address in addresses if address.address_type == "Billing"],
|
||||
"shipping_rules": get_applicable_shipping_rules(party),
|
||||
"cart_settings": frappe.get_cached_doc("Shopping Cart Settings")
|
||||
}
|
||||
@ -64,6 +64,9 @@ def place_order():
|
||||
# company used to create customer accounts
|
||||
frappe.defaults.set_user_default("company", quotation.company)
|
||||
|
||||
if not (quotation.shipping_address_name or quotation.customer_address):
|
||||
frappe.throw(_("Set Shipping Address or Billing Address"))
|
||||
|
||||
from erpnext.selling.doctype.quotation.quotation import _make_sales_order
|
||||
sales_order = frappe.get_doc(_make_sales_order(quotation.name, ignore_permissions=True))
|
||||
sales_order.payment_schedule = []
|
||||
@ -194,21 +197,16 @@ def get_terms_and_conditions(terms_name):
|
||||
return frappe.db.get_value('Terms and Conditions', terms_name, 'terms')
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_cart_address(address_fieldname, address_name):
|
||||
def update_cart_address(address_type, address_name):
|
||||
quotation = _get_cart_quotation()
|
||||
address_display = get_address_display(frappe.get_doc("Address", address_name).as_dict())
|
||||
|
||||
if address_fieldname == "shipping_address_name":
|
||||
quotation.shipping_address_name = address_name
|
||||
quotation.shipping_address = address_display
|
||||
|
||||
if not quotation.customer_address:
|
||||
address_fieldname == "customer_address"
|
||||
|
||||
if address_fieldname == "customer_address":
|
||||
if address_type.lower() == "billing":
|
||||
quotation.customer_address = address_name
|
||||
quotation.address_display = address_display
|
||||
|
||||
elif address_type.lower() == "shipping":
|
||||
quotation.shipping_address_name = address_name
|
||||
quotation.shipping_address = address_display
|
||||
|
||||
apply_cart_settings(quotation=quotation)
|
||||
|
||||
|
@ -26,15 +26,14 @@ $.extend(shopping_cart, {
|
||||
bind_address_select: function() {
|
||||
$(".cart-addresses").on('click', '.address-card', function(e) {
|
||||
const $card = $(e.currentTarget);
|
||||
const address_fieldname = $card.closest('[data-fieldname]').attr('data-fieldname');
|
||||
const address_type = $card.closest('[data-address-type]').attr('data-address-type');
|
||||
const address_name = $card.closest('[data-address-name]').attr('data-address-name');
|
||||
|
||||
return frappe.call({
|
||||
type: "POST",
|
||||
method: "erpnext.shopping_cart.cart.update_cart_address",
|
||||
freeze: true,
|
||||
args: {
|
||||
address_fieldname,
|
||||
address_type,
|
||||
address_name
|
||||
},
|
||||
callback: function(r) {
|
||||
|
@ -18,7 +18,7 @@
|
||||
<h6 class="text-uppercase">{{ _("Shipping Address") }}</h6>
|
||||
<div class="row no-gutters" data-fieldname="shipping_address_name">
|
||||
{% for address in shipping_addresses %}
|
||||
<div class="mr-3 mb-3 w-25" data-address-name="{{address.name}}" {% if doc.shipping_address_name == address.name %} data-active {% endif %}>
|
||||
<div class="mr-3 mb-3 w-25" data-address-name="{{address.name}}" data-address-type="shipping" {% if doc.shipping_address_name == address.name %} data-active {% endif %}>
|
||||
{% include "templates/includes/cart/address_card.html" %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
@ -28,7 +28,7 @@
|
||||
<h6 class="text-uppercase">{{ _("Billing Address") }}</h6>
|
||||
<div class="row no-gutters" data-fieldname="customer_address">
|
||||
{% for address in billing_addresses %}
|
||||
<div class="mr-3 mb-3 w-25" data-address-name="{{address.name}}" {% if doc.customer_address == address.name %} data-active {% endif %}>
|
||||
<div class="mr-3 mb-3 w-25" data-address-name="{{address.name}}" data-address-type="billing" {% if doc.customer_address == address.name %} data-active {% endif %}>
|
||||
{% include "templates/includes/cart/address_card.html" %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
@ -123,9 +123,19 @@ frappe.ready(() => {
|
||||
primary_action: (values) => {
|
||||
frappe.call('erpnext.shopping_cart.cart.add_new_address', { doc: values })
|
||||
.then(r => {
|
||||
d.hide();
|
||||
window.location.reload();
|
||||
frappe.call({
|
||||
method: "erpnext.shopping_cart.cart.update_cart_address",
|
||||
args: {
|
||||
address_type: r.message.address_type,
|
||||
address_name: r.message.name
|
||||
},
|
||||
callback: function (r) {
|
||||
d.hide();
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user