[fix] recurring document logic

This commit is contained in:
Nabin Hait 2016-03-18 15:19:54 +05:30
parent 90ff509f6d
commit 5996b2f1bb
10 changed files with 36 additions and 51 deletions

View File

@ -2472,7 +2472,7 @@
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name",
@ -2692,7 +2692,7 @@
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"menu_index": 0, "menu_index": 0,
"modified": "2016-03-18 02:03:39.309675", "modified": "2016-03-18 13:13:43.694604",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Purchase Invoice", "name": "Purchase Invoice",

View File

@ -234,8 +234,6 @@ class PurchaseInvoice(BuyingController):
reconcile_against_document(lst) reconcile_against_document(lst)
def on_submit(self): def on_submit(self):
super(PurchaseInvoice, self).on_submit()
self.check_prev_docstatus() self.check_prev_docstatus()
frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype,

View File

@ -3171,7 +3171,7 @@
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name",
@ -3418,7 +3418,7 @@
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"menu_index": 0, "menu_index": 0,
"modified": "2016-03-18 02:03:34.511447", "modified": "2016-03-18 13:12:12.430038",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice", "name": "Sales Invoice",

View File

@ -81,8 +81,6 @@ class SalesInvoice(SellingController):
self.update_packing_list() self.update_packing_list()
def on_submit(self): def on_submit(self):
super(SalesInvoice, self).on_submit()
if cint(self.update_stock) == 1: if cint(self.update_stock) == 1:
self.update_stock_ledger() self.update_stock_ledger()
else: else:
@ -473,7 +471,7 @@ class SalesInvoice(SellingController):
frappe.db.set(self,'paid_amount',0) 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"))) flt(self.paid_amount*self.conversion_rate, self.precision("base_paid_amount")))
def check_prev_docstatus(self): def check_prev_docstatus(self):
for d in self.get('items'): for d in self.get('items'):

View File

@ -2474,7 +2474,7 @@
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name",
@ -2693,7 +2693,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-03-18 02:03:28.445402", "modified": "2016-03-18 13:13:07.334625",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Buying", "module": "Buying",
"name": "Purchase Order", "name": "Purchase Order",

View File

@ -171,8 +171,6 @@ class PurchaseOrder(BuyingController):
if self.is_against_so(): if self.is_against_so():
self.update_status_updater() self.update_status_updater()
super(PurchaseOrder, self).on_submit()
purchase_controller = frappe.get_doc("Purchase Common") purchase_controller = frappe.get_doc("Purchase Common")
self.update_prevdoc_status() self.update_prevdoc_status()

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _, throw from frappe import _, throw
from frappe.utils import today, flt, cint, fmt_money, getdate from frappe.utils import today, flt, cint, fmt_money
from erpnext.setup.utils import get_company_currency, get_exchange_rate from erpnext.setup.utils import get_company_currency, get_exchange_rate
from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year, get_account_currency from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year, get_account_currency
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
@ -31,9 +31,6 @@ class AccountsController(TransactionBase):
self.set_missing_values(for_validate=True) self.set_missing_values(for_validate=True)
self.validate_date_with_fiscal_year() self.validate_date_with_fiscal_year()
if self.meta.get_field('next_date') and self.next_date:
self.validate_recurring_next_date()
if self.meta.get_field("currency"): if self.meta.get_field("currency"):
self.calculate_taxes_and_totals() self.calculate_taxes_and_totals()
if not self.meta.get_field("is_return") or not self.is_return: if not self.meta.get_field("is_return") or not self.is_return:
@ -45,17 +42,14 @@ class AccountsController(TransactionBase):
if self.doctype in ("Sales Invoice", "Purchase Invoice") and not self.is_return: if self.doctype in ("Sales Invoice", "Purchase Invoice") and not self.is_return:
self.validate_due_date() self.validate_due_date()
if self.meta.get_field("is_recurring"):
validate_recurring_document(self)
if self.meta.get_field("taxes_and_charges"): if self.meta.get_field("taxes_and_charges"):
self.validate_enabled_taxes_and_charges() self.validate_enabled_taxes_and_charges()
self.validate_party() self.validate_party()
self.validate_currency() self.validate_currency()
def on_submit(self): if self.meta.get_field("is_recurring") and not self.get("__islocal"):
if self.meta.get_field("is_recurring"): validate_recurring_document(self)
convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date")) convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date"))
def on_update_after_submit(self): def on_update_after_submit(self):
@ -91,14 +85,6 @@ class AccountsController(TransactionBase):
validate_fiscal_year(self.get(date_field), self.fiscal_year, validate_fiscal_year(self.get(date_field), self.fiscal_year,
self.meta.get_label(date_field), self) self.meta.get_label(date_field), self)
def validate_recurring_next_date(self):
posting_date = self.get("posting_date") or self.get("transaction_date")
if getdate(posting_date) > getdate(self.next_date):
frappe.throw(_("Next Date must be greater than Posting Date"))
if getdate(self.next_date).day != self.repeat_on_day_of_month:
frappe.throw(_("Next Date's day and Repeat on Day of Month must be equal"))
def validate_due_date(self): def validate_due_date(self):
from erpnext.accounts.party import validate_due_date from erpnext.accounts.party import validate_due_date
if self.doctype == "Sales Invoice": if self.doctype == "Sales Invoice":

