How to add Price field to Odoo Product template? - odoo

I am using this free Odoo data slider module on website.
https://www.odoo.com/apps/modules/9.0/website_snippet_data_slider/
A nice module and works well too.I need to add "price" field in to this as currently it displays product name only.
Accordingly to this module we can add fields to slider from product.template to this section
https://github.com/laslabs/odoo-website/blob/9.0/website_snippet_data_slider/static/src/js/data_slider.js#L131
have tried to add price field like this
this.priceField = this.widgetOptions.data_price_field;
this.fields = [this.priceField, 'lst_price'];
unfortunate it doesn't work.Can anyone point me the reason and fix?
Thanks

Basically you need to map the value of the price to an html element. I have not tested this however if you take a look at data_slider.js just follow what is done for the display_name (product name data_name_field) from top to bottom.
You will also want to do some formatting for currency and so on. This should get you going in the right direction. Good luck!
In data_slider.js try making the following changes.
Below line 27 add:
data_price_field: 'price',
Below line 125 add:
this.priceField = this.widgetOptions.data_price_field;
Replace line 131 with:
this.fields = [this.nameField, this.priceField, 'id'];
Below line 96 add:
var $price = $('<h5>').text("Price " + record[this.fields[1]]);
Replace line 97 with:
var $caption = $('<div class="caption">').append($title).append($price);

Related

Sale Quotation Line's Quantity (product_uom_qty) is not triggering onchange

In Sale Quotation Line, there is a field Quantity (product_uom_qty).
I want to customize something in its onchange event, but it does not seem to be triggering it when I change its value.
This is what I tried:
class sale_order_line_inherit(models.Model):
_inherit = 'sale.order.line'
#api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
print(res)
print(self.price_unit)
res = super(sale_order_line_inherit, self).product_uom_change()
print(res)
print(self.price_unit)
Nothing gets printed at all.
I already included 'sale' in manifest as well.
What did I do wrong?
Few points to consider,
How to change quantity from the frond end or script?
Can you verify field name on the list/form view?
Put print statement on the Odoo core sale module
If still not working, put error code on the file and upgrade the module to identify file execute at all or not.
I don't have any issue in your code. This is alternative of your code.
#api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
print(self.price_unit)
super().product_uom_change()
print(self.price_unit)

docx4j: Use docx template and replace value of MergeField variable

So I'm trying to use docx4j. I made a simple template, use that and replace th value programmatically.
Here's my docx template.
My Name is «myName»
I’m «myAge» years old.
My address is «myAddress»
When I click toggle field codes it looks like this.
My Name is {MERGEFIELD myName \* MERGEFORMAT}
I’m {MERGEFIELD myAge \* MERGEFORMAT} years old.
My address is {MERGEFIELD myAddress \* MERGEFORMAT}
I do not know the use of MERGEFIELD but I tried to use it simply because that's what the post in the internet currently use.
Here's my code.
def config = grailsApplication.config.template.invoiceSample as Map
def String templateFileName = "${grailsApplication.config.template.dir}/${config.doc.templateFileName}"
WordprocessingMLPackage template = WordprocessingMLPackage.load(new File(templateFileName));
Map<DataFieldName, String> map = new HashMap<DataFieldName, String>();
map.put(new DataFieldName("#myName"),"Jean");
map.put(new DataFieldName("#myAge"),"30");
map.put(new DataFieldName("#myAddress"),"Sampaloc");
org.docx4j.model.fields.merge.MailMerger.setMERGEFIELDInOutput(MailMerger.OutputField.KEEP_MERGEFIELD);
org.docx4j.model.fields.merge.MailMerger.performMerge(template, map, false);
template.save(new File("C:/temp/OUT_SIMPLE.docx") );
However, It doesn't replace the value in the output file. Could you tell me what is wrong with my code?
I found out that this problem is just easy to fix.
Basically this line affects the output.
MailMerger.setMERGEFIELDInOutput(MailMerger.OutputField.KEEP_MERGEFIELD);
Based on my observation, these options do the following:
MailMerger.OutputField.KEEP_MERGEFIELD - replace the field with value but you need to click toggle field codes to reveal it.
MailMerger.OutputField.REMOVED - the codes will be gone but most importantly the value will be replaced without the need to click toggle field codes
MailMerger.OutputField.AS_FORMTEXT_REGULAR - I honestly don't know what it does, it just shows {FORMTEXT} in the word.
MailMerger.OutputField.DEFAULT - does the same thing with REMOVED.
Please feel free to update my answer if you think i've said something wrong.

