Strip string from a field with defined separator in invoice report - printing

first of all - I'm still newbie in Odoo so this is maybe explained wrong but I will try.
In inherited invoice_report xml document i have conditional field that needs to be shown - if column (field) in db is equal to another column. To be more precise - if invoice_origin from account_move is equal to name in sale_order.
This is it's code:
<t t-foreach="request.env['sale.order'].search([('name', '=', o.invoice_origin)])" t-as="obj">
For example in database this invoice_origin is [{'invoice_origin': 'S00151-2022'}]
On invoices that are created from more than one sales orders it is this [{'invoice_origin': 'S00123-2022, S00066-2022'}]
How can I strip this data to use in foreach separately the part [{'invoice_origin': 'S00123-2022'}] and separately [{'invoice_origin': 'S00066-2022'}]
Thank you.

You can try to split up the invoice origin and use the result for your existing code:
<t t-set="origin_list" t-value="o.invoice_origin and o.invoice_origin.split(', ') or []" />
<t t-foreach="request.env['sale.order'].search([('name', 'in', origin_list)])" t-as="obj">
<!-- do something -->
</t>

Related

Access 2010 multiple field textbox not showing all

A textbox in a report I am trying to show properly is hiding multiples, even though the second field is different.
For example: "=[Client] & " " & [Invoice]".
If there is a Bob with multiple invoices, the report will only show one Bob and the lowest invoice number.
How can I make the textbox show every client and invoice individually?
Thanks.
Edit: The SQL requested
"SELECT [SUMFCRR&Plaintiff].Firm, [SUMFCRR&Plaintiff].[Firm Type], IIf([ReportID] Is Null,0,Val([ReportID])) AS [Report #], [SUMFCRR&Plaintiff].SumOfFeesBilled, [SUMFCRR&Plaintiff].[SumOfRecommended Reduction], [SUMFCRR&Plaintiff].[SumOfCosts Billed], [SUMFCRR&Plaintiff].[SumOfCost Reduction], [SumOfFeesBilled]+[SumOfCosts Billed]+[SumOfRecommended Reduction]+[SumOfCost Reduction] AS Reimbursement, [SUMFCRR&Plaintiff].Plaintiff, [SUMFCRR&Plaintiff].ReportID, [SumOfRecommended Reduction]+[SumOfCost Reduction] AS ReductionSum, [SUMFCRR&Plaintiff].Invoice, ([SumOfFeesBilled]+[SumOfRecommended Reduction]) AS FeeReimbursement, ([SumOfCosts Billed]+[SumOfCost Reduction]) AS CostReimbursement, -[SumOfRecommended Reduction] AS PositivefeeReduction, IIf([positivefeereduction]>[sumoffeesbilled] Or [sumofcost reduction]>[sumofcosts billed],"E"," ") AS ErrorNote, -[sumofcost reduction] AS PositveCostReduction
FROM [SUMFCRR&Plaintiff]
WHERE ((([SUMFCRR&Plaintiff].Firm) Like [which firm?] & "*") AND (([SUMFCRR&Plaintiff].ReportID)=[which report?]))
ORDER BY IIf([ReportID] Is Null,0,Val([ReportID]));"
Edit2: The two fields of concern here are [Plaintiff] and [Invoice], and all information is shown when I run the query itself.
Fixed it. It was originally in the [Plaintiff] grouping. I changed the group to [Invoice], and the multiple invoice numbers started showing.

Transform portion of ETL using Scriptella?

