我想计算account.bank.statement
上“Montantcrédit”列的总和。我试图使用_get_sum_entry_encoding,但它不起作用。获取odoo8中列的总和
看到的景象:
我想计算account.bank.statement
上“Montantcrédit”列的总和。我试图使用_get_sum_entry_encoding,但它不起作用。获取odoo8中列的总和
看到的景象:
大量试验后,并与Kbir这里的帮助是解决方案: 的.py:
from openerp.osv import fields, orm, osv
class sale_order_line(orm.Model):
_inherit = 'account.bank.statement'
_name = 'account.bank.statement'
def _get_tot(self, cr, uid, ids, name, arg, context=None):
res = {}
cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(ids[0])+"")
data = cr.fetchone()
for re in self.browse(cr, uid, ids, context=context):
res[re.id] = data[0]
return res
def _get_statement_from_line(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
result[line.statement_id.id] = True
return result.keys()
_columns = {
'totm': fields.function(_get_tot, 'totm',type='float',
store = {
'account.bank.statement': (lambda self, cr, uid, ids, context=None: ids, ['line_ids','move_line_ids'], 10),
'account.bank.statement.line': (_get_statement_from_line, ['amount'], 10),
}),
}
的.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form_ftz">
<field name="name">view.order.form.ftz</field>
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_formfz" />
<field name="arch" type="xml">
<xpath expr="//field[@name='balance_start']" position="after">
<field name="totm" string="Montant total"/>
</xpath>
</field>
</record>
</data>
</openerp>
我再想想你卡比尔。
试试下面的代码:
def _get_tot(self, cr, uid, ids, name, arg, context=None):
res = {}
cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(ids)+"")
data = cr.fetchall()
for re in self.browse(cr, uid, ids, context=context):
res[re.id] = data
return res
您好,我想用Python代码来尝试,因为我想打电话给在其他功能 –
总值尝试SQL查询... – KbiR
是的,我尝试..plz看到答案..我得到这个错误:我得到这个错误:KeyError:'statement_id' –
谢谢kbiR的回答我尝试在这里使用SQL查询我的代码:
from openerp.osv import fields, orm, osv
class sale_order_line(orm.Model):
_inherit = 'account.bank.statement'
_name = 'account.bank.statement'
def _get_tot(self,cr,uid,values,context):
idstate = self.id
cr.execute("SELECT sum(amount) FROM account_bank_statement_line WHERE statement_id ="+str(idstate)+"")
return cr.fetchall()
_columns = {
'totm': fields.selection(_get_tot, 'totm'),
}
我的xml字段:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_order_form_ftz">
<field name="name">view.order.form.ftz</field>
<field name="model">account.bank.statement</field>
<field name="inherit_id" ref="account.view_bank_statement_formfz" />
<field name="arch" type="xml">
<xpath expr="//field[@name='balance_start']" position="after">
<field name="totm"/>
</xpath>
</field>
</record>
</data>
</openerp>
我得到这个错误:_get_tot()到底需要5个参数(给出4)
我不能看到id'的'的声明,在你的代码,没有价值的id这就是为什么你得到'keyError'。更新我以前的答案现在就试试。 – KbiR
尝试''totm':dields.function(_get_tot,type ='selection','totm) – KbiR
hi thnx kbir我试试它('totm':fields。功能(_get_tot, 'TOTM',类型= '浮动'))我得到这个错误:ProgrammingError:ERREUR:ERREUR德syntaxe河畔OUPrès区德«[» LINE 1:...吨)FROM account_bank_statement_line WHERE statement_id = [16 ] –
我们可以看看你迄今为止所尝试过的吗?你是否以代码的形式尝试? – halfer