From 7e4f747475125e804bfe2d11b05e9c86b24b96c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Tue, 3 May 2022 15:13:22 +0100 Subject: [PATCH] feat: support for notes generation --- src/budy/models/order.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/budy/models/order.py b/src/budy/models/order.py index 30f9606..e97202d 100644 --- a/src/budy/models/order.py +++ b/src/budy/models/order.py @@ -1322,7 +1322,7 @@ def import_omni_s( # an expensive server-to-server operation api.issue_money_sale_slip_sale( sale["object_id"], - metadata = dict(notes = "Budy order - %s" % self.reference) + metadata = dict(notes = self._build_notes()) ) # "marks" the current order as invoiced, properly avoiding @@ -1788,3 +1788,24 @@ def _cancel(self, cancel_data, cancel_function = None, strict = False): if not has_function and not strict: return function = cancel_function or getattr(self, "_cancel_" + method) return function(cancel_data) + + def _build_notes(self): + # creates the list of notes that are going to be representing + # the current order in a text fashion, this should include the product + # attributes for every single order line + notes_l = [] + notes_l.append("Budy order - %s" % self.reference) + for line in self.lines: + if not line.product: continue + if not line.product.product_id: continue + if not line.attributes: continue + attributes_l = appier.legacy.items(line.attributes) + attributes_l.sort() + for key, value in attributes_l: + notes_l.append("Product %s - %s => %s" % ( + line.product.product_id), + key, + str(value) + ) + notes = "\n".join(notes_l) + return notes