From 3d76686b82e49b35456fdf825781c3d80a1ccdeb Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 16 Sep 2015 18:52:52 +0530 Subject: [PATCH] [shopping-cart] cart via Jinja WIP --- .../doctype/sales_invoice/sales_invoice.py | 33 ++++--- .../controllers/website_list_for_contact.py | 3 + erpnext/shopping_cart/cart.py | 3 +- erpnext/templates/includes/cart.css | 20 ++++- erpnext/templates/includes/cart.js | 61 ++++++------- .../templates/includes/cart/cart_address.html | 24 +++++ .../includes/cart/cart_item_line.html | 16 ++++ .../templates/includes/cart/cart_macros.html | 21 +++++ erpnext/templates/includes/macros.html | 13 --- .../templates/includes/{ => order}/order.css | 0 .../includes/order/order_macros.html | 15 ++++ .../templates/includes/order/order_taxes.html | 19 ++++ erpnext/templates/pages/cart.html | 89 ++++++++----------- erpnext/templates/pages/cart.py | 2 - erpnext/templates/pages/order.html | 24 +---- erpnext/templates/pages/order.py | 3 + 16 files changed, 208 insertions(+), 138 deletions(-) create mode 100644 erpnext/templates/includes/cart/cart_address.html create mode 100644 erpnext/templates/includes/cart/cart_item_line.html create mode 100644 erpnext/templates/includes/cart/cart_macros.html rename erpnext/templates/includes/{ => order}/order.css (100%) create mode 100644 erpnext/templates/includes/order/order_macros.html create mode 100644 erpnext/templates/includes/order/order_taxes.html diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 030fddbb99..885e7bd160 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -35,6 +35,15 @@ class SalesInvoice(SellingController): 'overflow_type': 'billing' }] + def set_indicator(self): + """Set indicator for portal""" + if self.outstanding_amount > 0: + self.indicator_color = "orange" + self.indicator_title = _("Unpaid") + else: + self.indicator_color = "green" + self.indicator_title = _("Paid") + def validate(self): super(SalesInvoice, self).validate() self.validate_posting_time() @@ -90,7 +99,7 @@ class SalesInvoice(SellingController): # this sequence because outstanding may get -ve self.make_gl_entries() - + if not self.is_return: self.update_billing_status_for_zero_amount_refdoc("Sales Order") self.check_credit_limit() @@ -161,10 +170,10 @@ class SalesInvoice(SellingController): 'extra_cond': """ and exists (select name from `tabSales Invoice` where name=`tabSales Invoice Item`.parent and update_stock=1 and is_return=1)""" } ]) - + def check_credit_limit(self): from erpnext.selling.doctype.customer.customer import check_credit_limit - + validate_against_credit_limit = False for d in self.get("items"): if not (d.sales_order or d.delivery_note): @@ -282,7 +291,7 @@ class SalesInvoice(SellingController): reconcile_against_document(lst) def validate_debit_to_acc(self): - account = frappe.db.get_value("Account", self.debit_to, + account = frappe.db.get_value("Account", self.debit_to, ["account_type", "report_type", "account_currency"], as_dict=True) if account.report_type != "Balance Sheet": @@ -290,7 +299,7 @@ class SalesInvoice(SellingController): if self.customer and account.account_type != "Receivable": frappe.throw(_("Debit To account must be a Receivable account")) - + self.party_account_currency = account.account_currency def validate_fixed_asset_account(self): @@ -437,18 +446,18 @@ class SalesInvoice(SellingController): if cint(self.is_pos) == 1: if flt(self.paid_amount) == 0: if self.cash_bank_account: - frappe.db.set(self, 'paid_amount', - flt(flt(self.grand_total) - flt(self.write_off_amount), self.precision("paid_amount"))) + frappe.db.set(self, 'paid_amount', + flt(flt(self.grand_total) - flt(self.write_off_amount), self.precision("paid_amount"))) else: # show message that the amount is not paid frappe.db.set(self,'paid_amount',0) frappe.msgprint(_("Note: Payment Entry will not be created since 'Cash or Bank Account' was not specified")) else: frappe.db.set(self,'paid_amount',0) - - frappe.db.set(self, 'base_paid_amount', + + frappe.db.set(self, 'base_paid_amount', flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount"))) - + def check_prev_docstatus(self): for d in self.get('items'): if d.sales_order and frappe.db.get_value("Sales Order", d.sales_order, "docstatus") != 1: @@ -487,7 +496,7 @@ class SalesInvoice(SellingController): from erpnext.accounts.general_ledger import merge_similar_entries gl_entries = [] - + self.make_customer_gl_entry(gl_entries) self.make_tax_gl_entries(gl_entries) @@ -586,7 +595,7 @@ class SalesInvoice(SellingController): # write off entries, applicable if only pos if self.write_off_account and self.write_off_amount: write_off_account_currency = frappe.db.get_value("Account", self.write_off_account, "account_currency") - + gl_entries.append( self.get_gl_dict({ "account": self.debit_to, diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index 9ec94eb3f8..51fb0a5889 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -66,6 +66,9 @@ def post_process(doctype, data): doc.status_percent += flt(doc.per_delivered) doc.status_display.append(_("Delivered") if doc.per_delivered==100 else _("{0}% Delivered").format(doc.per_delivered)) + if hasattr(doc, "set_indicator"): + doc.set_indicator() + doc.status_display = ", ".join(doc.status_display) doc.items_preview = ", ".join([d.item_name for d in doc.items]) result.append(doc) diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index e219d8ed5f..6ff164b229 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -122,7 +122,8 @@ def update_cart_address(address_fieldname, address_name): quotation.flags.ignore_permissions = True quotation.save() - return get_cart_quotation(quotation) + return frappe.render_template("templates/includes/cart/cart_address.html", + get_cart_quotation(quotation)) def guess_territory(): territory = None diff --git a/erpnext/templates/includes/cart.css b/erpnext/templates/includes/cart.css index ed98846a8d..7a18530286 100644 --- a/erpnext/templates/includes/cart.css +++ b/erpnext/templates/includes/cart.css @@ -1,7 +1,25 @@ .cart-content { min-height: 400px; + margin-top: 60px; } .cart-header, .cart-footer { - margin-bottom: 40px; + margin-bottom: 60px; +} + +.cart-item-header { + padding-bottom: 10px; + margin-bottom: 10px; + border-bottom: 1px solid #d1d8dd; +} + +.tax-grand-total-row { + font-size: 14px; + margin-top: 30px; + font-weight: bold; +} + +.cart-addresses { + margin-top: 80px; + margin-bottom: 60px; } diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js index 349e2f5ed8..e0706f7fce 100644 --- a/erpnext/templates/includes/cart.js +++ b/erpnext/templates/includes/cart.js @@ -13,6 +13,8 @@ $.extend(shopping_cart, { }, bind_events: function() { + shopping_cart.bind_address_select(); + // bind update button $(document).on("click", ".item-update-cart button", function() { var item_code = $(this).attr("data-item-code"); @@ -31,19 +33,36 @@ $.extend(shopping_cart, { }); }); - $("#cart-add-shipping-address").on("click", function() { - window.location.href = "addresses"; - }); - - $("#cart-add-billing-address").on("click", function() { - window.location.href = "address"; - }); - $(".btn-place-order").on("click", function() { shopping_cart.place_order(this); }); }, + bind_address_select: function() { + $(".cart-addresses").find('input[data-address-name]').on("click", function() { + if($(this).prop("checked")) { + var me = this; + + return frappe.call({ + type: "POST", + method: "erpnext.shopping_cart.cart.update_cart_address", + args: { + address_fieldname: $(this).attr("data-fieldname"), + address_name: $(this).attr("data-address-name") + }, + callback: function(r) { + if(!r.exc) { + $('.cart-addresses').html(r.message); + } + } + }); + } else { + return false; + } + }); + + }, + render: function(out) { var doc = out.doc; var addresses = out.addresses; @@ -209,32 +228,6 @@ $.extend(shopping_cart, { +$(this).attr("data-address-name")+'"]').collapse("toggle"); }); - $address_wrapper.find('input[type="checkbox"]').on("click", function() { - if($(this).prop("checked")) { - var me = this; - $address_wrapper.find('input[type="checkbox"]').each(function(i, chk) { - if($(chk).attr("data-address-name")!=$(me).attr("data-address-name")) { - $(chk).prop("checked", false); - } - }); - - return frappe.call({ - type: "POST", - method: "erpnext.shopping_cart.cart.update_cart_address", - args: { - address_fieldname: $address_wrapper.attr("data-fieldname"), - address_name: $(this).attr("data-address-name") - }, - callback: function(r) { - if(!r.exc) { - shopping_cart.render(r.message); - } - } - }); - } else { - return false; - } - }); $address_wrapper.find('input[type="checkbox"][data-address-name="'+ address_name +'"]') .prop("checked", true); diff --git a/erpnext/templates/includes/cart/cart_address.html b/erpnext/templates/includes/cart/cart_address.html new file mode 100644 index 0000000000..44964da47c --- /dev/null +++ b/erpnext/templates/includes/cart/cart_address.html @@ -0,0 +1,24 @@ +{% from "erpnext/templates/includes/cart/cart_macros.html" + import show_address %} +
+
+

