how do I force a field to be translated in my Odoo code? - odoo

I am developing a module for electronic invoicing, and should express the payment term in spanish, so I am setting a dictionary with all the needed fields, and when I do this:
{
...
'FmaPago': inv.payment_term.name,
...
}
The output file contains the value "name" in english. I've tried something like
_(inv.payment_term.name)
but with the same result.
How should I force the value to be expressed in a defined translation?

The field name of Payment Terms are already translatable. You can change the translation in Odoo by clicking the little button within a field in edit mode.
If you've done that correct, you have to avoid some typical mistakes at code side if you use the old API.
always pass the context
e.g. if you browse the invoice, pass the context, to get all translations correct
use partner language if you want to translate for them
Odoo is using user language in his context, to translate the web client correctly. If you print documents for customers, you want them in customer language of course...
So you maybe need to manipulate the context (key 'lang'). For new API you have to call with_context() to do that.

You must use _() for strings that you want to be able to translate.
You must make translating files *.po (as i remmember) and thats all I think.
Dont forget to check documentation link

Related

Use category name in Sitefinity blog URL

I followed the instructions here on establishing a new provider and generating custom URLs, and it works as expected. There doesn't seem to be a clear reference for what parameters can be utilized in the settings as the example given is very basic.
I want to use the category name of the post in the URL. I tried:
/[Category]/[UrlName]
but what I got in the frontend was:
http://localhost:60327/my-page/Telerik.OpenAccess.TrackedList%601[System.Guid]/my-post-name
I also tried
/[Category.Title]/[UrlName]
which just threw errors.
Anyone know how to do this, or better yet, a good reference for the parameters?
I don't think this is possible since the Category property is actually a collection (TrackedList).
In theory you would need one of the collection items, let's say the first one, and your URL expression would be /[Category[0].Title]/[UrlName], but this is currently not supported by the expression parser.
Also, the idea of making the URL dependent on a complex (related) field is not a good idea. If someone deletes that category, they will break all your blog post URLs.
I would suggest you to create a custom text field for the blog post item (ex: CategoryUrl) and then you should be able to set the URL format to /[CategoryUrl]/[UrlName]. Make sure CategoryUrl field is required.

What it use and functionality of "Synchronize Translation" in OpenERP?

I found Synchronize Translation in Application Terms under settings. It'll will be visible when we enable Technical Features. I have synchronized the language by selecting both English and French. But it doesn't made any change in Translated Terms. I don't know how it works and what it'll perform.
Purpose of that action is to update translation fields with new fields that you potentially added in your module (or changed/overrided).
Potential cases: if you create new module and add new fields on some object, or create new .rml file etc.
For example: add field with string (name) on eng base 'technical_description' and after sync with french you will get that field in view so you can translate it :)

Best approach to build a DYNAMIC query-by-example form in AngularJS?

I'm relatively experienced with Angular having written many directives, but I have a new requirement where I have to build a query-by-example form into which a user can enter different search criteria. My problem is that I do not know ahead of time what the possible criteria will be. This criteria information will be coming from the server via an ajax request and can differ per user. Thus I will need to dynamically construct a suitable user interface based on the information I get from the server.
I have built individual directives suitable for capturing the search criteria (for example a custom calendar control for date criteria) but I am unsure of the best approach to adding these directives to a form dynamically. Is this even possible in Angular?
I have built something like this before in jQuery but its not so clear to me how I would best do this in an 'Angular way'?
Any suggestions would be most appreciated!
Everything that you can express as a model-to-view projection can be implemented in AngularJS.
I think here you can make a model consisting of "query params". Each of them has name, type and data for filter builder. For example, for the "select" type a data can contain a list of all possible values to choose from.
Then you iterate through the list of "query params" with ng-repeat, rendering each control differently according to its type. That's all.
If I understood the task wrong, please provide more info.

Pass product variables by user selection

I want to make a ticket sales site theme. As you might guess, most of ticket sales site using a flash based chair selection tool. Those systems using premade scenes which is audiences can select their chairs. I can make premade scenes with jQuery or flash but I don't know how can we handle this selection by Magento.
So, what I want to know that is it possible to pass a user specific variable in Magento? I mean, this variable should be available in checkout and backend as well. Could you please give me an advice to accomplish such an idea?
If this option can be selected from a fixed list of options, then what you want can be achieved using Configurable Products, or Custom Options.
If what you're looking for is a completely bespoke user-defined value, then this is pretty programming intensive, so if you're not a developer it's not an easy task.
Forgive the shameless self-link, but I've recently posted on this topic here:
http://mikebywaters.wordpress.com/2012/03/29/adding-custom-data-to-a-cart-item-in-magento/
In short, the post says that you can add an array of custom data to the quote when the item is added to the quote. For this, you’ll have to hijack the add-to-cart controller completely. To start with, take all the functionality from the existing controller. Look at the Mage_Sales_Model_Quote::addProduct() function and you’ll see that it takes two parameters like so:
$quote->addProduct($product, $request);
where $request is of type Varien_Object formatted like this:
$request = new Varien_Object(array(
'qty'=>$qty,
'options'=>$options,
'custom_options'=>$custom_options
));
Hope this helps.

How to create custom context in OpenERP

I want to create custom context in OpenERP. Need something like polish notation in domain with '|'. Need also hierarchial like 'region_id','child_of','region_id.parent_id'. is it possible?
thanks :)
As far as I know, you can dump any data you want into the context, and it's up to the server-side code to interpret that data. The only time I've run into trouble with context was when two screens used the same key in context but put conflicting data there. Then visiting one screen would break the other screen.