Provo a spiegarvi il mio problema, vorrei fare in modo di colorare le righe o il testo dello stato con diversi colori a seconda dello stato impostato il codice è questo:
py:
from openerp import models, fields, api
import logging
_logger = logging.getLogger(__name__)
import requests
from datetime import datetime
class WebsiteSupportTicket(models.Model):
_name = "website.support.ticket"
def _open_ticket(self):
open_state = self.env.search([('name','=','Aperto')])
return open_state[0]
partner_id = fields.Many2one('res.partner', string="Cliente", readonly=False)
person_name = fields.Char(required=False, string='Persona riferimento', readonly=False)
email = fields.Char(string="Email", readonly=False)
category = fields.Many2one('website.support.ticket.categories', string="Categoria", required=True)
subject = fields.Char(string="Oggetto", readonly=False)
description = fields.Text(string="Descrizione", readonly=False)
state = fields.Many2one('website.support.ticket.states', required=True, default=_open_ticket, string="State Name")
conversation_history = fields.One2many('website.support.ticket.message', 'ticket_id', string="Storia Conversazione")
attachment = fields.Binary(string="Allegato")
attachment_filename = fields.Char(string="Nome allegato")
@api.one
def add_comment(self):
self.conversation_history.create({'content':self.add_comment})
self.add_comment = ""
#send email out to notify user of the comment
#notification_template = self.env.get_object_reference('website_support', 'ticket_new_message')[1]
#values = self.env.generate_email(notification_template, self.id)
#values += message.content + "<hr/>" + "<p>You can reply to this message here</p>"
#msg_id = self.env.create(values)
#self.env.send([msg_id], True)
class WebsiteSupportTicketMessage(models.Model):
_name = "website.support.ticket.message"
ticket_id = fields.Many2one('website.support.ticket', string='Ticket ID')
content = fields.Text(string="Content")
class WebsiteSupportTicketCategories(models.Model):
_name = "website.support.ticket.categories"
name = fields.Char(required=True, string='Category Name')
cat_user_ids = fields.Many2many('res.users', string="Category Users")
class WebsiteSupportTicketStates(models.Model):
_name = "website.support.ticket.states"
name = fields.Char(required=True, string="State Name")
class WebsiteSupportTicketUsers(models.Model):
_inherit = "res.users"
cat_user_ids = fields.Many2many('website.support.ticket.categories', string="Category Users")
xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="whdst_form_view">
<field name="name">whdst Form View</field>
<field name="model">website.support.ticket</field>
<field name="arch" type="xml">
<form create="false">
<group>
<field name="partner_id"/>
<field name="person_name"/>
<field name="email"/>
<field name="category"/>
<field name="state"/>
<field name="subject"/>
<field name="attachment" filename="attachment_filename"/>
<field name="attachment_filename" invisible="True"/>
<field name="description"/>
<field name="conversation_history" context="{'ticket_id':active_id}">
<tree editable="bottom">
<field name="content"/>
</tree>
</field>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="whdst_tree_view">
<field name="name">whdst Tree View</field>
<field name="model">website.support.ticket</field>
<field name="arch" type="xml">
<tree>
<field name="id" string="Ticket Number"/>
<field name="person_name"/>
<field name="category"/>
<field name="state"/>
<field name="email"/>
<field name="description"/>
</tree>
</field>
</record>
<record id="action_view_support_ticket" model="ir.actions.act_window">
<field name="name">Support Tickets</field>
<field name="res_model">website.support.ticket</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p>
No Support Tickets found
</p>
</field>
</record>
Il codice ovviamente funziona correttamente, se aggiungo <tree colors="red:state == 'Aperto'> non succede nulla, ma se cambio ad esempio <tree colors="red:person_name == 'Ciccio'> e ciccio è presente nel campo ciccio diventa rosso.
Sono arrivato a questa conclusione che il campo many2one mi restituisce un valore diverso rispetto al nome dello stato quindi non mi restituisce Aperto ma un'altra cosa anche se a video appare Aperto
Esiste un modo per visualizzare i parametri che arrivano dalla pagina e capire come viene resistuito il valore Aperto?
Ho fatto un pò di casino ma forse mi sono spiegato... o forse no