Get field value from input to use it in Odoo - odoo

On the Website View,
How to get the value of "nbr1" field and copy it automatically in "Direct copy of nbr1" field ?
Does someone have an example, please ?
template.xml
<template id="biography">
<t t-call="website.layout">
<t t-set="title">bio</t>
<div class="oe_structure">
<div class="container">
<h3 t-field="person.name"/>
<p>Last modified: <i t-field="person.write_date"/></p>
<p>nbr1 : <input type="number" name="nbr1"/></p>
<p>Direct copy of nbr1 : <h3 t-field="person.result"/></p>
</div>
</div>
<div class="oe_structure"/>
</t>
</template>
model.py
name = fields.Char()
nbr1 = fields.Integer()
result = fields.Integer(compute="_compute_total")
#api.onchange('nbr1')
def _compute_total(self):
for record in self:
record.result = self.nbr1

Give nbr1 in onchange function instead of biography.
name = fields.Char()
nbr1 = fields.Integer()
result = fields.Integer()
#api.onchange('nbr1')
def _compute_total(self):
for record in self:
if record.nbr1:
record.result = record.nbr1

Related

I need to bind the first name to the alt text of each LI item

I need to bind the first name to the alt text of each LI item. Don't understand what's the problem. Can someone please help me? Thank you!
html:
<div id = name> <label for = "firstName">First Name:</label> <input type = "text" id = "firstName" v-model = "firstName"> <br><ol><li v-for = "food in foods" :key = "food.id" :alt = "firstName">{{food.text}}</li></ol></div>
vue.js:
var name = new Vue({el: "#name",data:{firstName: "lee",foods: [{id:0, text:"pizza"}, {id:1, text:"ice cream"}, {id:2, text:"sushi"}})
You can add condition like this on LI to show firstname as alternate text when food.text is not available.
<div id = name>
<label for = "firstName">First Name:</label>
<input type = "text" id = "firstName" v-model = "firstName"> <br>
<ol>
<li v-for = "food in foods" :key = "food.id" >{{food && food.text ? food.text : firstName}}</li>
</ol>
</div>
alt is usually used as alternative text for images. If you want to show a tooltip for each <li> use title instead:
<div id="name">
<label for="firstName">First Name:</label>
<input type = "text" id = "firstName" v-model = "firstName"><br>
<ol>
<li v-for = "food in foods" :key = "food.id" :title = "firstName">
{{food.text}}
</li>
</ol>
</div>

How to get specific value by BeautifulSoup?

I try to get some specific text using BeautifulSoup but couldn't figure it out.
All I need is the numbers with the "THIS TEXT" block (56789), not "SOME TEXT"...
Can someone point what's wrong with my code?
from bs4 import BeautifulSoup
def foo():
response = """
<div class="data_content_blog">
<div class="data_content">
<h5 class="large"> SOME TEXT </h5>
<p class="large some-text">12345</p>
</div>
</div>
<div class="data_content_blog">
<div class="data_content">
<h5 class="large"> SOME TEXT </h5>
<p class="large some-text">34567</p>
</div>
</div>
<div class="data_content_blog">
<div class="data_content">
<h5 class="large"> THIS TEXT </h5>
<p class="large this-text">56789</p>
</div>
</div>
"""
soup = BeautifulSoup(response, features="html.parser")
soup_1 = soup.find_all("div", {"class": "data_content"})
for s_1 in soup_1:
s_2 = s_1.find("p").attrs["class"][0]
s_3 = s_1.find("p").attrs["class"][1]
if s_2 == "large" and s_3 == "this-text":
print(s_2, s_3, "<- here")
# get the number 56789 ???
else:
print(s_2, s_3)
If class "this-text" is unique, you can select it and then .find_previous() tag:
num = soup.select_one(".this-text") # or soup.find(class_="this-text")
h5 = num.find_previous()
print(h5.text, num.text)
Prints:
THIS TEXT 56789

Populate Dynamic Input Box with existing Data VueJs

From the title itself, I want to populate a dynamically created input box that I will load via AJAX upon page load.
<div class="col-md-10" id="app">
<div class="form-row" v-for="i in travellers">
<div class="form-group col-md-6" v-for="(details, index) in bookingRequiredDetails">
<label for="required-details">{{ details }}</label>
<input
type="text"
class="form-control"
#input="prop('traveller_' + i, details, $event)"
placeholder="Required Details"
/>
</div>
</div>
</div>
data () {
return {
bookingForm: {
...
bookingRequiredDetails: ''
},
travellerDetails: {},
}
},
load: function () {
... where the data variable has value upon page load
vm.bookingForm.bookingRequiredDetails = data.bookingRequiredDetails;
if (data.travellerDetails) {
vm.travellerDetails = data.travellerDetails;
}
}
Loaded Data:
The input boxes generated will depend on the required details. So for this instance, there will be 3 generated input boxes.
bookingRequiredDetails: Array(1)
0: Array(3)
0: "Full Name"
1: "Age"
2: "Gender"
travellerDetails: Array(1)
0:
traveller_1: Object
Age: "12"
Full Name: "Jane"
Gender: "M"
1: ...
2: ...
Sample Output:
What I want is to populate the existing travellerDetails object with data loaded from the server to their respective input boxes. However, I have problems with pairing the correct data to their respective key-value pairs of the input box as shown in the screenshot.
Any idea would be greatly appreciated.
So I manage to solve it. By adding v-model.
v-model="travellerDetails['traveller_' + i][details]"
div class="col-md-10" id="app">
<div class="form-row" v-for="i in travellers">
<div class="form-group col-md-6" v-for="(details, index) in bookingRequiredDetails">
<label for="required-details">{{ details }}</label>
<input
type="text"
class="form-control"
v-model="travellerDetails['traveller_' + i][details]"
#input="prop('traveller_' + i, details, $event)"
placeholder="Required Details"
/>
</div>
</div>
</div>

Data binding in angular 2

I have 2 input boxes in my HTML file.
<div class="row">
<label>Input1</label>
<input type="text" name="input1" [(ngModel)]="model.valueInput1">
</div>
<div class="row">
<label>Input2</label>
<input type="text" name="input2" [(ngModel)]="model.valueInput2">
</div>
And my model is:
model = {
valueInput1:string = "",
valueInput2:string = ""
}
Now I want, when I bind 'input1', the value should bind with 'input2' automatic. But if I change 'input2' value, it should not make changes in 'input1'.
How can I achieve this kind of binding in Angular 2?
<div class="row">
<label>Input1</label>
<input type="text" name="input1" [(ngModel)]="model.valueInput1" (ngModelChange)="updateInput($event)">
</div>
..........
In the ts
updateInput(value: string): void {
this.model.valueInput2 = value;
}
that's it

Which is Odoo website user group?

I'm new in odoo so sorry if this is a noob question.
How can I assing unlogged website user read permission to the model?
which is the website user group?
And why odoo 8.0 documentation so poor?
I've made a module website_downloads:
models:
class Files(models.Model):
_name = 'website_downloads.files'
name = fields.Char()
file = fields.Binary('File')
filename = fields.Char()
controler:
class website_downloads(http.Controller):
#http.route('/downloads/', auth='public', website=True)
def index(self, **kw):
files = http.request.env['website_downloads.files']
return http.request.render('website_downloads.index', {
'files': files.search([]),
})
website template:
<template id="index" name="Website Downloads Index">
<t t-call="website.layout">
<div id="wrap" style="margin-top:50px;margin-bottom:50px">
<div class="container text-center">
<table class="table table-striped">
<t t-foreach="files" t-as="f">
<tr>
<td align="left"><t t-esc="f.name"/></td>
<td><t t-esc="f.filename"/></td>
<td><a t-attf-href="/web/binary/saveas?model=website_downloads.files&field=file&filename_field=filename&id={{ f.id }}"> <i class="fa fa-download"></i> Download</a></td>
</tr>
</t>
</table>
</div>
</div>
</t>
</template>
security
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_website_downloads_user,website_downloads.files,model_website_downloads_files,base.group_user,1,0,0,0
access_website_downloads_manager,website_downloads.files,model_website_downloads_files,base.group_sale_manager,1,1,1,1
"base.group_public"
I solved adding this to the security file
access_website_downloads_public,website_downloads.files,model_website_downloads_files,base.group_public,1,0,0,0