Skip to content
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
11 changes: 10 additions & 1 deletion posnext/doc_events/pos_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
def validate_pf(doc,method):
if not doc.custom_edit_rate_and_uom:
doc.custom_use_discount_percentage = 0
doc.custom_use_discount_amount = 0
doc.custom_use_discount_amount = 0


@frappe.whitelist()
def get_pos_profile_branch(pos_profile_name):
if not pos_profile_name:
frappe.throw("POS Profile name is required.")

branch = frappe.db.get_value("POS Profile", pos_profile_name, "branch")
return {"branch": branch}
59 changes: 39 additions & 20 deletions posnext/public/js/pos_item_cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,32 +523,51 @@ this.highlight_checkout_btn(true);
});

this.$component.on('click', '.add-branch-wrapper', function () {
const $wrapper = $(this); // Store reference to the clicked element
const $wrapper = $(this);
const posProfileName = me.settings.name;
console.log("POS Profile:", posProfileName);

// Create a div container for the link field
const branchFieldWrapper = $('<div class="branch-field"></div>');

// Replace the wrapper with the new div
$wrapper.replaceWith(branchFieldWrapper);

// Create a Frappe Link Field dynamically
let branchField = new frappe.ui.form.ControlLink({
df: {
fieldtype: 'Link',
options: 'Branch', // Link to Branch Doctype
fieldname: 'branch',
label: 'Branch',
placeholder: 'Select Branch',
frappe.call({
method: "posnext.doc_events.pos_profile.get_pos_profile_branch",
args: {
pos_profile_name: posProfileName
},
parent: branchFieldWrapper, // Append inside the same container
value: '',
change: function (value) {
console.log('Selected Branch:', value);
}
});
callback: function (r) {
const branch_name = r.message && r.message.branch;

console.log(branch_name)


if (!branch_name) {
frappe.msgprint(__('Create Branch Accounting Dimensions'));
return;
}

// Render the field
branchField.refresh();

let branchField = new frappe.ui.form.ControlLink({
df: {
fieldtype: 'Link',
options: 'Branch',
fieldname: 'branch',
label: 'Branch',
placeholder: 'Select Branch',
default: branch_name,
reqd: 1,
get_query: () => ({
filters: { disabled: 0 }
})
},
parent: branchFieldWrapper
});

branchField.make();
branchField.set_value(branch_name);
branchField.refresh();
},
});
});

frappe.ui.form.on("Sales Invoice", "paid_amount", frm => {
Expand Down
Loading