From 766efc97a4d83643e03861bbfcd92e70a723e723 Mon Sep 17 00:00:00 2001 From: CarmenMiranda Date: Thu, 10 Nov 2022 18:37:05 +0000 Subject: [PATCH] [REF] pos_restaurant: Split _get_order_lines method Splitting the method `_get_order_lines` will allow making it inheritable, this way more order line fields can be added and expand them easily and avoid having to overwrite it. closes odoo/odoo#105858 X-original-commit: 457624160f03c28e9b90d14fb4c56fe2f7fabeed Signed-off-by: Trinh Jacky (trj) --- addons/pos_restaurant/models/pos_order.py | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/addons/pos_restaurant/models/pos_order.py b/addons/pos_restaurant/models/pos_order.py index 36158587ea0..3a7da05cb6e 100644 --- a/addons/pos_restaurant/models/pos_order.py +++ b/addons/pos_restaurant/models/pos_order.py @@ -67,6 +67,22 @@ class PosOrder(models.Model): ]) return fields + def _prepare_order_line(self, order_line): + """Method that will allow the cleaning of values to send the correct information. + :param order_line: order_line that will be cleaned. + :type order_line: pos.order.line. + :returns: dict -- dict representing the order line's values. + """ + order_line["product_id"] = order_line["product_id"][0] + order_line["server_id"] = order_line["id"] + + del order_line["id"] + if not "pack_lot_ids" in order_line: + order_line["pack_lot_ids"] = [] + else: + order_line["pack_lot_ids"] = [[0, 0, lot] for lot in order_line["pack_lot_ids"]] + return order_line + def _get_order_lines(self, orders): """Add pos_order_lines to the orders. @@ -84,15 +100,7 @@ class PosOrder(models.Model): extended_order_lines = [] for order_line in order_lines: - order_line['product_id'] = order_line['product_id'][0] - order_line['server_id'] = order_line['id'] - - del order_line['id'] - if not 'pack_lot_ids' in order_line: - order_line['pack_lot_ids'] = [] - else: - order_line['pack_lot_ids'] = [[0, 0, lot] for lot in order_line['pack_lot_ids']] - extended_order_lines.append([0, 0, order_line]) + extended_order_lines.append([0, 0, self._prepare_order_line(order_line)]) for order_id, order_lines in groupby(extended_order_lines, key=lambda x:x[2]['order_id']): next(order for order in orders if order['id'] == order_id[0])['lines'] = list(order_lines)