How to add fields to a tree view with default values on button click?
I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
odoo odoo-10
add a comment |
I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
odoo odoo-10
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42
add a comment |
I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
odoo odoo-10
I add a button that open a new wizard, this last is contain only one field is number , that's number is the number of fields that i want to creat on my tree notebook tree view with default value
for example if i type 20 , thene whene i submit should i get 20 entries in the tree view
odoo odoo-10
odoo odoo-10
asked Nov 12 '18 at 13:02
MahmoudMahmoud
9810
9810
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42
add a comment |
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42
add a comment |
2 Answers
2
active
oldest
votes
Here is a capture of the model :
Look to my code :
@api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
add a comment |
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XMLcontext="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the fieldsource_record_id
in your wizard. You need to make sure your wizard has a field calledsource_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.
– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262756%2fhow-to-add-fields-to-a-tree-view-with-default-values-on-button-click%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a capture of the model :
Look to my code :
@api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
add a comment |
Here is a capture of the model :
Look to my code :
@api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
add a comment |
Here is a capture of the model :
Look to my code :
@api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
Here is a capture of the model :
Look to my code :
@api.multi
def creat_fields(self):
numbers = self.w_qtt
for values in numbers:
# self.env['sale.order.line'].create(lignes_vales)
self.env['sale.order.line'].create({
'contrat_name_id': self.w_contrat_name,
'contrat_lignes_id' : self.w_contrat_line,
'product_id' : self.w_product_name,
'bons_po' : self.w_po_number,
'product_uom_qty' : 1,
'price_unit' : self.w_prix,
})
and on the xml :
<footer>
<button string="Cancel" class="oe_link" special="cancel"/>
<button
name="creat_fields"
string="Enregistrer"
class="oe_highlight"
context="{'default_source_record_id': active_id}"/>
</footer>
answered Nov 16 '18 at 13:44
MahmoudMahmoud
9810
9810
add a comment |
add a comment |
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XMLcontext="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the fieldsource_record_id
in your wizard. You need to make sure your wizard has a field calledsource_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.
– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
add a comment |
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XMLcontext="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the fieldsource_record_id
in your wizard. You need to make sure your wizard has a field calledsource_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.
– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
add a comment |
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
I'm assuming that this is a one2many field. One2many fields are linked to your model by specifying the record id number in a field that you specify when you define the many2one field.
For example:
child_ids = fields.One2many('child.model.name', 'parent_id', 'Child Records')
So when you create a new line using the one2many field, a new record is created of model "child.model.name" and the parent_id field is set to the id of the current record.
So to create a number of empty lines in your form, all you have to do is create records with the "parent_id" field set to the originating records id.
Firstly, you will need to pass the originating record's id to the wizard, which you would do in the button definition:
<button name="%(wizard_action)d"
string="Wizard Button"
type="action"
context="{'default_source_record_id': active_id}" />
You will need a field called "source_record_id" in your wizard, which will be a many2one field with the same model that you are calling it from, and you will need to have that field in your wizard view, but you can make it invisible if you want.
In the code you're calling from the wizard, you will create a loop to call the create method on the "child.model.name" model to create that number of empty records. It would look something like this:
iterations = self.nombre
for i in range(iterations):
self.env['child.model.name'].create({
'parent_id': self.source_record_id.id
})
That will create the empty records and they will be displayed in your one2many field.
edited Nov 16 '18 at 14:15
answered Nov 12 '18 at 15:42
djamesdjames
642
642
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XMLcontext="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the fieldsource_record_id
in your wizard. You need to make sure your wizard has a field calledsource_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.
– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
add a comment |
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XMLcontext="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the fieldsource_record_id
in your wizard. You need to make sure your wizard has a field calledsource_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.
– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
Thank you, can you look to my code and tell me where is the problem please
– Mahmoud
Nov 16 '18 at 13:45
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
@Mahmoud you didn't mention what error or issue you're facing but now that I look at it the for loop should be for values in range(numbers)
– djames
Nov 16 '18 at 13:49
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
yeah I add the for values in range(numbers) but no result on tree view
– Mahmoud
Nov 16 '18 at 13:52
@Mahmoud the line in your XML
context="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the field source_record_id
in your wizard. You need to make sure your wizard has a field called source_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.– djames
Nov 16 '18 at 14:04
@Mahmoud the line in your XML
context="{'default_source_record_id': active_id}"/>
is passing the id number of the active record to the field source_record_id
in your wizard. You need to make sure your wizard has a field called source_record_id
which is a Many2one field with the same model of the parent record to collect that value. Then you need to make sure that you're including that field when you create the new records, because that is how Odoo links the line to the parent model. In your One2many field you specified the model of the lines, and the field that refers to the parent.– djames
Nov 16 '18 at 14:04
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
thank you but I don't understand, can you give me a code example or more details, please
– Mahmoud
Nov 16 '18 at 14:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262756%2fhow-to-add-fields-to-a-tree-view-with-default-values-on-button-click%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what do you mean but when i submit I get 20 entries in the view you mean 20 line in the tree view?!! is so what will be the values of article field in every line?!!!
– EasyOdoo
Nov 15 '18 at 7:42