Skip to content

Commit

Permalink
add categories in pos and allow stripe cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
bvisible committed Sep 15, 2023
1 parent 3c2b227 commit 0406238
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 4 deletions.
47 changes: 47 additions & 0 deletions erpnext/selling/page/point_of_sale/point_of_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,50 @@ def get_pos_profile_data(pos_profile):

pos_profile.customer_groups = _customer_groups_with_children
return pos_profile

#////
@frappe.whitelist()
def has_items(item_group, pos_profile):
warehouse, hide_unavailable_items, company = frappe.db.get_value( #////
"POS Profile", pos_profile, ["warehouse", "hide_unavailable_items", "company"] #////
)

if not frappe.db.exists("Item Group", item_group):
item_group = get_root_of("Item Group")

condition = get_item_group_condition(pos_profile)

lft, rgt = frappe.db.get_value("Item Group", item_group, ["lft", "rgt"])

bin_join_selection, bin_join_condition = "", ""
if hide_unavailable_items:
bin_join_selection = ", `tabBin` bin"
bin_join_condition = (
"AND bin.warehouse = %(warehouse)s AND bin.item_code = item.name AND bin.actual_qty > 0"
)

item_count = frappe.db.sql(
"""
SELECT COUNT(item.name)
FROM
`tabItem` item {bin_join_selection}
WHERE
item.disabled = 0
AND item.has_variants = 0
AND item.is_sales_item = 1
AND item.is_fixed_asset = 0
AND item.item_group in (SELECT name FROM `tabItem Group` WHERE lft >= {lft} AND rgt <= {rgt})
{condition}
{bin_join_condition}
""".format(
lft=cint(lft),
rgt=cint(rgt),
condition=condition,
bin_join_selection=bin_join_selection,
bin_join_condition=bin_join_condition,
),
{"warehouse": warehouse}
)

return {'count': item_count[0][0]}
#////
117 changes: 115 additions & 2 deletions erpnext/selling/page/point_of_sale/pos_item_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,39 @@ erpnext.PointOfSale.ItemSelector = class {
this.hide_images = settings.hide_images;
this.auto_add_item = settings.auto_add_item_to_cart;

this.inti_component();
this.init_component();
}

