Question

I'm trying to generate a list in RML report from one2many lines fields. There is sale.order class and sale.order.line (this one is related with another class that stores taxes names).

So in rml report I tried something like this:

[[ ', '.join(list.append(x.name) for x in l.tax_id) ]]

Where l is equivalaned to order_line(this field relates with sale.order.line class) and tax_id relates with taxes table where I need to get all taxes names and append it to string. In rml I can't simply define list and then try some for to append it, because it gives me incorrect syntax error.

After trying that line, I got this error:

TypeError: descriptor 'append' requires a 'list' object but received a 'unicode'

So then I tried wrapping x.name with list(), and then I got this error:

TypeError: append() takes exactly one argument (0 given)

I also tried with lambda, but wasn't able to create list from it too, it would output generator object, if I wrapped lambda expression with list(), then it would output function objects. It's clear that I'm doing something wrong, but I can't figure how to simply get a list that I could then create string from it?

Update I also tried this one:

[[ ', '.join(map(lambda x: x.name, l.tax_id)) ]]

But it works correctly with only one order line. If there are more than one, then it shows the last lines results (forgeting about the previous ones). So it's the same thing that it does not create list.

Sample data (simplified)

Tax table

|id|name|
 1 | tax1
 2 | tax2
 3 | tax3

Sale Order(as order_line as one2many I just showed like this)

|id|order_line|
|1 |3,4|

Sale Order Line

|id|tax_id|
|3 |1,2
|4 |2,3

So giving this sample for such sale order with those order lines and taxes it should output this:

tax1, tax2, tax3 (it should not output the same tax name more than once)

And currently it outputs like this: tax2, tax3

Was it helpful?

Solution

Try [[ ', '.join(list(set(tax.name for line in o.order_line for tax in line.tax_id if tax))) ]]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top