hi
i'm creating a wizard to display revenue by salemsman and agence
when i click on the button "appliquer" i get this error AttributeError: 'ca.report' object has no attribute 'appliquer'
this is my wizard code :
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')
# datas = fields.Binary('File')
# get invoice 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 invoice by date, status , agence 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
}
___________________________________________________________________
and this is my xml.py
<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 col="3">
<field name="paid" class="oe_inline" />
<strong> CA Validé </strong>
<field name="draft" class="oe_inline" />
<strong> CA Brouillon </strong>
<field name="open" class="oe_inline" />
<strong> CA Ouvert </strong>
</group>
<group>
<field name="vendeur" options="{'no_create':True,'no_create_edit': True}"/>
<field name="agence_id" />
</group>
<button name="appliquer" class="oe_inline oe_stat_button" string="Appliquer" type="object" icon="fa-pencil/>
<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="base.next_id_61" sequence="6" />
</data>
</openerp>