From f30bf4791ad7325736ec634f7bae88b2de62b12e Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 1 Feb 2021 17:54:26 +0100 Subject: [PATCH] purchase_usability: add py3o_lines_layout() --- purchase_usability/models/purchase_order.py | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/purchase_usability/models/purchase_order.py b/purchase_usability/models/purchase_order.py index a3c0817..6709368 100644 --- a/purchase_usability/models/purchase_order.py +++ b/purchase_usability/models/purchase_order.py @@ -42,3 +42,32 @@ class PurchaseOrder(models.Model): self.env, po.amount_untaxed, currency_obj=po.currency_id) result.append((po.id, name)) return result + + # for report + def py3o_lines_layout(self): + self.ensure_one() + res = [] + has_sections = False + subtotal = 0.0 + for line in self.order_line: + if line.display_type == 'line_section': + # insert line + if has_sections: + res.append({'subtotal': subtotal}) + subtotal = 0.0 # reset counter + has_sections = True + else: + if not line.display_type: + subtotal += line.price_subtotal + res.append({'line': line}) + if has_sections: # insert last subtotal line + res.append({'subtotal': subtotal}) + # res: + # [ + # {'line': sale_order_line(1) with display_type=='line_section'}, + # {'line': sale_order_line(2) without display_type}, + # {'line': sale_order_line(3) without display_type}, + # {'line': sale_order_line(4) with display_type=='line_note'}, + # {'subtotal': 8932.23}, + # ] + return res