Wednesday, 24 January 2018

How to print the collect and print in erpnext desk

import frappe
from frappe.model.document import Document
def get_data(document, method):
doc = frappe.get_doc("Opportunity","OPTY-00003")
frappe.msgprint("Test doc"+doc.name)
frappe.msgprint("Customer name is "+doc.customer)
frappe.msgprint("status is "+doc.status)
comments = frappe.get_list('Communication', fields=['content', 'user'], filters={'reference_name': doc.name})
for com in comments :
frappe.msgprint(com.user)
frappe.msgprint(com.content)
frappe.msgprint("comments over")

Friday, 19 January 2018

Custom script for calculate sales invoice

cur_frm.add_fetch("sales_order","customer","customer");
cur_frm.add_fetch("sales_order","customer_name","customer_name");

cur_frm.add_fetch("item_code","item_name","item_name");
cur_frm.add_fetch("item_code","description","description");
cur_frm.add_fetch("item_code","rate","rate")

//set total quantity of item on save of sales order

frappe.ui.form.on("docttype name ","validate",function(frm){
set_total_qty(frm);
});

// set total quantity of item , on change of qty
frappe.ui.form.on(" Sales Order item","qty", function(frm,cdt,cdn){
set_total_qty(frm);
});

// calculate total quantity

var set_total_qty= function(frm){
var total_qty=0.0;
total_amount=0.0;
$.each(frm.doc.items, function(i,row){
total_qty +=flt(row.qty);
total= toatl_qty * row.rate;
total_amount += flt(total);
})
frm.set_value('total_qty',total_qty);
frm.set_value('total_amount',total_amount);
frm.set_value("total",total_amount);
        frm.refresh();
}

Thursday, 11 January 2018

Send mail script

#Write this code in  docttype-name.js life
frappe.ui.form.on('Sales Order', {
send_email: function(frm) {
if ( frm.doc.email ){
frappe.call({
method : "hotel.api.send_conformation_email",
args : {
hotel :frm.doc.name
}
});
}
}
});

#write this code in api.py file in your application ex. hotel
import frappe
from frappe.model.document import Document
@frappe.whitelist()
def send_conformation_email(hotel):
# i use field as hardcoded so please change according to your req.
frappe.sendmail(
recipients="demo@gmail.com",
sender="test@gmail.com",
subject="sub",
message="content",
send_priority = 0
)
frappe.msgprint("send mail success")

Write a server side script in python or frappe

from __future__ import unicode_literals
import frappe
from frappe.utils import flt
from frappe.model.document import Document

class SalesOrder(Document):
def validate(self):
total_weight = 0.0
for row in self.menu :
row.total=flt(row.rate_per_unit)*flt(row.quantity)
discount=row.total*row.discount/100
total_weight += row.total-discount
self.weight=total_weight
self.total=total_weight

Tuesday, 9 January 2018

How to set custom print format as default in frappe

Search Setup > click on custom form > put your print format name in set default print format and related doctype

how to add footer in frappe

<div id="footer-html" class="visible-pdf">
<hr>
        {% if not no_letterhead and footer %}
        <div class="letter-head-footer">
            {{ footer }}
        </div>
        {% endif %}
        <p class="text-center small page-number visible-pdf">
            {{ _("Page {0} of {1}").format('<span class="page"></span>', '<span class="topage"></span>') }}
        </p>
    </div>

How to get value in one doctype to other doctype in frappe

{{ frappe.db.get_value("Customer", doc.customer_ref,"customer_ref") or ''}}

Django rest api - filter

views.py from django_filters.rest_framework import DjangoFilterBackend class PollList(viewsets.ModelViewSet):     queryset = X.objects...