我正在创建一个向导,以按销售员和代理商显示收入 当我单击“贴花”按钮时,出现此错误AttributeError:'ca.report'对象没有属性'appliquer'
代码:
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
from openerp import models, fields, api
import time
from openerp.exceptions import Warning
from cStringIO import StringIO
class ca_report(models.TransientModel):
_name = 'ca.report'
vendeur = fields.Many2many(comodel_name='res.users', string=u'Vendeur')
client_id = fields.Many2many('res.partner',string=u"Client")
agence_id = fields.Many2many('res.agence',string=u'Agence')
open = fields.Boolean(string='CA ouvert',help="total amount open")
draft = fields.Boolean(string='CA brouillon',help="total amount draft")
paid = fields.Boolean(string='CA validé',help="total amount paid")
ca = fields.Float(string='chiffre d\'affaire',compute="_get_total_amount")
date_from = fields.Date('Start Date')
date_to = fields.Date('End Date')
# get invoices by date and status
def _get_invoice_by_DateAndStatus(self):
status = []
if self.open:
status.append('open')
if self.draft:
status.append('draft')
if self.paid:
status.append('paid')
if status :
invoice = self.env['account.invoice'].search([('type', 'in', ['out_invoice']),('state', 'in', status),('date_invoice', '>=', self.date_from),('date_invoice', '<=', self.date_to)])
return invoice
else:
invoice = self.env['account.invoice'].search([('type', 'in', ['out_invoice']),('date_invoice', '>=', self.date_from),('date_invoice', '<=', self.date_to),('state', 'in', ['open','draft','paid'])])
return invoice
# get invoices by date, status, agency and/or vendor
def _get_invoice_by_Vendor_agence(self):
all_invoice = self._get_invoice_by_DateAndStatus()
partner = self.env['res.partner'].search([('user_id', 'in', self.vendeur.ids)])
if self.agence_ids and self.vendeur:
invoice = self.env['account.invoice'].search([('id', 'in', all_invoice.ids),('partner_id', 'in', partner.ids),('agence_id', 'in', self.agence_ids.ids)])
else:
if self.vendeur:
invoice = self.env['account.invoice'].search([('id', 'in', all_invoice.ids),('partner_id', 'in', partner.ids)])
else:
if self.agence_ids:
invoice = self.env['account.invoice'].search([('id', 'in', all_invoice.ids),('agence_id', 'in', self.agence_ids.ids)])
else:
invoice = all_invoice
return invoice
# Total des factures(ca) "à revoir "
def _get_total_amount(self):
invoice_open = self.pool['account.invoice'].search_read(cr,1,[('partner_id','=',o.id),('state','=','open')],['amount_total'],context=context)
invoice_open_total = sum([x['amount_total'] for x in invoice_open]) or 0
invoice_draft = self.pool['account.invoice'].search_read(cr,1,[('partner_id','=',o.id),('state','=','draft')],['amount_total'],context=context)
invoice_draft_total = sum([x['amount_total'] for x in invoice_draft]) or 0
invoice_paid = self.pool['account.invoice'].search_read(cr,1,[('partner_id','=',o.id),('state','=','paid')],['amount_total'],context=context)
invoice_paid_total = sum([x['amount_total'] for x in invoice_paid]) or 0
# afficher le resultat de la demande :
@api.multi
def appliquer(self):
self.ensure_one()
context = dict(self.env.context or {})
def ref(module,xml_id):
proxy = self.env['ir.model.data']
return proxy.get_object_reference(module, xml_id)
model, tree_view_id = ref('account.invoice', 'invoice_tree', 'account.invoice.tree')
context.update(date_from=self.date_from)
context.update(date_to=self.date_to)
context.update(vendeur=self.vendeur)
context.update(agence_id=self.agence_id)
views = [
(tree_view_id, 'tree'),]
domain=[]
for x in self.browse(cr,uid,ids):
if x.vendeur:
domain.append(('vendeur','=',x.vendeur.id))
if x.agence_id:
domain.append(('agence_id','=',x.agence_id.id))
if x.open:
domain.append(('ca','=',x.open))
if x.draft:
domain.append(('ca','=',x.draft))
if x.paid:
domain.append(('ca','=',x.paid))
#if rec.date_from and rec.date_to:
# domain.append (("date_from", "> =", rec.date_from))
# domain.append (("date_to", "<=", rec.date_to))
return {
'name': "Chiffre d'affaire",
'view_type': 'form',
'view_mode': 'tree,graph',
'res_model': 'ca.report',
'view_id': False,
'type': 'ir.actions.act_window',
'views' : views,
'domain': domain
}
答案 0 :(得分:-1)
<record id="ca_report_form" model="ir.ui.view">
<field name="name">ca.report.form</field>
<field name="model">ca.report</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="ca.report">
<group col="4">
<field name="date_from" />
<field name="date_to" />
</group>
<group row="3">
<field name="paid" class="oe_inline" />
<field name="draft" class="oe_inline" />
<field name="open" class="oe_inline" />
</group>
<group>
<field name="vendeur" options="{'no_create':True,'no_create_edit': True}"/>
<field name="agence_id" />
</group>
<button name="appliquer" type="object" string="Appliquer" class="oe_highlight"/>
<footer>
<button string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="ca_report_action" model="ir.actions.act_window">
<field name="name">ca.report.action</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ca.report</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{}</field>
</record>
<menuitem action="ca_report_action"
id="ca_report_menu" name="chiffre d'affaire"
parent="stock.next_id_61" sequence="6" />
</data>