Referencing another field in a domain function (Odoo12) - field

I want to restrict the account lookup (domain) based on the value entered in GL Prefix (I'll actually use some wildcards and some other logic which I'm comfortable adding later), the problem is that I'm getting a logical True or False value returned by self.x_poLineGLprefix rather than the value in the field. How do I get the actual data value of x_poLineGLprefix?
class QuickPOLine(models.Model):
_name = 'purchase.order.line'
_inherit = 'purchase.order.line'
x_poLineGLprefix = fields.Char(string='GL Prefix')
x_poLineGLaccount = fields.Many2one(
'account.account', string="Line Item Expense Account",
domain=lambda self: [('code', '=', self.x_poLineGLprefix)])

Try this
#api.onchange('x_poLineGLprefix')
def onchange_x_poLineGLprefix(self):
if self.x_poLineGLprefix:
return {'domain': {
'x_poLineGLaccount': [('code', '=', self.x_poLineGLprefix)]
}}

You can add dynamic domain to achieve this based on any field. In #api.onchange() function you can return domain for many2one. To add dynamic domain you can refer this link. If you are using both many2one fields refer this link.

Related

How to change token label using C_SetAttributeValue

Is there any way to change token label using C_SetAttributeValue? what template is being used to change token name as I tried with below function got error iaik.pkcs.pkcs11.wrapper.PKCS11Exception: CKR_TEMPLATE_INCOMPLETE
token = getToken();
CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[2];
attrs[0] = new CK_ATTRIBUTE();
attrs[0].type = PKCS11Constants.CKA_LABEL;
attrs[0].pValue = label.toCharArray();
attrs[1] = new CK_ATTRIBUTE();
attrs[1].type = PKCS11Constants.CKA_ID;
attrs[1].pValue = label.toCharArray();
token.getSlot().getModule().getPKCS11Module().C_SetAttributeValue(
session.getSessionHandle(), token.getSlot().getSlotID(), attrs, true);
Hello on StackOverflow!
Have a look at C_SetAttributeValue definition:
CK_DEFINE_FUNCTION(CK_RV, C_SetAttributeValue)(
CK_SESSION_HANDLE hSession,
CK_OBJECT_HANDLE hObject,
CK_ATTRIBUTE_PTR pTemplate,
CK_ULONG ulCount
);
The second parameter is the Object ID, not the slot ID.
Please refer to your library's manufacturer documentation for extensions to PKCS#11 that allow to set token label.
C_SetAttributeValue is categorized as an object-management function. More precisely, the cryptoki function C_SetAttributeValue is used to modify or set an attribute value of an object (not token). If you use a standard PKCS#11 library, you should use C_initToken to change or set the token label.
Please note that a company may provide some non-standard functions for its own products. Thus, it might be also a non-standard function or extension in a specific product that helps you to change the token label.

URL Mapping - Replacing characters in a parameter pulled from a database

