How to creat records in odoo tree view onclick button?












1















please help
I need when I click Enregistrer Button to create those fields in the tree view on the bottom



for this example, I have quantity equal 12 so I need 12 lines to be created on the tree view with the values on the wizard view



enter image description here



the wizard code :



class LinesWizard(models.Model):
_name = 'bons.wizard'
w_contrat_name = fields.Many2one('contrat.contrat', string='Contrat')
w_contrat_line = fields.Many2one('contrat.lignes', string='Ligne contrat')
w_product_name = fields.Many2one('product.product', string='Produit')
w_po_number = fields.Char(string='Numero PO')
w_qtt = fields.Float('quantite', related='w_contrat_line.quantity')
w_prix = fields.Float(string='Prix unitaire', related='w_contrat_line.unit_price')

@api.onchange('w_contrat_name')
def on_change_contrat_name(self):
if self.w_contrat_name:
self.w_contrat_line = False
return {'domain': {'w_contrat_line' : [('ligne_ids', '=', self.w_contrat_name.id)]}}
else:
return {'domain': {'w_contrat_line': }}









share|improve this question

























  • How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

    – EasyOdoo
    Nov 19 '18 at 4:20











  • To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

    – Mahmoud
    Nov 19 '18 at 8:08











  • Can you show a minimum code to reproduce this?

    – WaKo
    Nov 19 '18 at 8:44











  • @WaKo done , I add the wizard code

    – Mahmoud
    Nov 19 '18 at 8:49











  • You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

    – WaKo
    Nov 19 '18 at 9:02
















1















please help
I need when I click Enregistrer Button to create those fields in the tree view on the bottom



for this example, I have quantity equal 12 so I need 12 lines to be created on the tree view with the values on the wizard view



enter image description here



the wizard code :



class LinesWizard(models.Model):
_name = 'bons.wizard'
w_contrat_name = fields.Many2one('contrat.contrat', string='Contrat')
w_contrat_line = fields.Many2one('contrat.lignes', string='Ligne contrat')
w_product_name = fields.Many2one('product.product', string='Produit')
w_po_number = fields.Char(string='Numero PO')
w_qtt = fields.Float('quantite', related='w_contrat_line.quantity')
w_prix = fields.Float(string='Prix unitaire', related='w_contrat_line.unit_price')

@api.onchange('w_contrat_name')
def on_change_contrat_name(self):
if self.w_contrat_name:
self.w_contrat_line = False
return {'domain': {'w_contrat_line' : [('ligne_ids', '=', self.w_contrat_name.id)]}}
else:
return {'domain': {'w_contrat_line': }}









share|improve this question

























  • How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

    – EasyOdoo
    Nov 19 '18 at 4:20











  • To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

    – Mahmoud
    Nov 19 '18 at 8:08











  • Can you show a minimum code to reproduce this?

    – WaKo
    Nov 19 '18 at 8:44











  • @WaKo done , I add the wizard code

    – Mahmoud
    Nov 19 '18 at 8:49











  • You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

    – WaKo
    Nov 19 '18 at 9:02














1












1








1








please help
I need when I click Enregistrer Button to create those fields in the tree view on the bottom



for this example, I have quantity equal 12 so I need 12 lines to be created on the tree view with the values on the wizard view



enter image description here



the wizard code :



class LinesWizard(models.Model):
_name = 'bons.wizard'
w_contrat_name = fields.Many2one('contrat.contrat', string='Contrat')
w_contrat_line = fields.Many2one('contrat.lignes', string='Ligne contrat')
w_product_name = fields.Many2one('product.product', string='Produit')
w_po_number = fields.Char(string='Numero PO')
w_qtt = fields.Float('quantite', related='w_contrat_line.quantity')
w_prix = fields.Float(string='Prix unitaire', related='w_contrat_line.unit_price')

@api.onchange('w_contrat_name')
def on_change_contrat_name(self):
if self.w_contrat_name:
self.w_contrat_line = False
return {'domain': {'w_contrat_line' : [('ligne_ids', '=', self.w_contrat_name.id)]}}
else:
return {'domain': {'w_contrat_line': }}









share|improve this question
















please help
I need when I click Enregistrer Button to create those fields in the tree view on the bottom



for this example, I have quantity equal 12 so I need 12 lines to be created on the tree view with the values on the wizard view



enter image description here



the wizard code :



class LinesWizard(models.Model):
_name = 'bons.wizard'
w_contrat_name = fields.Many2one('contrat.contrat', string='Contrat')
w_contrat_line = fields.Many2one('contrat.lignes', string='Ligne contrat')
w_product_name = fields.Many2one('product.product', string='Produit')
w_po_number = fields.Char(string='Numero PO')
w_qtt = fields.Float('quantite', related='w_contrat_line.quantity')
w_prix = fields.Float(string='Prix unitaire', related='w_contrat_line.unit_price')

@api.onchange('w_contrat_name')
def on_change_contrat_name(self):
if self.w_contrat_name:
self.w_contrat_line = False
return {'domain': {'w_contrat_line' : [('ligne_ids', '=', self.w_contrat_name.id)]}}
else:
return {'domain': {'w_contrat_line': }}






odoo odoo-10 odoo-9






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 8:48







Mahmoud

















asked Nov 18 '18 at 21:29









