Skip to content

Commit

Permalink
feat: support for notes generation
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed May 3, 2022
1 parent 065aef3 commit 7e4f747
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/budy/models/order.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7e4f747

Please sign in to comment.