I am currently trying to figure out, how to modify the parameter being integrated into the URL Mapping I am using.
static mappings =
{
"/$controller/$action?/$id?/(.$format)?"
{
constraints {
// apply constraints here
}
}
name test1: "/.../$title/..."{
controller = "study"
action = "st_show"
}
name test2: "/.../$title/..."{
controller = "search"
action = "se_show"
}
The parameter $title is pretty much a dataset, which is pulled from a database and which will get transmitted in the following format [ this is a title ]. So there are square brackets in front and behind the string and words are seperated through blanks.
If I am creating a link through g:link now with the params nested in, it gets put into the url as it is pulled from the database. What I am attempting is to create SEO-URLs, which will present a certain title of a publication devided by hyphens instead of url-encoded "%20".
Until now, I was able to generate dynamic urls looking like this:
http://localhost:8080/projectname/show/%5BAllgemeine%20Bevölkerungs[...]/782/...PARAMS...
Furthermore I already implemented it through JQuery, though it should be static and users should be able to copy the link to open up the page themselves - that wouldn't be possible when changing the url client-side while loading up the page.
Is there a way to define a function with something like replaceAll.(' ', '-'), which can be invoked onto the parameter in the mapping to replace blanks with hyphens and f.e. square brackets with an empty character?
That's pretty much, what I wasn't able to come by through the documentation.
Thank you already in advance for your help!
I managed to solve my problem by creating a service with a function containing a regex and executing this function onto the parameter title in my g:link, which I firstly converted to a string, which gets passed to the function.
<g:link controller="study" action="st_show" params="[data: data, ... title: ConversionService.convert(fieldValue(bean: path).toString(), ... data: data)]"></g:link>
And the function in the ConversionService
public static String convert(String title){
title = title.replaceAll("\\s", "-").replaceAll("[^0-9a-zA-Z\\-]", "");
return title;
}

How to get Customized template fields from invoice using QuickBooks QBFC

I want to get custom S.O. Invoice Template fields using QuickBooks QBFC.
Here's how to read custom fields from a sales order:
Add "0" to the OwnerIDList of the SalesOrderQuery.
Read custom header fields from the DataExtRetList that is attached to SalesOrderRet objects that are returned from the query.
Read custom line item fields from the DataExtRetList in the SalesOrderLineRet and SalesOrderLineGrouptRet objects that are included in each SalesOrderRet (if you're reading line items).
If you're already using the IncludeRetElementList, you must add DataExtRet to the list; if you're not then don't start using IncludeRetElementList until you have custom fields working. Just like any transaction query, you won't see any line item data unless you set the IncludeLineItems flag in the request.
Custom fields are well documented in the QuickBooks SDK Manual. I'd recommend you take a look at the section DataExt: Using Custom Fields and Private Data in the QBSDK Programmers Guide.
To elaborate on Paul Keister's answer, the reason you must add "0" to the query is because that is the Owner ID of the custom field you are attempting to retrieve. 0 is probably likely to be the value, but if the owner ID is different, you will have to use a different value here.
Some example C# code:
//set the owner id of the custom field you are trying to get back
IInvoiceQuery invoiceQuery = requestMsgSet.AppendInvoiceQueryRq();
invoiceQuery.OwnerIDList.Add("0");
//set up query parameters and actually call your query...
//call this method for each invoice to get its custom fields (if they exist)
static void GetInvoiceCustomFields(IInvoiceRet invoice)
{
if (invoice.DataExtRetList == null)
{
return;
}
for (int i = 0; i < invoice.DataExtRetList.Count; i++)
{
IDataExtRet extData = invoice.DataExtRetList.GetAt(i);
Console.WriteLine("external data name: " + extData.DataExtName.GetValue());
Console.WriteLine("external data value: " + extData.DataExtValue.GetValue());
}
}

Override Grails Error Messages to format Dates and Numbers

I have created a domain with a Double field. When the validation occurs it throws the error message with size value showing the number with commas. Following are the detials
Groovy Class
class Quote {
String content;
Double size;
static constraints = {
content(maxSize:1000, blank:false)
size(min: 0.00D, max:999.99D)
}
}
Value entered "11111", error obtained "Size 11,111 is exceeded the limit". I have added the property key/value pair in messages.properties.
Here, I would like to get the message back without the commas. My main aim is to take the key and format the message returned based on my requirements. I require this as I have other fields that need conversion. For example, a date is validated but when showing the error the Gregorian date needs to be converted to an Islamic date and shown to user.
Does anyone know if I can do something to make this work.
I have tried the solution provided in http://ishanf.tumblr.com/post/434379583/custom-property-editor-for-grails but this did not work.
I have also tried modifying the messages values, but this is not flexible in case of my date issue. Example, for a key value pair, instead of using {2} as a place holder I could use {2, date, mm/dd/yyyy}, but for Islamic dates I want to format and show things differently.
Also, please note I have created a separate key for default date formatting for my application.
Would appreciate the help.
In grails, the return of a constrain is an already translated string.
You can create a taglib to format that, or enhance the
Another option would be custom validators. A custom validator can return false or a key when failing.
For example in your domain class, to vaildate a field:
myDateField validator: {val, obj -> obj.myShinyDateValidatorMethod(val) }
private myShinyDateValidatorMethod() {
if (isNotValidDate(val) {
return [the_message_key, val.formatedAsYouWand]
}
}
and, in your properties file you have to have defined the key:
the_message_key=This date: {3} is not valid
The trick here is that in the return from the validator, first string is the key and the rest are parameters for that key, but grails already uses {0}, {1}, {2} placeholders for className, fieldName and value, and the first parameter that you pass will be used as {3} placeholder.
Hope this helps

How to dynamically set Datatables search and column filters state via url params?

Let's say I have two models: customers and orders.
Every order belongs to a customer.
I also set a orders (index) view with a Datatable showing all the orders.
If I want to see all the orders for a given customer all I have to do is to filter the results for that customer writing the concerning customer name in the "search" field or selecting that customer from its column filter field.
Now I'd like to implement a customer-orders link which automatically shows the orders Datatable with those settings.
In other words, I'd like that a link to /orders?isearch='customer_name+customer_surname' will show the Datatable with the customer full name already written in the search field (or the customer column filter set accordingly).
Of course I can fetch the #customer instance variable from the controller and pass it to the view, but then?
Using the oSearch variable in the initialization code I can define an initialization value for the search field, the isearch variable:
$(document).ready( function() {
var isearch = $('#isearch').val()
$('#example').dataTable( {
"oSearch": {"sSearch": isearch}
} );
} )
The isearch value is stored in a proper hidden field in the view:
<%= hidden_field_tag "isearch", #isearch.to_s, { :id => "isearch" } %>
(This is the best way I found so far to pass an instance variable to a .js file in Rails).
Last but not least, the #isearch instance variable is set from the order_controller:
#isearch = params[:isearch]
Of course its value should be passed to the url like:
.../orders?isearch='customer_name+customer_surname'
----ADDENDUM----
I figured out I don't need an instance variable, in fact I can pass as many url params as I want using this javascript function:
function getUrlParam( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1].replace("+", " ");
}
Then I can fetch them from my .js file like this:
// fetches url params
var isearch = getUrlParam('isearch');
var customer_name = getUrlParam('customer_name');
var order_status = getUrlParam('order_status');
Accordin to these values I not only can set the oSearch variable but also a column-specific using Datatables aoSearchCols initialization parameter ( http://www.datatables.net/ref#aoSearchCols )
The last problem to solve, given that I am using individual column filtering with select elements (http://www.datatables.net/release-datatables/examples/api/multi_filter_select.html), so set every select element according to the URL-passed params.
I did it with this jQuery instruction:
// sets all select filters according to url passed params
$('select').val([customer_name, preparation_kind, preparation_status]);
From the performance point of view this solution is improvable, but its easy and it works.

Resources