Odoo Help

Welcome!

This community 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.

0

How to create the new line in tree view

By
Rick
on 11/17/16, 12:56 AM 134 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

                     self.amount_each_currency=sums

        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"?>

<openerp>

         <data>

                 <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"/>

                                     </tree>

                            </field>

                 </record>

         </data>

</openerp>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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