I am trying out Scriptella to see if it will meet my needs. So far, it seems like a great tool. I've spent several hours studying sample scripts, searching forums, and trying to get the hang of nested queries/scripts.
This is an example of my ETL file, slightly cleaned up for brevity. Lines beginning with # are added and not part of the actual ETL file. I am trying to insert/retrieve IDs and then pass them on to later script blocks. The most promising way to do this appears to be using global variables but I'm getting null when trying to retrieve the values. Later, I will be adding code in the scripts blocks that parse and significantly transform fields before adding them into the DB.
There are no errors. I'm just not getting the OS ID and Category IDs that I'd expect. Thank you in advance.
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<connection id="in" driver="csv" url="mycsvfile.csv"/>
<connection id="dest" url="jdbc:mysql://localhost:3306/pvm3" user="user" password="password"/>
<connection id="js" driver="script"/>
<query connection-id="in">
<!-- all columns are selected, notably: OPERATINGSYSTEM, CATEGORY, QID, TITLE -->
<query connection-id="dest">
#Check to see if the OS already exists, and get the ID if it does
select max(os_id) as os_id, count(*) as os_cnt from etl_os where os = ?OPERATINGSYSTEM;
#If it doesnt exist then add it and get the auto_increment value
<script if="os_cnt==0">
insert into etl_os(os) values(?OPERATINGSYSTEM);
<query connection-id="dest">
select last_insert_id() as os_id;
#Store in global so it can be accessed in later script blocks
<script connection-id="js">
etl.globals.put('os_id', os_id);
</script>
</query>
</script>
#Same style select/insert as above for category_id (excluded for brevity)
#See if KB record exists by qid, if not then add it with the OS ID and category ID we got earlier
<query connection-id="dest">
select max(qid) as existing_qid, count(*) as kb_cnt from etl_qids where qid = ?QID
<script if="kb_cnt==0">
insert into etl_qids(qid, category_id, os_id) values (?QID, ?{etl.globals.get('category_id')}, ?{etl.globals.get('os_id')});
</script>
</query>
</query>
</query>
</etl>
Found out how to do it. Essentially, just nest queries to modify the data before passing it to a script. The below is a quick type-up of the solution. I did not understand at first that queries could be immediately nested to transform the row before passing it for processing. My impression was also that only scripts could manipulate the data.
(Query)Raw data -> (Query)manipulate data -> (Script)write new data.
.. in is a CSV file ..
.. js is a driver="script" block ..
<query connection-id="in">
<query connection-id="js">
//transform data as needed here
if (BASE_TYPE == '-') BASE_TYPE = '0';
if (SECONDARY_TYPE == '-') SECONDARY_TYPE = '0';
SIZES = SIZES.toLowerCase();
query.next(); //call nested scripts
<script connection-id="db">
INSERT IGNORE INTO sizes(size) VALUES (?SIZE);
INSERT IGNORE INTO test(base_type,secondary_type) VALUES (?BASE_TYPE, ?SECONDARY_TYPE);
</script>
</query>
</query>

multiple expressions for single condition result

I have to change the header string of primefaces dialog, acording to a variable state in my backing bean. The condition would be the following (pseudo code):
#{backingBean.editing ? resourceBundle.edit_string resourceBundle.item.id : msg.add_string}
and the short snippet example:
<p:dialog id="dokDialog" header="#{backingBean.editing ? resourceBundle.edit_string resourceBundle.item.id : msg.add_string}" ...>
<!-- content -->
</p:dialog>
In this example I want to display either value #{msg.edit_string} #{resourceBundle.item.id} or #{msg.add_string} according to boolean value of #{backingBean.editing}.
What I want to do is to show either Editing Item 01 or New Item in the title.
Also I get the following exeption because I have two expressions (resourceBundle.edit_string resourceBundle.item.id) for one result:
Caused by: org.apache.el.parser.ParseException: Encountered " <IDENTIFIER>
Thanks!
resourceBundle.edit_string resourceBundle.item.id - it's a wrong expression. You need to concatenate
String.concat may help if you are using an appropriate version of EL: resourceBundle.edit_string.concat(' ').concat(resourceBundle.item.id)

how to manage a one to many relationship - grails

