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>