Browse Source

[fix] recurring document logic

develop
Nabin Hait 9 years ago
parent
commit
5996b2f1bb
  1. 4
      erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
  2. 2
      erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
  3. 4
      erpnext/accounts/doctype/sales_invoice/sales_invoice.json
  4. 4
      erpnext/accounts/doctype/sales_invoice/sales_invoice.py
  5. 4
      erpnext/buying/doctype/purchase_order/purchase_order.json
  6. 2
      erpnext/buying/doctype/purchase_order/purchase_order.py
  7. 22
      erpnext/controllers/accounts_controller.py
  8. 39
      erpnext/controllers/recurring_document.py
  9. 4
      erpnext/selling/doctype/sales_order/sales_order.json
  10. 2
      erpnext/selling/doctype/sales_order/sales_order.py

4
erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json

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

2
erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

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

4
erpnext/accounts/doctype/sales_invoice/sales_invoice.json

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

4
erpnext/accounts/doctype/sales_invoice/sales_invoice.py

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

4
erpnext/buying/doctype/purchase_order/purchase_order.json

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

2
erpnext/buying/doctype/purchase_order/purchase_order.py

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

22
erpnext/controllers/accounts_controller.py

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
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.accounts.utils import get_fiscal_year, validate_fiscal_year, get_account_currency
from erpnext.utilities.transaction_base import TransactionBase
@ -31,9 +31,6 @@ class AccountsController(TransactionBase):
self.set_missing_values(for_validate=True)
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"):
self.calculate_taxes_and_totals()
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:
self.validate_due_date()
if self.meta.get_field("is_recurring"):
validate_recurring_document(self)
if self.meta.get_field("taxes_and_charges"):
self.validate_enabled_taxes_and_charges()
self.validate_party()
self.validate_currency()
def on_submit(self):
if self.meta.get_field("is_recurring"):
if self.meta.get_field("is_recurring") and not self.get("__islocal"):
validate_recurring_document(self)
convert_to_recurring(self, self.get("posting_date") or self.get("transaction_date"))
def on_update_after_submit(self):
@ -91,14 +85,6 @@ class AccountsController(TransactionBase):
validate_fiscal_year(self.get(date_field), self.fiscal_year,
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):
from erpnext.accounts.party import validate_due_date
if self.doctype == "Sales Invoice":

39
erpnext/controllers/recurring_document.py

@ -108,6 +108,7 @@ def make_new_document(reference_doc, date_field, posting_date):
new_document.run_method("on_recurring", reference_doc=reference_doc)
if reference_doc.submit_on_creation:
new_document.insert()
new_document.submit()
else:
new_document.docstatus=0
@ -160,26 +161,33 @@ def assign_task_to_owner(doc, doctype, msg, users):
def validate_recurring_document(doc):
if doc.is_recurring:
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:
msgprint(_("Please select {0}").format(doc.meta.get_label("recurring_type")),
raise_exception=1)
frappe.throw(_("Please select {0}").format(doc.meta.get_label("recurring_type")))
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):
if doc.is_recurring:
set_next_date(doc, posting_date)
if doc.is_recurring:
if not doc.recurring_id:
doc.db_set("recurring_id", doc.name)
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))
if doc.next_date:
validate_recurring_next_date(doc)
def validate_notification_email_id(doc):
if doc.notify_by_email:
@ -198,13 +206,12 @@ def validate_notification_email_id(doc):
def set_next_date(doc, posting_date):
""" Set next date on which recurring document will be created"""
if not doc.repeat_on_day_of_month:
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],
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))

4
erpnext/selling/doctype/sales_order/sales_order.json

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

2
erpnext/selling/doctype/sales_order/sales_order.py

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

Loading…
Cancel
Save