Erpnext: [Feature Request] Amend document without cancelling.

Created on 28 Nov 2017  路  18Comments  路  Source: frappe/erpnext

Amendment is a common day to day requirement, for updating existing document or correcting errors

Problem Faced under current scenario.

  • Sales order cannot be amended if part delivery is made or material request / purchase order is linked to it.
  • Reason for amendment or changes made in amendment cannot be seen or apprehended.
  • E-mail communication or comments trail is lost with cancelled documents.
  • Attachments under existing documents are required to be relinked / uploaded.
  • End reports are not accurate where amendment is not possible and short close of order is done. ( suppose if we look at quantity ordered in past, it would not reflect actual quantity)

Possible Solution
Following restructuring of documents could be done.

  • Amendment should be possible without cancelling document. Amended document should be part of original document with revised document name. ( Explanation : Like currently changes made to document before submitting.)
  • Additional validation to amended documents. Eg.

    • For sales order, Reducing qty should be restricted to quantity already delivered.

    • For delivery note/Sales Invoice, Amendment accounting entry for difference.

  • Links to other doctypes, emails and attachments of original document to be carried forward to amended document.
feature-request

All 18 comments

I understand that "amend" means to correct but I don't think it's proper to be able to amend a submitted document.

Hi,
I understand this is debatable.

My Concern is simple. Currently documents can be amended. But first they need to be cancelled (which cannot be done if it is linked to another existing document) and then amended, which results in creation of new document, and old trail gets lost.

Why to cancel in first place when ultimately it just needs to be amended?

Also, a lot of complexities exists in businesses, say,

  • Change terms of contract
  • Add charges
  • Change Shipping Address
  • Add extra items
  • Cancel particular items. etc.

This all may require to amend documents.

Finally, amending documents would surely be restricted to few users to avoid its misuse.

Hope I am able to justify...:-)

@snvora +1

For adding things like shipping costs, delivery costs, custom duties etc, remember that we have Landed Cost Voucher

Landed cost voucher is only applicable to Purchase Receipt / Purchase Invoice, and it is limited to additional charges.

With this feature scope would increase to a greater extent, including purchase/sales order, sales invoicing, etc.

Also Landed Cost voucher could be corrected for errors if any.... ;-)

@snvora +1

here the related discussion from the forum
https://discuss.erpnext.com/t/sales-order-amendment/31688

After the following changes in my own local development instance, I can change the submitted sales orders with following features:

  1. can add item
  2. can delete item with restriction: delivered item can not be deleted see implementation detail step 6
  3. can change quantity with restriction: quantity can not be less than delivered quantity, see implementation detail step 5

the implementation so far is far from complete, a lot of other features need to be considered, e.g
quantity can not be less than produced quantity, can not be less than ordered quantity, can not be less than returned quantity?
item can not be deleted if already partially or fully billed, it is associated with other linked documents?

anyone interested in this topic? let us push this feature to be implemented by the core team !

changes made

  1. change doctype: docfields to remove eval: parent.is_submittable from the depends on field
  2. change doctype: sales order, enable allow on submit for items(child table) and other item quantity based calculation fields such as total amount, total tax amount etc
  3. change doctype: sales order item, enable allow on submit for quantity, rate and all relevant calculated fields based on these basic fields
  4. change doctype: sales taxes and charges: enable allow on submit for amount field which are calculated based on item quantity
  5. in sales_order.py, update validate_for_items to do validation check to not allow change item quantity less change delivered quantity, add the validation check into event trigger before_update_after_submit which get called when update the submitted doc
    def validate_for_items(self):
    check_list = []
    for d in self.get('items'):
    check_list.append(cstr(d.item_code))
        # used for production plan
        d.transaction_date = self.transaction_date

        tot_avail_qty = frappe.db.sql("select projected_qty from `tabBin` \
            where item_code = %s and warehouse = %s", (d.item_code, d.warehouse))
        d.projected_qty = tot_avail_qty and flt(tot_avail_qty[0][0]) or 0
        if d.qty < d.delivered_qty:
            frappe.throw(_("Row #{0}: Quantity can not be less than Delivered quantity").format(d.idx))


    # check for same entry multiple times
    unique_chk_list = set(check_list)
    if len(unique_chk_list) != len(check_list) and \
        not cint(frappe.db.get_single_value("Selling Settings", "allow_multiple_items")):
        frappe.msgprint(_("Same item has been entered multiple times"),
            title=_("Warning"), indicator='orange')

def before_update_after_submit(self):
self.validate_po()
self.validate_drop_ship()
self.validate_supplier_after_submit()
self.validate_for_items()
self.update_delivery_status()
self.set_status()

  1. implement validation check to not allow deleting item when it is already delivered by PY and JS as following
    sales_order_item.py
    @frappe.whitelist()
    def check_item_delete(cdt, cdn):
    dn = frappe.db.sql_list("""select t1.name from tabDelivery Note t1,tabDelivery Note Item t2
    where t1.name = t2.parent and t2.so_detail = %s""", cdn)
    if dn:
    return "no_delete"
    frappe.ui.form.on("Sales Order Item", {
    before_items_remove: function(frm, dct, dcn){
    frappe.call({
    method: "erpnext.selling.doctype.sales_order_item.sales_order_item.check_item_delete",
    args: {
    cdt: dct,
    cdn: dcn
    },
    always: function(r){
    if(r.message.code == "no_delete"){
    frappe.throw(__("before _xx_remove You cannot delete this row, as there is linked object {0}.", [r.message.msg]))
    }
    }
    })
    }
    });

@szufisher Your efforts are really appreciable.

I thought about this. Maybe another way to implement this could be as follows

  • Amend feature to duplicate existing document (like it happens currently, but now it could happen without cancelling).
  • Additionally new document could be linked to all documents, attachments and email's to which original document is linked
  • Additional validations as you have worked will surely be required. (Already, there are fields of Qty delivered and billed within each item which need to be carried forward to duplicate document --> and then apply validations on them)
  • Status of old document changed to amended.

quantity can not be less than produced quantity, can not be less than ordered quantity, can not be less than returned quantity?

Well I feel that only compulsory validations should be considered (as you have correctly worked upon). Maybe warning for others (as quoted above) should suffice.

I feel this would help everyone a lot and I'd surely love to devote all help needed for this. I can't code, but I can definitely help in formulating logic.

+1

+1

+1

+1

+1

+10 :)

+100

+1000

+100

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GSLabIt picture GSLabIt  路  4Comments

heyakyra picture heyakyra  路  4Comments

alimalkhalifa picture alimalkhalifa  路  3Comments

raymondliew1992 picture raymondliew1992  路  4Comments

jboilesen picture jboilesen  路  3Comments