Drupal 7 - Print PDF and Panelizer

Hi guys ,
I'm currently working on a Drupal project which use the Panelizer module by overriding the default node display. The panel for this content type is made width a lot of rules and specifications in order to display some specific content (like views) according some fields.
Now I need to print in PDF the same content that is displayed by the panelizer module but in another display (in one column ), so I cloned the display I use and rearranged it to display what I want.Then I want to use this display width the print module but I didn't managed to do that.
Any idea how can I do that ?
I just can't use the default node render, because I would miss some informations dues to the specifications used in the panel, and I can't print the panelized content because it's not the same display.
I read this thread but how can I say to the print module to use the "print" display I cloned instead of the default one ?
Any suggestions or ideas will be appreciated or if you have another idea for doing that you're welcome :)
Thank you !
In your print pdf template you can load the node then create a view with the display and finally render it : drupal_render(node_view(node_load($node->nid), "name of your display")) ;
Another way is to alter node entity info, telling that 'print' view can be panelized, i.e.
/**
* Implements hook_entity_info_alter().
*/
function mymodule_entity_info_alter(&$entity_info) {
$entity_info['node']['view modes']['print']['custom settings'] = TRUE;
...
}
After that, you go to panelizer settings of your content type(s), and set whatever you want for the print view mode

Make Text Field item as Read Only in APEX 5.0

I have some text field page items on my APEX 5.0 page and I want to make the textboxes as read only/non-editable. During the page load I want to use these text boxes for only the data display on the page and should be non-editable.
Can somebody advice on how to do that? What attributes need to set for this?
This answer is a bit late to the party, but I found myself confronted to this problem and I wanted to share the solution I came up with.
In fact you just need to create your item as a text area, let say P1_Text_Area and you give it a readonly attribute using JavaScript. Write thoses 2 lines in the "Function and Global Variable Declaration" of your page:
var disItem = document.getElementById('P1_Text_Area');
disItem.readOnly = true;
Hope this helps someone in need.
in item properties find the
Read Only group
and set Read Only Condition Type as Always
or the option that suits to you
You can use disabled + save session state ==> read only

FilteringSelect text alignment

Using Dojo 1.6.1
I have a FilteringSelect that looks like:
When an address is selected, it looks like:
What I'd really like to see instead is:
Any ideas on how this could be accomplished?
When you select a value in a Filtering select, the caret position is at the end of the text, so it's not CSS that will help you there.
You have to move the cursor to the beginning of the text.
I see no other option than javascript here.
If you look at the template of dijit.form.FilteringSelect, you will see that the input node is bound to the property "focusNode" of the widget. So you could use that to move the caret, like this :
dijit.byId('your_filteringSelect_id').onChange = function(evt) {
this.focusNode.setSelectionRange(0,0);
}
This appears to be an IE & FF issue see this listed bug:
http://bugs.dojotoolkit.org/ticket/8298
and also this test case (issue seen in IE7-9):
http://jsfiddle.net/snover/96Ud8/
The work around suggested is to set the function _setCaretPos to do notthing e.g
dijit.byId('your_filteringSelect_id')._setCaretPos = function() {};
.setSelectionRange doesn't work at IE
Use dijit.selectInputText(widget.focusNode,0,0); instead