MahmoudMahmoud

9810




9810













  • How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

    – EasyOdoo
    Nov 19 '18 at 4:20











  • To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

    – Mahmoud
    Nov 19 '18 at 8:08











  • Can you show a minimum code to reproduce this?

    – WaKo
    Nov 19 '18 at 8:44











  • @WaKo done , I add the wizard code

    – Mahmoud
    Nov 19 '18 at 8:49











  • You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

    – WaKo
    Nov 19 '18 at 9:02



















  • How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

    – EasyOdoo
    Nov 19 '18 at 4:20











  • To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

    – Mahmoud
    Nov 19 '18 at 8:08











  • Can you show a minimum code to reproduce this?

    – WaKo
    Nov 19 '18 at 8:44











  • @WaKo done , I add the wizard code

    – Mahmoud
    Nov 19 '18 at 8:49











  • You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

    – WaKo
    Nov 19 '18 at 9:02

















How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

– EasyOdoo
Nov 19 '18 at 4:20





How did you open the wizard by a button. And why you are using a wizard for this.is it because you hate creating lines in the tree view. And is this view for a custom model or sale.order

– EasyOdoo
Nov 19 '18 at 4:20













To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

– Mahmoud
Nov 19 '18 at 8:08





To open the wizard I create a button on the header of sale.order , and why wizard, because is a request of the work they need to create a multi-tree line in one click, depends on the quantity And this view sale.order @Cherif

– Mahmoud
Nov 19 '18 at 8:08













Can you show a minimum code to reproduce this?

– WaKo
Nov 19 '18 at 8:44





Can you show a minimum code to reproduce this?

– WaKo
Nov 19 '18 at 8:44













@WaKo done , I add the wizard code

– Mahmoud
Nov 19 '18 at 8:49





@WaKo done , I add the wizard code

– Mahmoud
Nov 19 '18 at 8:49













You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

– WaKo
Nov 19 '18 at 9:02





You can add a button to fill the order lines from the wizard.Odoo already provided a good example at odoo.com/documentation/10.0/howtos/…

– WaKo
Nov 19 '18 at 9:02












1 Answer
1






active

oldest

votes


















0














In your function for the Enregistrer button, you can use below code to get the active sale.order ID.



session_id = self.env['sale.order'].browse(self._context.get('active_id'))


Then in the same function, simply create and add your rows.



session_id.write({
'your_tree_ids': [(0, False,
{
'w_contrat_name': self.w_contrat_name,
'w_product_name': self.w_product_name,
'etc': 'etc...'}
)] * int(self.w_qtt) # assuming rows to be added are the same, create a list of w_qtt quantity of (0, _, values), since your qty is a float, need to convert to int first
})





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365654%2fhow-to-creat-records-in-odoo-tree-view-onclick-button%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In your function for the Enregistrer button, you can use below code to get the active sale.order ID.



    session_id = self.env['sale.order'].browse(self._context.get('active_id'))


    Then in the same function, simply create and add your rows.



    session_id.write({
    'your_tree_ids': [(0, False,
    {
    'w_contrat_name': self.w_contrat_name,
    'w_product_name': self.w_product_name,
    'etc': 'etc...'}
    )] * int(self.w_qtt) # assuming rows to be added are the same, create a list of w_qtt quantity of (0, _, values), since your qty is a float, need to convert to int first
    })





    share|improve this answer




























      0














      In your function for the Enregistrer button, you can use below code to get the active sale.order ID.



      session_id = self.env['sale.order'].browse(self._context.get('active_id'))


      Then in the same function, simply create and add your rows.



      session_id.write({
      'your_tree_ids': [(0, False,
      {
      'w_contrat_name': self.w_contrat_name,
      'w_product_name': self.w_product_name,
      'etc': 'etc...'}
      )] * int(self.w_qtt) # assuming rows to be added are the same, create a list of w_qtt quantity of (0, _, values), since your qty is a float, need to convert to int first
      })





      share|improve this answer


























        0












        0








        0







        In your function for the Enregistrer button, you can use below code to get the active sale.order ID.



        session_id = self.env['sale.order'].browse(self._context.get('active_id'))


        Then in the same function, simply create and add your rows.



        session_id.write({
        'your_tree_ids': [(0, False,
        {
        'w_contrat_name': self.w_contrat_name,
        'w_product_name': self.w_product_name,
        'etc': 'etc...'}
        )] * int(self.w_qtt) # assuming rows to be added are the same, create a list of w_qtt quantity of (0, _, values), since your qty is a float, need to convert to int first
        })





        share|improve this answer













        In your function for the Enregistrer button, you can use below code to get the active sale.order ID.



        session_id = self.env['sale.order'].browse(self._context.get('active_id'))


        Then in the same function, simply create and add your rows.



        session_id.write({
        'your_tree_ids': [(0, False,
        {
        'w_contrat_name': self.w_contrat_name,
        'w_product_name': self.w_product_name,
        'etc': 'etc...'}
        )] * int(self.w_qtt) # assuming rows to be added are the same, create a list of w_qtt quantity of (0, _, values), since your qty is a float, need to convert to int first
        })






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 19:56









        mingtwo_h9mingtwo_h9

        963




        963






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365654%2fhow-to-creat-records-in-odoo-tree-view-onclick-button%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?