Merge branch 'develop' of https://github.com/sbkolate/erpnext into sbkolate-develop
This commit is contained in:
commit
8370cb3e71
@ -233,6 +233,41 @@ cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = functi
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.cscript.is_recurring = function(doc, dt, dn) {
|
||||
// set default values for recurring invoices
|
||||
if(doc.is_recurring) {
|
||||
var owner_email = doc.owner=="Administrator"
|
||||
? frappe.user_info("Administrator").email
|
||||
: doc.owner;
|
||||
|
||||
doc.notification_email_address = $.map([cstr(owner_email),
|
||||
cstr(doc.contact_email)], function(v) { return v || null; }).join(", ");
|
||||
doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(doc.posting_date).getDate();
|
||||
}
|
||||
|
||||
refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.from_date = function(doc, dt, dn) {
|
||||
// set to_date
|
||||
if(doc.from_date) {
|
||||
var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
|
||||
'Yearly': 12};
|
||||
|
||||
var months = recurring_type_map[doc.recurring_type];
|
||||
if(months) {
|
||||
var to_date = frappe.datetime.add_months(doc.from_date,
|
||||
months);
|
||||
doc.to_date = frappe.datetime.add_days(to_date, -1);
|
||||
refresh_field('to_date');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
|
||||
if(doc.select_print_heading){
|
||||
// print heading
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,10 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
from frappe.utils import cint, cstr, flt, formatdate
|
||||
|
||||
from frappe.utils import add_days, cint, cstr, date_diff, formatdate, flt, getdate, nowdate, \
|
||||
get_first_day, get_last_day
|
||||
from frappe.model.naming import make_autoname
|
||||
|
||||
from frappe import msgprint, _, throw
|
||||
from erpnext.setup.utils import get_company_currency
|
||||
@ -14,6 +17,8 @@ import frappe.defaults
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
from erpnext.accounts.party import get_party_account, get_due_date
|
||||
|
||||
from erpnext.controllers.recurring_document import *
|
||||
|
||||
form_grid_templates = {
|
||||
"entries": "templates/form_grid/item_grid.html"
|
||||
}
|
||||
@ -61,6 +66,7 @@ class PurchaseInvoice(BuyingController):
|
||||
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount",
|
||||
"purchase_receipt_details")
|
||||
self.create_remarks()
|
||||
validate_recurring_document(self)
|
||||
|
||||
def create_remarks(self):
|
||||
if not self.remarks:
|
||||
@ -259,6 +265,11 @@ class PurchaseInvoice(BuyingController):
|
||||
self.update_against_document_in_jv()
|
||||
self.update_prevdoc_status()
|
||||
self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
|
||||
convert_to_recurring(self, self.posting_date)
|
||||
|
||||
def on_update_after_submit(self):
|
||||
validate_recurring_document(self)
|
||||
convert_to_recurring(self, self.posting_date)
|
||||
|
||||
def make_gl_entries(self):
|
||||
auto_accounting_for_stock = \
|
||||
|
@ -104,7 +104,7 @@ class SalesInvoice(SellingController):
|
||||
self.update_against_document_in_jv()
|
||||
|
||||
self.update_time_log_batch(self.name)
|
||||
convert_to_recurring(self, "RECINV.#####", self.posting_date)
|
||||
convert_to_recurring(self, self.posting_date)
|
||||
|
||||
def before_cancel(self):
|
||||
self.update_time_log_batch(None)
|
||||
@ -147,7 +147,7 @@ class SalesInvoice(SellingController):
|
||||
|
||||
def on_update_after_submit(self):
|
||||
validate_recurring_document(self)
|
||||
convert_to_recurring(self, "RECINV.#####", self.posting_date)
|
||||
convert_to_recurring(self, self.posting_date)
|
||||
|
||||
def before_recurring(self):
|
||||
self.aging_date = None
|
||||
|
@ -206,6 +206,39 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.is_recurring = function(doc, dt, dn) {
|
||||
// set default values for recurring orders
|
||||
if(doc.is_recurring) {
|
||||
var owner_email = doc.owner=="Administrator"
|
||||
? frappe.user_info("Administrator").email
|
||||
: doc.owner;
|
||||
|
||||
doc.notification_email_address = $.map([cstr(owner_email),
|
||||
cstr(doc.contact_email)], function(v) { return v || null; }).join(", ");
|
||||
doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(doc.posting_date).getDate();
|
||||
}
|
||||
|
||||
refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
|
||||
}
|
||||
|
||||
cur_frm.cscript.from_date = function(doc, dt, dn) {
|
||||
// set to_date
|
||||
if(doc.from_date) {
|
||||
var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
|
||||
'Yearly': 12};
|
||||
|
||||
var months = recurring_type_map[doc.recurring_type];
|
||||
if(months) {
|
||||
var to_date = frappe.datetime.add_months(doc.from_date,
|
||||
months);
|
||||
doc.to_date = frappe.datetime.add_days(to_date, -1);
|
||||
refresh_field('to_date');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.send_sms = function() {
|
||||
frappe.require("assets/erpnext/js/sms_manager.js");
|
||||
var sms_man = new SMSManager(cur_frm.doc);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,9 @@ import frappe
|
||||
from frappe.utils import cstr, flt
|
||||
from frappe import msgprint, _, throw
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
from erpnext.controllers.recurring_document import convert_to_recurring, validate_recurring_document
|
||||
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
|
||||
form_grid_templates = {
|
||||
@ -52,6 +55,8 @@ class PurchaseOrder(BuyingController):
|
||||
self.validate_for_subcontracting()
|
||||
self.validate_minimum_order_qty()
|
||||
self.create_raw_materials_supplied("po_raw_material_details")
|
||||
|
||||
validate_recurring_document(self)
|
||||
|
||||
def validate_with_previous_doc(self):
|
||||
super(PurchaseOrder, self).validate_with_previous_doc(self.tname, {
|
||||
@ -173,6 +178,8 @@ class PurchaseOrder(BuyingController):
|
||||
purchase_controller.update_last_purchase_rate(self, is_submit = 1)
|
||||
|
||||
frappe.db.set(self,'status','Submitted')
|
||||
|
||||
convert_to_recurring(self, self.transaction_date)
|
||||
|
||||
def on_cancel(self):
|
||||
pc_obj = frappe.get_doc('Purchase Common')
|
||||
@ -197,6 +204,10 @@ class PurchaseOrder(BuyingController):
|
||||
def on_update(self):
|
||||
pass
|
||||
|
||||
def on_update_after_submit(self):
|
||||
validate_recurring_document(self)
|
||||
convert_to_recurring(self, self.transaction_date)
|
||||
|
||||
def set_missing_values(source, target):
|
||||
target.ignore_pricing_rule = 1
|
||||
target.run_method("set_missing_values")
|
||||
|
@ -107,6 +107,11 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
po.get("po_details")[0].qty = 3.4
|
||||
self.assertRaises(UOMMustBeIntegerError, po.insert)
|
||||
|
||||
def test_recurring_order(self):
|
||||
from erpnext.controllers.tests.test_recurring_document import test_recurring_document
|
||||
|
||||
test_recurring_document(self, test_records)
|
||||
|
||||
|
||||
test_dependencies = ["BOM"]
|
||||
|
||||
|
@ -4,7 +4,11 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import _, msgprint
|
||||
from frappe.utils import flt, rounded
|
||||
|
||||
from frappe.utils import add_days, cint, cstr, today, date_diff, flt, rounded, getdate, nowdate, \
|
||||
get_first_day, get_last_day
|
||||
from frappe.model.naming import make_autoname
|
||||
|
||||
from erpnext.setup.utils import get_company_currency
|
||||
from erpnext.accounts.party import get_party_details
|
||||
|
||||
|
@ -2,15 +2,22 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
import frappe.utils
|
||||
import frappe.defaults
|
||||
from frappe.utils import cint, cstr, getdate, nowdate, get_first_day, get_last_day
|
||||
|
||||
from frappe.utils import add_days, cint, cstr, date_diff, flt, getdate, nowdate, \
|
||||
get_first_day, get_last_day, comma_and
|
||||
from frappe.model.naming import make_autoname
|
||||
|
||||
from frappe import _, msgprint, throw
|
||||
from erpnext.accounts.party import get_party_account, get_due_date, get_party_details
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
month_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12}
|
||||
|
||||
def create_recurring_documents():
|
||||
manage_recurring_documents("Sales Order")
|
||||
manage_recurring_documents("Sales Invoice")
|
||||
manage_recurring_documents("Purchase Order")
|
||||
manage_recurring_documents("Purchase Invoice")
|
||||
|
||||
def manage_recurring_documents(doctype, next_date=None, commit=True):
|
||||
"""
|
||||
@ -23,6 +30,10 @@ def manage_recurring_documents(doctype, next_date=None, commit=True):
|
||||
date_field = "transaction_date"
|
||||
elif doctype == "Sales Invoice":
|
||||
date_field = "posting_date"
|
||||
elif doctype == "Purchase Order":
|
||||
date_field = "transaction_date"
|
||||
elif doctype == "Purchase Invoice":
|
||||
date_field = "posting_date"
|
||||
|
||||
recurring_documents = frappe.db.sql("""select name, recurring_id
|
||||
from `tab{}` where ifnull(is_recurring, 0)=1
|
||||
@ -49,7 +60,7 @@ def manage_recurring_documents(doctype, next_date=None, commit=True):
|
||||
|
||||
frappe.db.begin()
|
||||
frappe.db.sql("update `tab%s` \
|
||||
set is_recurring = 0 where name = %s" % (doctype, '%s'),
|
||||
set is_recurring = 0 where name = %s" % (doctype, '%s'),
|
||||
(ref_document))
|
||||
notify_errors(ref_document, doctype, ref_wrapper.customer, ref_wrapper.owner)
|
||||
frappe.db.commit()
|
||||
@ -155,18 +166,18 @@ def validate_recurring_document(doc):
|
||||
elif not (doc.from_date and doc.to_date):
|
||||
throw(_("Period From and Period To dates mandatory for recurring %s") % doc.doctype)
|
||||
|
||||
def convert_to_recurring(doc, autoname, posting_date):
|
||||
if doc.is_recurring:
|
||||
if not doc.recurring_id:
|
||||
frappe.db.set(doc, "recurring_id",
|
||||
make_autoname(autoname))
|
||||
#
|
||||
def convert_to_recurring(doc, posting_date):
|
||||
if doc.is_recurring:
|
||||
if not doc.recurring_id:
|
||||
frappe.db.set(doc, "recurring_id", doc.name)
|
||||
|
||||
set_next_date(doc, posting_date)
|
||||
set_next_date(doc, posting_date)
|
||||
|
||||
elif doc.recurring_id:
|
||||
frappe.db.sql("""update `tab%s`
|
||||
set is_recurring = 0
|
||||
where recurring_id = %s""" % (doc.doctype, '%s'), (doc.recurring_id))
|
||||
elif doc.recurring_id:
|
||||
frappe.db.sql("""update `tab%s` set is_recurring = 0
|
||||
where recurring_id = %s""" % (doc.doctype, '%s'), (doc.recurring_id))
|
||||
#
|
||||
|
||||
def validate_notification_email_id(doc):
|
||||
if doc.notification_email_address:
|
||||
|
@ -41,6 +41,20 @@ def test_recurring_document(obj, test_records):
|
||||
date_field = "transaction_date"
|
||||
elif base_doc.doctype == "Sales Invoice":
|
||||
date_field = "posting_date"
|
||||
#for Purchase order/purchase invoice
|
||||
if base_doc.doctype == "Purchase Order":
|
||||
base_doc.update({
|
||||
"transaction_date": today
|
||||
})
|
||||
elif base_doc.doctype == "Purchase Invoice":
|
||||
base_doc.update({
|
||||
"posting_date": today
|
||||
})
|
||||
|
||||
if base_doc.doctype == "Purchase Order":
|
||||
date_field = "transaction_date"
|
||||
elif base_doc.doctype == "Purchase Invoice":
|
||||
date_field = "posting_date"
|
||||
|
||||
# monthly
|
||||
doc1 = frappe.copy_doc(base_doc)
|
||||
|
@ -166,7 +166,7 @@ class SalesOrder(SellingController):
|
||||
self.update_prevdoc_status('submit')
|
||||
frappe.db.set(self, 'status', 'Submitted')
|
||||
|
||||
convert_to_recurring(self, "SO/REC/.#####", self.transaction_date)
|
||||
convert_to_recurring(self, self.transaction_date)
|
||||
|
||||
def on_cancel(self):
|
||||
# Cannot cancel stopped SO
|
||||
@ -257,7 +257,7 @@ class SalesOrder(SellingController):
|
||||
|
||||
def on_update_after_submit(self):
|
||||
validate_recurring_document(self)
|
||||
convert_to_recurring(self, "SO/REC/.#####", self.transaction_date)
|
||||
convert_to_recurring(self, self.transaction_date)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
Loading…
x
Reference in New Issue
Block a user