{{ _("Shipping Address") }}

+
+ {% for address in addresses %} + {{ show_address(address, doc, "shipping_address_name") }} + {% endfor %} +
+ + {{ _("Manage Addresses") }} +
+
+

Billing Address

+
+ {% for address in addresses %} + {{ show_address(address, doc, "customer_address") }} + {% endfor %} +
+
+
diff --git a/erpnext/templates/includes/cart/cart_item_line.html b/erpnext/templates/includes/cart/cart_item_line.html new file mode 100644 index 0000000000..cd157634a0 --- /dev/null +++ b/erpnext/templates/includes/cart/cart_item_line.html @@ -0,0 +1,16 @@ +{% from "erpnext/templates/includes/order/order_macros.html" import item_name_and_description %} + +
+
+ {{ item_name_and_description(d) }} +
+
+
{{ d.get_formatted('qty') }}
+

+ {{ _("Rate") + ': ' + d.get_formatted("rate") }} +

+
+
+ {{ d.get_formatted("amount") }} +
+
diff --git a/erpnext/templates/includes/cart/cart_macros.html b/erpnext/templates/includes/cart/cart_macros.html new file mode 100644 index 0000000000..250b487920 --- /dev/null +++ b/erpnext/templates/includes/cart/cart_macros.html @@ -0,0 +1,21 @@ +{% macro show_address(address, doc, fieldname) %} +{% set selected=address.name==doc.get(fieldname) %} +
+
+
+
+ {{ address.name }}
+
+
+
+
+
+
{{ address.display }}
+
+
+{% endmacro %} diff --git a/erpnext/templates/includes/macros.html b/erpnext/templates/includes/macros.html index 487968ba81..81a10c2779 100644 --- a/erpnext/templates/includes/macros.html +++ b/erpnext/templates/includes/macros.html @@ -15,16 +15,3 @@ {% endmacro %} -{% macro item_name_and_description(d) %} -
-
-
- {{ product_image_square(d.image) }} -
-
-
- {{ d.item_code }} -

