Odoo Help


How to create the new line in tree view

on 11/17/16, 12:56 AM 1,384 views

I extended the sale.order modul.But it always can not create the new line. Any ideas?

My code as below:

from openerp import models, fields, api

class sale_currency_amount(models.Model):

        _name = 'sale.currency.amount'

        order_id= fields.Many2one('sale.order', 'Order Reference')

        currency_id= fields.Many2one('res.currency','currency')

        kind = fields.Char()

        @api.one @api.depends('order_id.amount_total','order_id.order_line.currency_id')

        def _compute_amount_each_currency(self):

               self.create({"currrency_id":3,"kind":"debit",})  #When this function is triggered, I want to create a new line first

               sums = dict([(l.currency_id.name, 0)  for l in self.order_id.order_line])

               for line in self.order_id.order_line:

                     sums[line.currency_id.name] += line.price_subtotal


        amount_each_currency = fields.Text(compute='_compute_amount_each_currency', string="Total", store=True) 


tree view.xml as below:

<?xml version="1.0" encoding="utf-8"?>



                 <record id="sale_order_currency_amount_tree" model="ir.ui.view">

                             <field name="name">sale.currency.amount.tree</field>

                             <field name="model">sale.currency.amount</field>

                             <field name="arch" type="xml">

                                     <tree string="Sales Order Currency Lines" editable = "true" create = 'true' >

                                                 <field name="order_id"/>

                                                  <field name="kind" string='Kind' onchange="onchange_check_change(order_id.amount_total,order_id.order_line.currency_id)"/>

                                                <field name="currency_id"/>

                                                <field name="amount_each_currency"/>






About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/17/16, 12:56 AM
Seen: 1384 times
Last updated: 11/17/16, 1:12 AM