diff --git a/__init__.py b/__init__.py index d4ed021..ba9b3e5 100644 --- a/__init__.py +++ b/__init__.py @@ -41,6 +41,7 @@ def register(): shop.SaleDiscont, shop.SaleShopDiscounts, printer.POSPrinter, + printer.POSPrinterCategory, sale.SaleSquareBoxStart, statement.Statement, statement.MultiPaymentDeliveryStart, diff --git a/printer.py b/printer.py index b43fa55..1ce6abd 100644 --- a/printer.py +++ b/printer.py @@ -13,12 +13,27 @@ class POSPrinter(ModelSQL, ModelView): ('network', 'Network'), ('ssh', 'SSH'), ('cups', 'Cups'), - ],'Interface', select=True) + ], 'Interface', select=True) host = fields.Char('Host', select=True) port = fields.Char('Port') row_characters = fields.Integer('Row Characters') + categories = fields.One2Many('sale.pos_printer.category', 'printer', 'Categories') @classmethod def __setup__(cls): super(POSPrinter, cls).__setup__() cls._order.insert(0, ('name', 'ASC')) + + +class POSPrinterCategory(ModelSQL, ModelView): + "POS Printer Category" + __name__ = "sale.pos_printer.category" + + printer = fields.Many2One("sale.pos_printer", 'Printer') + category = fields.Many2One("product.category", 'Category') + sequence = fields.Char('Secuence') + + @classmethod + def __setup__(cls): + super(POSPrinterCategory, cls).__setup__() + cls._order.insert(0, ('sequence', 'ASC')) \ No newline at end of file diff --git a/printer.xml b/printer.xml index 100b16b..87bbac7 100644 --- a/printer.xml +++ b/printer.xml @@ -46,6 +46,16 @@ this repository contains the full copyright notices and license terms. --> + + sale.pos_printer.category + tree + pos_printer_category_tree + + + sale.pos_printer.category + form + pos_printer_category_form + diff --git a/sale.py b/sale.py index 99c95b1..27347a2 100644 --- a/sale.py +++ b/sale.py @@ -333,8 +333,12 @@ class Sale(metaclass=PoolMeta): 'payment_term': payment_term.name if payment_term else '', 'total_amount': sale.total_amount_cache or str(sale.total_amount), 'shop': shop_name, - 'lines': [], } + if printer.categories: + orders[printer_id]['lines'] = {c.sequence: [] for c in printer.categories} + orders[printer_id]['categories'] = {c.category.id:c.sequence for c in printer.categories} + else: + orders[printer_id]['lines'] = [] if hasattr(sale, 'kind'): orders[printer_id]['kind'] = sale.kind or ',' if hasattr(sale, 'table_assigned'): @@ -342,12 +346,25 @@ class Sale(metaclass=PoolMeta): extras = cls.get_extras(sale) if extras: orders[printer_id].update(extras) - orders[printer_id]['lines'].append({ + value_line = { 'name': template.name, 'quantity': str(qty), 'unit_price': int(unit_price), 'note': notes, - }) + } + if isinstance(orders[printer_id]['lines'], list): + orders[printer_id]['lines'].append(value_line) + else: + key_id = orders[printer_id]['categories'][template.categories[0].id] + try: + orders[printer_id]['lines'][key_id].append(value_line) + except Exception: + orders[printer_id]['lines'][key_id] = [value_line] + + for order in orders.values(): + if isinstance(order['lines'], dict): + order['lines'] = [line for cats in order['lines'].values() for line in cats] + print('orders return', orders) return orders @@ -1642,7 +1659,7 @@ class SaleLine(metaclass=PoolMeta): __name__ = 'sale.line' order_sended = fields.Boolean('Order Sended') qty_fraction = fields.Char('Qty Fraction') - + @staticmethod def default_quantity(): return 1 diff --git a/tryton.cfg b/tryton.cfg index e2b3635..db81fb1 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=6.0.5 +version=6.0.6 depends: product account diff --git a/view/pos_printer_category_form.xml b/view/pos_printer_category_form.xml new file mode 100644 index 0000000..2ca1a1f --- /dev/null +++ b/view/pos_printer_category_form.xml @@ -0,0 +1,11 @@ + + +
+