View File

@ -108,6 +108,7 @@ def make_new_document(reference_doc, date_field, posting_date):
new_document.run_method("on_recurring", reference_doc=reference_doc) new_document.run_method("on_recurring", reference_doc=reference_doc)
if reference_doc.submit_on_creation: if reference_doc.submit_on_creation:
new_document.insert()
new_document.submit() new_document.submit()
else: else:
new_document.docstatus=0 new_document.docstatus=0
@ -160,26 +161,33 @@ def assign_task_to_owner(doc, doctype, msg, users):
def validate_recurring_document(doc): def validate_recurring_document(doc):
if doc.is_recurring: if doc.is_recurring:
validate_notification_email_id(doc) validate_notification_email_id(doc)
if not doc.recurring_id and not doc.is_new():
doc.recurring_id = doc.name
if not doc.recurring_type: if not doc.recurring_type:
msgprint(_("Please select {0}").format(doc.meta.get_label("recurring_type")), frappe.throw(_("Please select {0}").format(doc.meta.get_label("recurring_type")))
raise_exception=1)
elif not (doc.from_date and doc.to_date): elif not (doc.from_date and doc.to_date):
throw(_("Period From and Period To dates mandatory for recurring {0}").format(doc.doctype)) frappe.throw(_("Period From and Period To dates mandatory for recurring {0}").format(doc.doctype))
def validate_recurring_next_date(doc):
posting_date = doc.get("posting_date") or doc.get("transaction_date")
if getdate(posting_date) > getdate(doc.next_date):
frappe.throw(_("Next Date must be greater than Posting Date"))
if getdate(doc.next_date).day != doc.repeat_on_day_of_month:
frappe.throw(_("Next Date's day and Repeat on Day of Month must be equal"))
#
def convert_to_recurring(doc, posting_date): def convert_to_recurring(doc, posting_date):
if doc.is_recurring: if doc.is_recurring:
set_next_date(doc, posting_date) if not doc.recurring_id:
doc.db_set("recurring_id", doc.name)
elif doc.recurring_id: set_next_date(doc, posting_date)
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))
if doc.next_date:
validate_recurring_next_date(doc)
def validate_notification_email_id(doc): def validate_notification_email_id(doc):
if doc.notify_by_email: if doc.notify_by_email:
@ -198,13 +206,12 @@ def validate_notification_email_id(doc):
def set_next_date(doc, posting_date): def set_next_date(doc, posting_date):
""" Set next date on which recurring document will be created""" """ Set next date on which recurring document will be created"""
if not doc.repeat_on_day_of_month: if not doc.repeat_on_day_of_month:
msgprint(_("Please enter 'Repeat on Day of Month' field value"), raise_exception=1) msgprint(_("Please enter 'Repeat on Day of Month' field value"), raise_exception=1)
next_date = get_next_date(posting_date, month_map[doc.recurring_type], next_date = get_next_date(posting_date, month_map[doc.recurring_type],
cint(doc.repeat_on_day_of_month)) cint(doc.repeat_on_day_of_month))
frappe.db.set(doc, 'next_date', next_date) doc.db_set('next_date', next_date)
msgprint(_("Next Recurring {0} will be created on {1}").format(doc.doctype, next_date)) msgprint(_("Next Recurring {0} will be created on {1}").format(doc.doctype, next_date))

View File

@ -2799,7 +2799,7 @@
"unique": 0 "unique": 0
}, },
{ {
"allow_on_submit": 0, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name", "depends_on": "eval:doc.is_recurring && doc.recurring_id === doc.name",
@ -3018,7 +3018,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-03-18 02:03:43.706326", "modified": "2016-03-18 13:11:32.654873",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Sales Order", "name": "Sales Order",

View File

@ -150,8 +150,6 @@ class SalesOrder(SellingController):
frappe.throw(_("Row #{0}: Set Supplier for item {1}").format(d.idx, d.item_code)) frappe.throw(_("Row #{0}: Set Supplier for item {1}").format(d.idx, d.item_code))
def on_submit(self): def on_submit(self):
super(SalesOrder, self).on_submit()
self.check_credit_limit() self.check_credit_limit()
self.update_reserved_qty() self.update_reserved_qty()