offline email for POS
This commit is contained in:
parent
f0c7ba4b1f
commit
b5097ec161
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||
import frappe, json
|
||||
from frappe.utils import nowdate
|
||||
from erpnext.setup.utils import get_exchange_rate
|
||||
from frappe.core.doctype.communication.email import make
|
||||
from erpnext.stock.get_item_details import get_pos_profile
|
||||
from erpnext.accounts.party import get_party_account_currency
|
||||
from erpnext.controllers.accounts_controller import get_taxes_and_charges
|
||||
@ -257,12 +258,14 @@ def get_pricing_rule_data(doc):
|
||||
return pricing_rules
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_invoice(doc_list):
|
||||
def make_invoice(doc_list, email_queue_list):
|
||||
if isinstance(doc_list, basestring):
|
||||
doc_list = json.loads(doc_list)
|
||||
|
||||
name_list = []
|
||||
if isinstance(email_queue_list, basestring):
|
||||
email_queue = json.loads(email_queue_list)
|
||||
|
||||
name_list = []
|
||||
for docs in doc_list:
|
||||
for name, doc in docs.items():
|
||||
if not frappe.db.exists('Sales Invoice', {'offline_pos_name': name}):
|
||||
@ -270,17 +273,37 @@ def make_invoice(doc_list):
|
||||
si_doc = frappe.new_doc('Sales Invoice')
|
||||
si_doc.offline_pos_name = name
|
||||
si_doc.update(doc)
|
||||
submit_invoice(si_doc, name)
|
||||
submit_invoice(si_doc, name, doc)
|
||||
name_list.append(name)
|
||||
else:
|
||||
name_list.append(name)
|
||||
|
||||
return name_list
|
||||
email_queue = make_email_queue(email_queue)
|
||||
return {
|
||||
'invoice': name_list,
|
||||
'email_queue': email_queue
|
||||
}
|
||||
|
||||
def validate_records(doc):
|
||||
validate_customer(doc)
|
||||
validate_item(doc)
|
||||
|
||||
def make_email_queue(email_queue):
|
||||
name_list = []
|
||||
for key, data in email_queue.items():
|
||||
name = frappe.db.get_value('Sales Invoice', {'offline_pos_name': key}, 'name')
|
||||
data = json.loads(data)
|
||||
sender = frappe.session.user
|
||||
print_format = "POS Invoice"
|
||||
attachments = [frappe.attach_print('Sales Invoice', name, print_format= print_format)]
|
||||
|
||||
make(subject = data.get('subject'), content = data.get('content'), recipients = data.get('recipients'),
|
||||
sender=sender,attachments = attachments, send_email=True,
|
||||
doctype='Sales Invoice', name=name)
|
||||
name_list.append(key)
|
||||
|
||||
return name_list
|
||||
|
||||
def validate_customer(doc):
|
||||
if not frappe.db.exists('Customer', doc.get('customer')):
|
||||
customer_doc = frappe.new_doc('Customer')
|
||||
@ -328,7 +351,8 @@ def validate_item(doc):
|
||||
item_doc.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
|
||||
def submit_invoice(si_doc, name):
|
||||
|
||||
def submit_invoice(si_doc, name, doc):
|
||||
try:
|
||||
si_doc.insert()
|
||||
si_doc.submit()
|
||||
|
@ -95,11 +95,65 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
||||
me.sync_sales_invoice()
|
||||
});
|
||||
|
||||
this.page.add_menu_item(__("Email"), function () {
|
||||
if(me.frm.doc.docstatus == 1) {
|
||||
me.email_prompt()
|
||||
}
|
||||
});
|
||||
|
||||
this.page.add_menu_item(__("POS Profile"), function () {
|
||||
frappe.set_route('List', 'POS Profile');
|
||||
});
|
||||
},
|
||||
|
||||
email_prompt: function() {
|
||||
var me = this;
|
||||
fields = [{label:__("To"), fieldtype:"Data", reqd: 0, fieldname:"recipients",length:524288},
|
||||
{fieldtype: "Section Break", collapsible: 1, label: "CC & Standard Reply"},
|
||||
{fieldtype: "Section Break"},
|
||||
{label:__("Subject"), fieldtype:"Data", reqd: 1,
|
||||
fieldname:"subject",length:524288},
|
||||
{fieldtype: "Section Break"},
|
||||
{label:__("Message"), fieldtype:"Text Editor", reqd: 1,
|
||||
fieldname:"content"},
|
||||
{fieldtype: "Section Break"},
|
||||
{fieldtype: "Column Break"}];
|
||||
|
||||
this.email_dialog = new frappe.ui.Dialog({
|
||||
title: "Email",
|
||||
fields: fields,
|
||||
primary_action_label: __("Send"),
|
||||
primary_action: function() {
|
||||
me.send_action();
|
||||
}
|
||||
});
|
||||
|
||||
this.email_dialog.show()
|
||||
},
|
||||
|
||||
send_action: function() {
|
||||
this.email_queue = this.get_email_queue()
|
||||
this.email_queue[this.frm.doc.offline_pos_name] = JSON.stringify(this.email_dialog.get_values())
|
||||
this.update_email_queue()
|
||||
this.email_dialog.hide()
|
||||
},
|
||||
|
||||
update_email_queue: function () {
|
||||
try {
|
||||
localStorage.setItem('email_queue', JSON.stringify(this.email_queue));
|
||||
} catch (e) {
|
||||
frappe.throw(__("LocalStorage is full , did not save"))
|
||||
}
|
||||
},
|
||||
|
||||
get_email_queue: function () {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem('email_queue')) || {};
|
||||
} catch (e) {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
|
||||
dialog_actions: function () {
|
||||
var me = this;
|
||||
|
||||
@ -1282,18 +1336,22 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
||||
|
||||
sync_sales_invoice: function () {
|
||||
var me = this;
|
||||
this.si_docs = this.get_submitted_invoice();
|
||||
this.si_docs = this.get_submitted_invoice() || [];
|
||||
this.email_queue_list = this.get_email_queue() || {};
|
||||
|
||||
if (this.si_docs.length) {
|
||||
if (this.si_docs.length || this.email_queue_list) {
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
|
||||
args: {
|
||||
doc_list: me.si_docs
|
||||
doc_list: me.si_docs,
|
||||
email_queue_list: me.email_queue_list
|
||||
},
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
me.removed_items = r.message;
|
||||
me.removed_items = r.message.invoice;
|
||||
me.removed_email = r.message.email_queue
|
||||
me.remove_doc_from_localstorage();
|
||||
me.remove_email_queue_from_localstorage();
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -1323,10 +1381,10 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
||||
var me = this;
|
||||
this.si_docs = this.get_doc_from_localstorage();
|
||||
this.new_si_docs = [];
|
||||
if (this.removed_items) {
|
||||
if (this.removed_email) {
|
||||
$.each(this.si_docs, function (index, data) {
|
||||
for (key in data) {
|
||||
if (!in_list(me.removed_items, key)) {
|
||||
if (!in_list(me.removed_email, key)) {
|
||||
me.new_si_docs.push(data);
|
||||
}
|
||||
}
|
||||
@ -1336,6 +1394,19 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
|
||||
remove_email_queue_from_localstorage: function() {
|
||||
var me = this;
|
||||
this.email_queue = this.get_email_queue()
|
||||
if (this.removed_email) {
|
||||
$.each(this.email_queue_list, function (index, data) {
|
||||
if (in_list(me.removed_email, index)) {
|
||||
delete me.email_queue[index]
|
||||
}
|
||||
})
|
||||
this.update_email_queue();
|
||||
}
|
||||
},
|
||||
|
||||
validate: function () {
|
||||
var me = this;
|
||||
this.customer_validate();
|
||||
|
@ -65,10 +65,10 @@
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-5 selected-item">
|
||||
<div class="col-xs-6 selected-item">
|
||||
|
||||
</div>
|
||||
<div class="col-xs-7 numeric_keypad" style="display:none">
|
||||
<div class="col-xs-6 numeric_keypad" style="display:none">
|
||||
{% var chartData = ["Qty", "Disc", "Price"] %}
|
||||
{% for(var i=0; i<3; i++) { %}
|
||||
<div class="row text-right">
|
||||
@ -100,10 +100,10 @@
|
||||
<div class="app-listing item-list"></ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="row">
|
||||
<div class="row">
|
||||
<div class="text-right list-paging-area">
|
||||
<button class="btn btn-default btn-more btn-sm" style="margin:5px 20px">{{ __("More") }}</button>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,4 +1,3 @@
|
||||
<h5 style="margin-top:5px">Item <span class="text-primary no-margin font-montserrat">{%= item_name %}</h5>
|
||||
<div class="pos-bill-item" data-item-code="{%= item_code %}">
|
||||
<div class="form-group edit-pos-item">
|
||||
<label class=" text-left col-xs-4">Price:</label>
|
||||
|
Loading…
x
Reference in New Issue
Block a user