{{ d.description }}

-
-
-{% endmacro %} diff --git a/erpnext/templates/includes/order.css b/erpnext/templates/includes/order/order.css similarity index 100% rename from erpnext/templates/includes/order.css rename to erpnext/templates/includes/order/order.css diff --git a/erpnext/templates/includes/order/order_macros.html b/erpnext/templates/includes/order/order_macros.html new file mode 100644 index 0000000000..af974aad2f --- /dev/null +++ b/erpnext/templates/includes/order/order_macros.html @@ -0,0 +1,15 @@ +{% from "erpnext/templates/includes/macros.html" import product_image_square %} + +{% macro item_name_and_description(d) %} +
+
+
+ {{ product_image_square(d.image) }} +
+
+
+ {{ d.item_code }} +

{{ d.description }}

+
+
+{% endmacro %} diff --git a/erpnext/templates/includes/order/order_taxes.html b/erpnext/templates/includes/order/order_taxes.html new file mode 100644 index 0000000000..510e1a3d89 --- /dev/null +++ b/erpnext/templates/includes/order/order_taxes.html @@ -0,0 +1,19 @@ +{% if doc.taxes %} +
+
{{ _("Net Total") }}
+
+ {{ doc.get_formatted("net_total") }}
+
+{% endif %} +{% for d in doc.taxes %} +
+
{{ d.description }}
+
+ {{ d.get_formatted("base_tax_amount") }}
+
+{% endfor %} +
+
{{ _("Grand Total") }}
+
+ {{ doc.get_formatted("grand_total") }}
+
diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html index 2e1572869f..837df3b056 100644 --- a/erpnext/templates/pages/cart.html +++ b/erpnext/templates/pages/cart.html @@ -5,81 +5,62 @@ {% block script %}{% include "templates/includes/cart.js" %}{% endblock %} {% block style %}{% include "templates/includes/cart.css" %}{% endblock %} + +{% block header_actions %} +{% if doc.items %} + +{% endif %} +{% endblock %} + {% block content %} -{% from "erpnext/templates/includes/macros.html" import item_name_and_description %} +{% from "templates/includes/macros.html" import item_name_and_description %}
-

