Added Scaled Pricing Dialog to item

This commit is contained in:
2024-02-27 07:53:35 +00:00
parent 3664311505
commit 0d1cfdb88a
7 changed files with 142 additions and 17 deletions

View File

@@ -84,14 +84,4 @@ def print_label_by_server(doctype, name, qty, printer_setting, print_format=None
@frappe.whitelist() @frappe.whitelist()
def get_associated_stockentry(workorder): def get_associated_stockentry(workorder):
return frappe.get_last_doc('Stock Entry', filters={"work_order": workorder}) return frappe.get_last_doc('Stock Entry', filters={"work_order": workorder})
# @frappe.whitelist()
# def get_label_printers():
# label_printing_settings = frappe.get_doc('Label Printing Settings')
# label_printer_names = []
#
# for x in label_printing_settings.label_printers:
# label_printer_names.append(x.label_printer)
#
# return(label_printer_names)

View File

@@ -7,9 +7,6 @@ import json
def create_labels(values): def create_labels(values):
values = json.loads(values) values = json.loads(values)
print(values)
print(values["item_code"])
doc = frappe.new_doc('Label') doc = frappe.new_doc('Label')
doc.item_code = values["item_code"] doc.item_code = values["item_code"]
@@ -20,7 +17,6 @@ def create_labels(values):
ignore_if_duplicate=True, # dont insert if DuplicateEntryError is thrown ignore_if_duplicate=True, # dont insert if DuplicateEntryError is thrown
ignore_mandatory=True # insert even if mandatory fields are not set ignore_mandatory=True # insert even if mandatory fields are not set
) )
print(res)
# print_by_server("Label", "Label-00001", "labelprinter", "Labels") # print_by_server("Label", "Label-00001", "labelprinter", "Labels")
return 200 return 200

View File

@@ -1 +1,2 @@
Label Printing Label Printing
Scaled Pricing

View File

@@ -1 +1,2 @@
import './label_printing_desk'; import './label_printing_desk';
import './scaled_pricing';

View File

@@ -0,0 +1,90 @@
const table_fields = [
{
fieldname: "min_qty",
fieldtype: "Float",
in_list_view: 1,
label: "Min Qty",
mandatory: true
},
{
fieldname: "rate",
fieldtype: "Currency",
in_list_view: 1,
label: "Rate",
mandatory: true
},
{
fieldname: "priority",
fieldtype: "Int",
in_list_view: 1,
label: "Priority",
read_only: true
},
{
fieldname: "name",
fieldtype: "Link",
options: "Pricing Rule",
in_list_view: 1,
label: "Pricing Rule",
read_only: true
},
];
frappe.ui.form.on('Item', {
refresh(frm) {
frm.add_custom_button(__('Staggered Prices'), function () {
frappe.xcall('label_printing.scaled_pricing.scaled_pricing.get_price_lists', {
item_code: frm.doc.item_code
}).then((result) => {
generate_dialog(result, frm)
})
});
}
})
function generate_dialog(data, frm) {
let d = new frappe.ui.Dialog({
title: frm.doc.name,
fields: [
{
fieldname: "scaled_prices",
fieldtype: "Table",
label: "Scaled Prices",
cannot_add_rows: false,
in_place_edit: true,
reqd: 0,
data: data,
fields: table_fields,
},
],
size: 'large',
primary_action_label: 'Submit',
primary_action(values) {
if (values.scaled_prices.length > 20) {
frappe.throw(__('You can add a maximum of 20 Scaled Prices!'))
} else {
frappe.xcall('label_printing.scaled_pricing.scaled_pricing.change_price_lists', {
values: values,
frm: frm.doc.name
})
.then((result) => {
d.hide()
if (result === 200) {
frappe.show_alert({
message: __('Price Lists have been modified!'),
indicator: 'green'
}, 5);
d.hide();
} else {
frappe.throw(__("Couldn't change Pricelists!"))
}
})
}
}
});
d.show();
}

View File

@@ -0,0 +1,47 @@
import frappe
import json
@frappe.whitelist()
def get_price_lists(item_code):
pricing_rule_item_codes = frappe.db.get_all("Pricing Rule Item Code", filters={'item_code': item_code}, fields=["parent"])
pricing_rules = []
for item in pricing_rule_item_codes:
pricing_rule = frappe.get_doc('Pricing Rule', item.parent)
pricing_rules.append(pricing_rule)
return pricing_rules
@frappe.whitelist()
def change_price_lists(values, frm):
values = json.loads(values)
scaled_prices = values['scaled_prices']
scaled_prices = sorted(scaled_prices, key=lambda d: d['min_qty'])
for index, scaled_price in enumerate(scaled_prices):
doc = None
if frappe.db.exists('Pricing Rule', scaled_price["name"]):
doc = frappe.get_doc('Pricing Rule', scaled_price["name"])
else:
doc = frappe.new_doc('Pricing Rule')
doc.append("items", {
"item_code": frm,
"uom": "Stk"
})
doc.selling = 1
doc.min_qty = scaled_price["min_qty"]
doc.rate = scaled_price["rate"]
doc.title = "%s - %s" % (scaled_price["rate"], frm)
doc.priority = index + 1
doc.save()
return 200