Changes for Recurring PO/PI

This commit is contained in:
Sambhaji Kolate 2014-09-10 13:07:59 +05:30
parent 6e566fb154
commit e3d2643f2b
8 changed files with 150 additions and 12 deletions

View File

@ -232,6 +232,42 @@ cur_frm.fields_dict['entries'].grid.get_field('project_name').get_query = functi
} }
} }
//added by sambhaji
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');
}
}
}
//end of added by sambhajii
cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
if(doc.select_print_heading){ if(doc.select_print_heading){

View File

@ -1,4 +1,5 @@
{ {
"allow_attach": 1,
"allow_import": 1, "allow_import": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-05-21 16:16:39", "creation": "2013-05-21 16:16:39",
@ -142,6 +143,24 @@
"reqd": 0, "reqd": 0,
"search_index": 1 "search_index": 1
}, },
{
"allow_on_submit": 1,
"description": "Start date of current invoice's period",
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From",
"no_copy": 1,
"permlevel": 0
},
{
"allow_on_submit": 1,
"description": "End date of current invoice's period",
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To",
"no_copy": 1,
"permlevel": 0
},
{ {
"fieldname": "amended_from", "fieldname": "amended_from",
"fieldtype": "Link", "fieldtype": "Link",

View File

@ -4,7 +4,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe 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 frappe import msgprint, _, throw
from erpnext.setup.utils import get_company_currency from erpnext.setup.utils import get_company_currency
@ -14,6 +17,8 @@ import frappe.defaults
from erpnext.controllers.buying_controller import BuyingController from erpnext.controllers.buying_controller import BuyingController
from erpnext.accounts.party import get_party_account, get_due_date from erpnext.accounts.party import get_party_account, get_due_date
from erpnext.controllers.recurring_document import *
form_grid_templates = { form_grid_templates = {
"entries": "templates/form_grid/item_grid.html" "entries": "templates/form_grid/item_grid.html"
} }
@ -61,6 +66,7 @@ class PurchaseInvoice(BuyingController):
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount", self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount",
"purchase_receipt_details") "purchase_receipt_details")
self.create_remarks() self.create_remarks()
validate_recurring_document(self)
def create_remarks(self): def create_remarks(self):
if not self.remarks: if not self.remarks:
@ -259,6 +265,11 @@ class PurchaseInvoice(BuyingController):
self.update_against_document_in_jv() self.update_against_document_in_jv()
self.update_prevdoc_status() self.update_prevdoc_status()
self.update_billing_status_for_zero_amount_refdoc("Purchase Order") self.update_billing_status_for_zero_amount_refdoc("Purchase Order")
convert_to_recurring(self, "RECINV.#####", self.posting_date)
def on_update_after_submit(self):
validate_recurring_document(self)
convert_to_recurring(self, "RECINV.#####", self.posting_date)
def make_gl_entries(self): def make_gl_entries(self):
auto_accounting_for_stock = \ auto_accounting_for_stock = \

View File

@ -205,7 +205,40 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
cur_frm.email_doc(frappe.boot.notification_settings.purchase_order_message); cur_frm.email_doc(frappe.boot.notification_settings.purchase_order_message);
} }
} }
//added by sambhaji
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');
}
}
}
//end of added by sambhaji
cur_frm.cscript.send_sms = function() { cur_frm.cscript.send_sms = function() {
frappe.require("assets/erpnext/js/sms_manager.js"); frappe.require("assets/erpnext/js/sms_manager.js");
var sms_man = new SMSManager(cur_frm.doc); var sms_man = new SMSManager(cur_frm.doc);

View File

@ -1,4 +1,5 @@
{ {
"allow_attach": 1,
"allow_import": 1, "allow_import": 1,
"autoname": "naming_series:", "autoname": "naming_series:",
"creation": "2013-05-21 16:16:39", "creation": "2013-05-21 16:16:39",
@ -101,6 +102,24 @@
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1
}, },
{
"allow_on_submit": 1,
"description": "Start date of current order's period",
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From",
"no_copy": 1,
"permlevel": 0
},
{
"allow_on_submit": 1,
"description": "End date of current order's period",
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To",
"no_copy": 1,
"permlevel": 0
},
{ {
"fieldname": "amended_from", "fieldname": "amended_from",
"fieldtype": "Link", "fieldtype": "Link",

View File

@ -6,6 +6,9 @@ import frappe
from frappe.utils import cstr, flt from frappe.utils import cstr, flt
from frappe import msgprint, _, throw from frappe import msgprint, _, throw
from frappe.model.mapper import get_mapped_doc 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 from erpnext.controllers.buying_controller import BuyingController
form_grid_templates = { form_grid_templates = {
@ -53,6 +56,8 @@ class PurchaseOrder(BuyingController):
self.validate_minimum_order_qty() self.validate_minimum_order_qty()
self.create_raw_materials_supplied("po_raw_material_details") self.create_raw_materials_supplied("po_raw_material_details")
validate_recurring_document(self)
def validate_with_previous_doc(self): def validate_with_previous_doc(self):
super(PurchaseOrder, self).validate_with_previous_doc(self.tname, { super(PurchaseOrder, self).validate_with_previous_doc(self.tname, {
"Supplier Quotation": { "Supplier Quotation": {
@ -174,6 +179,8 @@ class PurchaseOrder(BuyingController):
frappe.db.set(self,'status','Submitted') frappe.db.set(self,'status','Submitted')
convert_to_recurring(self, "SO/REC/.#####", self.transaction_date)
def on_cancel(self): def on_cancel(self):
pc_obj = frappe.get_doc('Purchase Common') pc_obj = frappe.get_doc('Purchase Common')
self.check_for_stopped_status(pc_obj) self.check_for_stopped_status(pc_obj)
@ -197,6 +204,10 @@ class PurchaseOrder(BuyingController):
def on_update(self): def on_update(self):
pass pass
def on_update_after_submit(self):
validate_recurring_document(self)
convert_to_recurring(self, "SO/REC/.#####", self.transaction_date)
def set_missing_values(source, target): def set_missing_values(source, target):
target.ignore_pricing_rule = 1 target.ignore_pricing_rule = 1
target.run_method("set_missing_values") target.run_method("set_missing_values")

View File

@ -107,6 +107,11 @@ class TestPurchaseOrder(unittest.TestCase):
po.get("po_details")[0].qty = 3.4 po.get("po_details")[0].qty = 3.4
self.assertRaises(UOMMustBeIntegerError, po.insert) 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"] test_dependencies = ["BOM"]

View File

@ -4,7 +4,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _, msgprint 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.setup.utils import get_company_currency
from erpnext.accounts.party import get_party_details from erpnext.accounts.party import get_party_details