{{ _("Loading") }}...

-
-

-
-
- +
+
+
+ Items +
+
+ Qty +
+
+ Amount +
+
{% if doc.items %} {% for d in doc.items %}
-
-
- {{ item_name_and_description(d) }} -
-
-
-
- -
-
- -
-
-

- {{ _("Rate") + ': ' + d.get_formatted("rate") }} -

- - {{ d.get_formatted("amount") }} -
-
+ {% include "templates/includes/cart/cart_item_line.html" %}
{% endfor %} {% else %}

{{ _("Cart is Empty") }}

{% endif %}
-
-
+ {% if doc.items %} + +
+
+
+ {% include "templates/includes/order/order_taxes.html" %} +
+
-
-
-
-

{{ _("Shipping Address") }}

-
- -
-
-

Billing Address

-
- -
-
+
+ {% include "templates/includes/cart/cart_address.html" %}
-
+ {% endif %}
diff --git a/erpnext/templates/pages/cart.py b/erpnext/templates/pages/cart.py index bb8645d816..c57d826130 100644 --- a/erpnext/templates/pages/cart.py +++ b/erpnext/templates/pages/cart.py @@ -10,5 +10,3 @@ from erpnext.shopping_cart.cart import get_cart_quotation def get_context(context): context.update(get_cart_quotation()) - - print context diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html index c3bca5bb50..73763921f8 100644 --- a/erpnext/templates/pages/order.html +++ b/erpnext/templates/pages/order.html @@ -3,11 +3,11 @@ {% endblock %} -{% block style %}{% include "templates/includes/order.css" %}{% endblock %} +{% block style %}{% include "templates/includes/order/order.css" %}{% endblock %} {% block content %} -{% from "erpnext/templates/includes/macros.html" import item_name_and_description %} +{% from "erpnext/templates/includes/order/order_macros.html" import item_name_and_description %}
@@ -64,25 +64,7 @@
- {% if doc.taxes %} -
-
{{ _("Net Total") }}
-
- {{ doc.get_formatted("net_total") }}
-
- {% endif %} - {% for d in doc.taxes %} -
-
{{ d.description }}
-
- {{ d.get_formatted("total") }}
-
- {% endfor %} -
-
{{ _("Grand Total") }}
-
- {{ doc.get_formatted("grand_total") }}
-
+ {% include "erpnext/templates/includes/order/order_taxes.html" %}
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py index 260490d129..36444d1f30 100644 --- a/erpnext/templates/pages/order.py +++ b/erpnext/templates/pages/order.py @@ -9,6 +9,9 @@ from frappe import _ def get_context(context): context.no_cache = 1 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) + if hasattr(context.doc, "set_indicator"): + context.doc.set_indicator() + context.parents = frappe.form_dict.parents if not context.doc.has_permission("read"):