How to remove an element from a many2many field? - odoo-8

I'm trying to remove a group element from the many2many list in the model res.groups. In particular I'm trying to remove the "Analytic Accounting" group from the Employee (implied_ids field):
<record model="res.groups" id="base.group_user">
<field name="implied_ids" eval="[(3, ref('analytic.group_analytic_accounting'))]"/>
</record>
I use the number three because I read it in this question:
(3, ID) => cut the link to the linked record with id = ID
(delete the relationship between the two objects but does not delete the target object itself)
But the element doesn't dissapear from the list. Do I need to do anything else? Am I doing it in a wrong way?

Related

PowerApps: Filter a Lookup Field Based on a Previous Field

I have two lists w/ the following details:
List 1: JobType1; Column: Title
List 2: JobType2; Columns: Title, JobType1 (lookup of Title column of List 1)
On List 3 (Request), I am trying to use PowerApps and I have two fields that are lookups of the two lists:
JobType1 - lookup field that uses the Title column of List 1
JobType2 - lookup field that uses the Title column of List 2
I am trying to filter JobType2 field in the form to display all values on the Title column on List 2 that matches the value of the JobType1 field in the form w/ the JobType1 column on List 2.
I tried using this formula but it does not work. Please help me.
Filter(Choices(IntMktg.Job_x0020_Type_x0020_2), Value in Filter('JobType1', IntMktg.Job_x0020_Type_x0020_1 = DataCardValueClient.Text).Title)
Combo box control doesn't display the result. It seems a bug. I tried it out with the 3 lists and created a form on JobRequest. Here is my formula and it works if you use a dropdown. while waiting for Combo box to be fixed, you can use dropdown instead of Combo box.
Filter(Choices(JobRequest.JobType2), Id in Filter([#JobType2], JobType1.Value = DataCardValue2.Selected.Value).ID)

join two tables in linq with special conditions

I hope one can help me, I am new in linq,
I have 2 tables name tblcart and tblorderdetail:
I just show some fields in these two tables to show whats my problem:
tblCart:
ID,
CartID,
Barcode,
and tblOrderDetail:
ID,
CartID,
IsCompleted
Barcode
when someone save an order, before he confirms his request,one row temporarily enter into the tblCart,
then if he or she confirms his request another row will be inserted into the tblOrderDetail ,
Now I wanna not to show the rows that is inserted into tblOrderDetailed(showing just temporarily rows which there is in tblCart),
In another words, if there is rows in tblCart with cartID=1 and at the same time there is the same row with CartID= 1 in tblOrderDetail, then I dont want that Row.
All in all, Just the rows that there isnt in tblOrderDetail, and the field to realize this is CartID,
I should mention that I make Iscompleted=true, and with that either we can exclude the rows we do not want,
I did this:
var cartItems = context.tblCarts
.Join(context.tblSiteOrderDetails,
w => w.CartID,
orderDetail => orderDetail.cartID,
(w,orderDetail) => new{w,orderDetail})
.Where(a=>a.orderDetail.cartID !=a.w.CartID)
.ToList()
however it doesn't work.
one example:
tblCart:
ID=1
CartID=1213
Barcode=4567
ID=2
CartID=1214
Barcode=4567
ID=3
CartID=1215
Barcode=6576
tblOrderDetail:
ID=2
CartID=1213
Barcode=4567
IsCompleted=true
with these data it should just show the last two Row in tblCart, I mean
ID=2
CartID=1214
Barcode=4567
ID=3
CartID=1215
Barcode=6576
This sounds like a case for WHERE NOT EXISTS in sql.
roughly translated this should be something like this in LINQ:
var cartItems = context.tblCarts.Where(crt => !context.tblSiteOrderDetails.Any(od => od.CartID == crt.cartID));
If you have a navigation property on cart to reference details (I'll assume it's called Details), then:
var results=context.tblCarts.Where(c=>!c.Details.Any(d=>d.IsCompleted));

Laravel Eloquent how to get the second or third record?

I have an Order and a Product models.
"Order" HasMany Product (and Product belongsTo Order)...
Let's say I want to display the 3 products of my order, how to do that ?
I know the first could be retrieved like $order->products->first()... but how to retrieve the second and third product?
I tried $order->products->find(1) but "1" represents the id of the product... which I don't want to know...
$order->products()->skip(1)->first();//Second row
$order->products()->skip(2)->first();//Third row
....
Is more performant than loading all products and getting only first, second, ecc..
Instead if you want both second and third, you can get only them in a single query without load other rows, with similar approach:
$order->products()->skip(1)->take(2)->get(); //Skip first, take second and third
I finally found the solution, this is the correct syntax:
$order->products->get(0)->name; will return the first record
$order->products->get(1)->name; will return the second record
$order->products->get(2)->name; will return the third record
And so on...
$order->products()->skip(1)->take(1)->first(); //Second row
$order->products()->skip(2)->take(1)->first(); //Third row
$order->products()->orderBy('salary','desc')->skip(1)->take(1)->first(); //Second highest salary row
$order->products()->orderBy('salary','desc')->skip(2)->take(1)->first(); //Third highest salary row
Say you want a second product from Eloquent Collection
if you are sure that the array keys are same as array indexes, do that
$order->products->get(1)->name;
if you need the second item and you are not sure about the array keys, do this
$order->products->slice(1, 1)->first()->name;
You can simply try this :
$order->products->take(3)->get();

counting child nodes using XPATH

I have following XML
<orderList>
<orderInfo orderId="xyz" returnCode="Pending" />
<orderInfo orderId="yzz" returnCode="Shipped">
<orderDetail shipped-date="xxxx-xx-xx xx:xx:xx">
<order>
....
</order>
</orderDetail>
</orderInfo>
</orderList>
I want to count # of order under each orderDetail item ...
I tried this link (XPath to count the child nodes based on complex filter) but it didn't help
I came up with this path
count(//orderList/orderInfo/orderDetail[count(order)])
If you want to count all order elements in the orderList/orderInfo/orderDetail nodes (ignoring their current context), then you could use:
count(//orderList/orderInfo/orderDetail/order)
If you want to count the number of orders for a specific orderDetail, then you should use a predicate to select which orderDetail you want:
count(//orderList/orderInfo/orderDetail[#shipped-date="xxxx-xx-xx xx:xx:xx"]/order)
Unless you are using XPath 2.0 or a greater version, you won't be able to return a collection of results with a single expression. But you can select all orderDetail elements (//orderList/orderInfo/orderDetail), iterate through them and count the order elements in the current context, or set the predicate value as a variable to select a specific orderDetail.

MVC3 Set Drop down list Selected value

#Html.DropDownListFor(m => m.field, Model.fieldList, "Select")
I have the code above to get the values of a drop down list from a database. Because the database does not have the select value, I am add it to the list. However, I want to set the selected value to a certain value(variable). How can I do this?
Say I want the selected value to be "WI" and "WI" is in the list. How do i do this? Or how do I specify the #value property?
The DropDownListFor function will first look if there is a selected value in the provided select list. If there are no selected values in the selected list items, it will look at the value of the field that the drop down list is for and attempt to match that to the value of each select list item until it finds the correct one. If any select list item does not have value, it will compare it to the text instead.
Once you have the full list generated, loop through it and find the value you want selected, then set the selected property to true and it should choose that one.

Resources