I have a simple problem. I need to manage a hasMany collection on a domain object. I thought I was doing it correct, but it didn't work. I found another post but it is very dated and does not work (Handling parameters from dynamic form for one-to-many relationships in grails)
class User{
static hasMany = ['prefs': Preference]
}
class Preference{
Boolean email
Boolean site
Date dateCreated
Date lastUpdated
}
GSP
<g:each var="t" in="${user.prefs}" status="idx">
<li>
<input type='hidden' name="prefs[${idx}].id" value="${t.id}"/>
Email: <g:checkBox name="prefs[${idx}].email" value="${t.email}" />
Site: <g:checkBox name="prefs[${idx}].site" value="${t.site}" /><
</li>
</g:each>
Controller:
log.info(user.prefs)
user.properties = params
if(!user.save()){ ... }
It then errors out:
UserController - [Preference : 3, Preference : 4]
Error 2013-06-04 21:54:41,405 [http-bio-8080-exec-12] ERROR errors.GrailsExceptionResolver
IndexOutOfBoundsException occurred when processing request: [POST] /user/prefs - parameters:
prefs[0].email:
id: 2
prefs[1].site: on
prefs[0].email: on
_prefs[1].site:
_prefs[1].email:
prefs[1].id: 3
_prefs[0].site:
prefs[0].site: on
prefs[0].id: 4
Index: 1, Size: 1. Stacktrace follows:
Message: Index: 1, Size: 1
I found this problem few days ago. And spent 2 days to fix it.
You have to make sure that children index in params is ordered same as parent's object. In this case, the children's order is [Preference: 3, Preference: 4]. But the params order is prefs[0].id = 4, prefs[1].id = 3. The order is different.
I have to reorder the children index in params before bind them.
So I ended up fixing this and it was a hybrid approach. #Meam was correct, it was an ordering issue, but instead of worrying about ordering I just used #dmahapatro 's approach and set Preference to be a list. A side note on this is the definition of List preference has to come before the static hasMany definition. Or you will get a random error when trying to create User. Lastly, when you originally setup the relationship you have to use addTo to link the two...
class User{
List preference
static hasMany = ['prefs': Preference]
}
//another thing I did not know in order to originaly link
//the two when using lists, you have to use addTo...
user.addToPrefs(
new Preference(email: true, site:false)
)
The last thing I wanted to mention is there is a bug in <g:checkbox> if you use it with a hasMany like I did it will not work if you try to uncheck the value. I was able to work around it via coping the code from github for FormTagLib. And then updated the code with the other post i was reading https://stackoverflow.com/a/2942667/256793 that has a solution but it was a little dated. So here is the updated version:
//old code
//out << "<input type=\"hidden\" name=\"_${name}\""
//new...
def begin = name.lastIndexOf('.') +1
def tail = name.substring( begin);
out << "<input type=\"hidden\" name=\"${name.replace( tail, "_" + tail )}\" "

Find child of child which attribute code is equal to the parameter passed on the url - XSL

On this dynamic website,
The url looks something like this : departments/CHEM.html
CHEM is a parameter.
<xsl:param name="dep" select="'CHEM'" />
a piece of the xml is below
<course acad_year="2012" cat_num="5085" offered="Y">
<term term_pattern_code="1" fall_term="Y" spring_term="N">fall term</term>
<department code="CHEM">
<dept_long_name>Department of Chemistry and Chemical Biology</dept_long_name>
<dept_short_name>Chemistry and Chemical Biology</dept_short_name>
</department>
</course> ....
I am trying to get the dept_short_name to use on my H1 tag, but I have not been successful.So far I tried
<h2><xsl:value-of select="course/department/[code={#$dep}]"/></h2>
Any suggestions??? Thanks!
Just use:
<xsl:value-of select="course/department[#code eq $dep]/dept_short_name"/>
Remember:
In XPath 2.0 (XSLT 2.0) use the eq operator for value comparissons -- it is more efficient than the general comparisson operator = which really, only, needs to be used when at least one of its operands is a sequence.
I would try this:
<xsl:value-of select="course/department[#code=$dep]/dept_short_name/text()"/>
That says: find the department element (inside a course element) whose code attribute is the value of parameter "dep", then find the dept_short_name child element, then get the text inside that element.
You have to use the # to say that "code" is an attribute, but "dep" should not have it. I think the {} notation is for use inside attributes of the non-XSLT elements of your stylesheet, so I wouldn't use it inside a value-of expression.

Resources