Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(delivery): add cutoff item date for so delivery items #38561

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions erpnext/public/js/bulk_transaction_processing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
frappe.provide("erpnext.bulk_transaction_processing");

$.extend(erpnext.bulk_transaction_processing, {
create: function(listview, from_doctype, to_doctype) {
create: function(listview, from_doctype, to_doctype, args) {
let checked_items = listview.get_checked_items();
const doc_name = [];
checked_items.forEach((Item)=> {
Expand All @@ -15,7 +15,7 @@ $.extend(erpnext.bulk_transaction_processing, {
if (doc_name.length == 0) {
frappe.call({
method: "erpnext.utilities.bulk_transaction.transaction_processing",
args: {data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype}
args: {data: checked_items, from_doctype: from_doctype, to_doctype: to_doctype, args: args}
}).then(()=> {

});
Expand Down
8 changes: 7 additions & 1 deletion erpnext/selling/doctype/sales_order/sales_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,8 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
var delivery_dates = this.frm.doc.items.map(i => i.delivery_date);
delivery_dates = [ ...new Set(delivery_dates) ];

var today = new Date();

var item_grid = this.frm.fields_dict["items"].grid;
if(!item_grid.get_selected().length && delivery_dates.length > 1) {
var dialog = new frappe.ui.Dialog({
Expand All @@ -873,7 +875,11 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
<div class="list-item">
<div class="list-item__content list-item__content--flex-2">
<label>
<input type="checkbox" data-date="${date}" checked="checked"/>
<input
type="checkbox"
data-date="${date}"
${frappe.datetime.get_day_diff(new Date(date), today) > 0 ? "" : 'checked="checked"'}
/>
${frappe.datetime.str_to_user(date)}
</label>
</div>
Expand Down
8 changes: 8 additions & 0 deletions erpnext/selling/doctype/sales_order/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,9 @@ def condition(doc):
if frappe.flags.args and frappe.flags.args.delivery_dates:
if cstr(doc.delivery_date) not in frappe.flags.args.delivery_dates:
return False
if frappe.flags.args and frappe.flags.args.until_delivery_date:
if cstr(doc.delivery_date) > frappe.flags.args.until_delivery_date:
return False

return abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier != 1

Expand Down Expand Up @@ -1007,6 +1010,11 @@ def update_dn_item(source, target, source_parent):
for idx, item in enumerate(target_doc.items):
item.idx = idx + 1

if not kwargs.skip_item_mapping and frappe.flags.bulk_transaction and not target_doc.items:
# the (date) condition filter resulted in an unintendedly created empty DN; remove it
del target_doc
return

# Should be called after mapping items.
set_missing_values(so, target_doc)

Expand Down
19 changes: 18 additions & 1 deletion erpnext/selling/doctype/sales_order/sales_order_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,24 @@ frappe.listview_settings['Sales Order'] = {
});

listview.page.add_action_item(__("Delivery Note"), ()=>{
erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Delivery Note");
frappe.db.get_single_value("Selling Settings", "enable_cutoff_date_on_bulk_delivery_note_creation").then((value) => {
if (value) {
var dialog = new frappe.ui.Dialog({
title: __("Select Items up to Delivery Date"),
fields: [{fieldtype: "Date", fieldname: "delivery_date", default: frappe.datetime.add_days(frappe.datetime.nowdate(), 1)}]
});
dialog.set_primary_action(__("Select"), function(values) {
var until_delivery_date = values.delivery_date;
erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Delivery Note", {
until_delivery_date
});
dialog.hide();
});
dialog.show();
} else {
erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Delivery Note");
}
})
});

listview.page.add_action_item(__("Advance Payment"), ()=>{
Expand Down
11 changes: 9 additions & 2 deletions erpnext/selling/doctype/selling_settings/selling_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"allow_sales_order_creation_for_expired_quotation",
"dont_reserve_sales_order_qty_on_sales_return",
"hide_tax_id",
"enable_discount_accounting"
"enable_discount_accounting",
"enable_cutoff_date_on_bulk_delivery_note_creation"
],
"fields": [
{
Expand Down Expand Up @@ -200,14 +201,20 @@
"fieldname": "blanket_order_allowance",
"fieldtype": "Float",
"label": "Blanket Order Allowance (%)"
},
{
"default": "0",
"fieldname": "enable_cutoff_date_on_bulk_delivery_note_creation",
"fieldtype": "Check",
"label": "Enable Cut-Off Date on Bulk Delivery Note Creation"
}
],
"icon": "fa fa-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-10-25 14:03:03.966701",
"modified": "2024-03-01 12:07:39.994520",
"modified_by": "Administrator",
"module": "Selling",
"name": "Selling Settings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SellingSettings(Document):
dont_reserve_sales_order_qty_on_sales_return: DF.Check
editable_bundle_item_rates: DF.Check
editable_price_list_rate: DF.Check
enable_cutoff_date_on_bulk_delivery_note_creation: DF.Check
enable_discount_accounting: DF.Check
hide_tax_id: DF.Check
maintain_same_rate_action: DF.Literal["Stop", "Warn"]
Expand Down
22 changes: 17 additions & 5 deletions erpnext/utilities/bulk_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@


@frappe.whitelist()
def transaction_processing(data, from_doctype, to_doctype):
def transaction_processing(data, from_doctype, to_doctype, args=None):
if isinstance(data, str):
deserialized_data = json.loads(data)
else:
deserialized_data = data

if isinstance(args, str):
args = frappe._dict(json.loads(args))

length_of_data = len(deserialized_data)

frappe.msgprint(
Expand All @@ -23,6 +26,7 @@ def transaction_processing(data, from_doctype, to_doctype):
deserialized_data=deserialized_data,
from_doctype=from_doctype,
to_doctype=to_doctype,
args=args,
)


Expand Down Expand Up @@ -71,8 +75,13 @@ def update_log(log_name, status, retried, err=None):
frappe.db.set_value("Bulk Transaction Log Detail", log_name, "error_description", err)


def job(deserialized_data, from_doctype, to_doctype):
def job(deserialized_data, from_doctype, to_doctype, args):
fail_count = 0

if args:
# currently: flag-based transport to `task`
frappe.flags.args = args

for d in deserialized_data:
try:
doc_name = d.get("name")
Expand Down Expand Up @@ -147,9 +156,12 @@ def task(doc_name, from_doctype, to_doctype):
else:
obj = mapper[from_doctype][to_doctype](doc_name)

obj.flags.ignore_validate = True
obj.set_title_field()
obj.insert(ignore_mandatory=True)
if obj:
obj.flags.ignore_validate = True
obj.set_title_field()
obj.insert(ignore_mandatory=True)

del obj
del frappe.flags.bulk_transaction


Expand Down
Loading