Add sub categories render in menu

This commit is contained in:
Oscar Alvarez 2020-12-28 18:17:37 -05:00
parent 2a67b0df9c
commit e64663d796
2 changed files with 49 additions and 43 deletions

View File

@ -137,6 +137,7 @@ class MenuDash(QVBoxLayout):
self.last_width = width - self.start_width - 10
def change_view(self, view_id):
print('view_id >>> ', view_id)
view = self.ctx_widgets[self.current_view]['items']
view.hide()
if not view_id:
@ -223,46 +224,46 @@ class MenuDash(QVBoxLayout):
'items': products,
'parent': parent_id,
}
# if childs:
# subrow = 0
# subcol = 0
# sub_categories = QGridLayout()
# sub_categories.setSpacing(4)
# scroll_subarea = QScrollArea()
# scroll_subarea.setWidgetResizable(True)
# scroll_subarea.setLayout(sub_categories)
# self.ctx_widgets[cat_id] = {
# 'items': scroll_subarea,
# 'parent': parent_id,
# }
# for subcat in childs:
# sub_id = str(subcat['id'])
# if subcol > num_cat_cols - 1:
# subcol = 0
# subrow += 1
# name_button = 'button_' + sub_id
# button = CustomButton(
# parent=self,
# id=name_button,
# icon=None,
# desc=subcat['name'],
# method='selected_method',
# target=str(subcat['id']),
# size=self.button_size,
# name_style='category_button'
# )
# sub_categories.addWidget(button, row, col)
# subcol += 1
# products_list = subcat.get('items')
#
# if products_list:
# products_items = self.get_products(products_list)
# print('===>', sub_id, products_items)
# self.ctx_widgets[sub_id] = {
# 'items': products_items,
# 'parent': cat_id,
# }
# col += 1
if childs:
subrow = 0
subcol = 0
sub_categories = QGridLayout()
sub_categories.setSpacing(4)
scroll_subarea = QScrollArea()
scroll_subarea.setWidgetResizable(True)
scroll_subarea.setLayout(sub_categories)
self.ctx_widgets[cat_id] = {
'items': scroll_subarea,
'parent': parent_id,
}
for subcat in childs:
sub_id = str(subcat['id'])
if subcol > num_cat_cols - 1:
subcol = 0
subrow += 1
name_button = 'button_' + sub_id
button = CustomButton(
parent=self,
id=name_button,
icon=None,
desc=subcat['name'],
method='selected_method',
target=str(subcat['id']),
size=self.button_size,
name_style='category_button'
)
sub_categories.addWidget(button, row, col)
subcol += 1
products_list = subcat.get('items')
if products_list:
products_items = self.get_products(products_list)
print('===>', sub_id, products_items)
self.ctx_widgets[sub_id] = {
'items': products_items,
'parent': cat_id,
}
col += 1
def action_back(self):
parent_id = self.ctx_widgets[self.current_view]['parent']

View File

@ -1521,8 +1521,8 @@ class MainWindow(FrontWindow):
if delivery_amount:
self.field_delivery_amount.setText(delivery_amount)
if sale.get('kind'):
self.field_kind.set_from_id(sale['kind'])
kind = sale.get('kind') or ''
self.field_kind.set_from_id(kind)
delivery_party = sale.get('delivery_party') or ''
if delivery_party:
@ -1610,13 +1610,18 @@ class MainWindow(FrontWindow):
]
def get_product_by_categories(self):
print('XXXX =>', self.product_categories)
self.allow_categories = [
pc for pc in self.product_categories if not pc['parent'] and not pc['accounting']
]
for cat in self.allow_categories:
cat['icon'] = get_icon(cat['name_icon'])
cat['items'] = self._get_products_by_category(cat['id'])
if cat.get('childs'):
for child in cat.get('childs'):
child['items'] = self._get_products_by_category(child['id'])
else:
cat['items'] = self._get_products_by_category(cat['id'])
return self.allow_categories
def get_menu_control_panel(self):