inti_component() {
init_component() {
this.prepare_dom();
this.make_search_bar();
this.load_items_data();
this.load_item_groups_data(); //// Ajoutez ceci après avoir chargé les articles
this.bind_events();
this.bind_item_group_events(); //// Ajoutez ceci après avoir lié les événements
this.attach_shortcuts();
}

prepare_dom() {
//// added <div class="parent-item-group-container"></div>
//// added <div class="item-group-container"></div>
this.wrapper.append(
`<section class="items-selector">
<div class="filter-section">
<div class="label">${__('All Items')}</div>
<div class="search-field"></div>
<div class="item-group-field"></div>
</div>
<div class="parent-item-group-container"></div>
<div class="item-group-container"></div>
<div class="items-container"></div>
</section>`
);

this.$component = this.wrapper.find('.items-selector');
this.$items_container = this.$component.find('.items-container');
this.$item_group_container = this.$component.find('.item-group-container'); ////
this.$parent_item_group_container = this.$component.find('.parent-item-group-container'); ////
}

async load_items_data() {
Expand Down Expand Up @@ -407,4 +415,109 @@ erpnext.PointOfSale.ItemSelector = class {
this.set_search_value('');
this.$component.css('display', show ? 'flex': 'none');
}

////
async load_item_groups_data() {
let res = [];
let res_all = [];
let res_childs = [];
let res_parent = [];
let res_all_parents = [];
if(!this.item_group) {
res_childs = await frappe.db.get_list("Item Group", {filters: {'parent_item_group': 'Tous les Groupes d\'Articles'}, fields: ["name", "parent_item_group", "pos_color"]});
let pos_profile_doc = await frappe.db.get_doc("POS Profile", this.pos_profile);
if (pos_profile_doc && pos_profile_doc.item_groups) {
let itemGroupNames = pos_profile_doc.item_groups.map(entry => entry.item_group);

res_childs = res_childs.filter(itemGroupName => !itemGroupNames.includes(itemGroupName));
}
} else {
let group_data = await frappe.db.get_value("Item Group", this.item_group, "group_tree")
if(group_data.message.group_tree) {
let split_group = group_data.message.group_tree.split(">");
for (let group of split_group) {
let parent = await frappe.db.get_list("Item Group", {
filters: {'item_group_name': group},
fields: ["name", "parent_item_group", "pos_color"]
});
res_all_parents = res_all_parents.concat(parent);
}
}
res_childs = await frappe.db.get_list("Item Group", {filters: {'parent_item_group': this.item_group}, fields: ["name", "parent_item_group", "pos_color"]});
}
this.item_groups = res_all_parents;
await this.render_parent_item_group_list(this.item_groups);
this.item_groups = res_childs;
await this.render_item_group_list(this.item_groups);
}

async render_item_group_list(item_groups) {
const item_group_container = this.$component.find('.item-group-container');
item_group_container.html('');

for (let item_group of item_groups) {
let r = await frappe.call({
method: "erpnext.selling.page.point_of_sale.point_of_sale.has_items",
args: { item_group: item_group.name, pos_profile: this.pos_profile },
})

if(r.message && r.message.count > 0) {
const item_group_html = this.get_item_group_html(item_group);
item_group_container.append(item_group_html);
}
}
}

async render_parent_item_group_list(item_groups) {
const item_group_container = this.$component.find('.parent-item-group-container');
item_group_container.html('');

for (let item_group of item_groups) {
let r = await frappe.call({
method: "erpnext.selling.page.point_of_sale.point_of_sale.has_items",
args: { item_group: item_group.name, pos_profile: this.pos_profile },
})

if(r.message && r.message.count > 0) {
const item_group_html = this.get_item_group_html(item_group);
item_group_container.append(item_group_html);
}
}
}

get_item_group_html(item_group) {
let bgColor = item_group.pos_color ? `background-color: ${item_group.pos_color};` : '';
return (
`<div class="item-group-wrapper" data-item-group-name="${escape(item_group.name)}" style="${bgColor}">
${item_group.name}
</div>`
);
}

bind_item_group_events() {
const me = this;
this.$item_group_container.on("click", ".item-group-wrapper", function(){
const $item_group = $(this);
const item_group_name = unescape($item_group.attr('data-item-group-name'));

// Vous pouvez filtrer les articles par catégorie ici
// Par exemple :
me.filter_items_by_item_group(item_group_name, me);
});
this.$parent_item_group_container.on("click", ".item-group-wrapper", function(){
const $item_group = $(this);
const item_group_name = unescape($item_group.attr('data-item-group-name'));

// Vous pouvez filtrer les articles par catégorie ici
// Par exemple :
me.filter_items_by_item_group(item_group_name);
});
}

filter_items_by_item_group(item_group_name) {
this.item_group = item_group_name;
!this.item_group && (this.item_group = this.parent_item_group);
this.filter_items();
this.load_item_groups_data();
}
};
20 changes: 18 additions & 2 deletions erpnext/selling/page/point_of_sale/stripe_terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ erpnext.PointOfSale.StripeTerminal = function(){

function show_loading_modal(title, message) {
loading_dialog = new frappe.ui.Dialog({
title: title,
title: __(title),
fields: [{
label: '',
fieldname: 'show_dialog',
Expand All @@ -52,6 +52,12 @@ erpnext.PointOfSale.StripeTerminal = function(){
html += '</div>';
loading_dialog.fields_dict.show_dialog.$wrapper.html(html);
loading_dialog.show();
if(title == 'Collecting Payments') {
loading_dialog.set_primary_action(__('Cancel'), function () {
loading_dialog.hide();
terminal.clearReaderDisplay();
});
}
}

function unexpectedDisconnect() {
Expand Down Expand Up @@ -261,7 +267,17 @@ erpnext.PointOfSale.StripeTerminal = function(){

function create_payment(payment, is_online){
show_loading_modal('Collecting Payments', 'Please Wait<br>Collecting Payments');
frappe.dom.freeze();
loading_dialog.$wrapper.attr('id', 'myUniqueModalId');
loading_dialog.$wrapper.find('.btn-modal-close').hide()

$(document).on('shown.bs.modal', '#myUniqueModalId', function() {
$(this).data('bs.modal')._config.backdrop = 'static';
$(this).data('bs.modal')._config.keyboard = false;
});
$(document).on('hidden.bs.modal', '#myUniqueModalId', function() {
$(this).removeAttr('id');
});
//frappe.dom.freeze();
frappe.call({
method: "pasigono.pasigono.api.payment_intent_creation",
freeze: true,
Expand Down

0 comments on commit 0406238

Please sign in to comment.