Skip to Content
Menu
This question has been flagged
6 Replies
11808 Views

Hello, 


I'm trying to modify a priority widget so that instead of having only 3 priority levels, it has 5.

This is the section of the code in the main module's view that contains the priority widget (in bold)

[...]

<record model="ir.ui.view" id="crm_case_claims_tree_view">

<field name="name">CRM - Claims Tree</field>

<field name="model">crm.claim</field>

<field name="arch" type="xml">

<tree string="Claims">

<field name="name"/>

<field name="partner_id"/>

<field name="user_id"/>

<field name="date"/>

<field name="stage_id"/>

<field name="date_action_next"/>

<field name="action_next"/>

<field name="date_deadline"/>

<field name="categ_id" string="Type"/>

<field name="date_closed" invisible="1"/>

</tree>

</field>

</record>

<record model="ir.ui.view" id="crm_case_claims_form_view">

<field name="name">CRM - Claims Form</field>

<field name="model">crm.claim</field>

<field name="arch" type="xml">

<form string="Claim">

<header>

<field name="stage_id" widget="statusbar" clickable="True"/>

</header>

<sheet string="Claims">

<group>

<field name="name"/>

<field name="date"/>

</group>

<group colspan="4" col="4" groups="base.group_user">

<field name="user_id" context="{'default_groups_ref': ['base.group_user', 'base.group_partner_manager', 'base.group_sale_salesman_all_leads']}"/>

<field name="priority" widget="priority"/>

<field name="section_id" groups="base.group_multi_salesteams"/>

<field name="date_deadline"/>

</group>

[...]



in the .py file, priority is defined as

'priority': fields.selection([('0','Low'), ('1','Normal'), ('2','High')], 'Priority'),




In my module, I'm trying to inherit the previous view using 

<?xml version="1.0" encoding="UTF-8"?>

<openerp>

<data>

<record model="ir.ui.view" id="crm_claim_mod_view">

<field name="name">crm.claim.mod.view</field>

<field name="model">crm.claim</field>

<field name="inherit_id" ref="crm_claim.crm_case_claims_form_view"/>

<field name="arch" type="xml">

<field name="priority" position="replace">

<field name="priorityNew" widget="priorityNew"

</field>

</field>

</record>

</data>

</openerp>

and in my .py I have defined 

 # -*- coding: utf-8 -*-

from openerp import models, fields, api

from openerp.osv import fields

AVAILABLE_PRIORITIES = [

('0', 'Low'),

('1', 'Normal'),

('2', 'High'),

('3', 'Very High'),

('4', 'Max'),

]

class crm_claim_mod(models.Model):

_inherit = "crm.claim"

_description = "Claims modification"

priorityNew = fields.selection(AVAILABLE_PRIORITIES, 'Priority', select=True)


@api.model

def create(self,vals):

vals['stage_id']='1'

return super(crm_claim_mod,self).create(vals)



But I keep getting this error message

Error details:
Field `priorityNew` does not exist
Error context:
View `crm.claim.mod.view`
[view_id: 1641, xml_id: carlosUpgrade.crm_claim_mod_view, model: crm.claim, parent_id: 1016]" while parsing /home/carlos/dbTest/codigo/mods/carlosUpgrade/crm_claim_mod_view.xml:4, near
<record model="ir.ui.view" id="crm_claim_mod_view">
<field name="name">crm.claim.mod.view</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim.crm_case_claims_form_view"/>
<field name="arch" type="xml">
<field name="priority" position="replace">
<field name="priorityNew" widget="priorityNew"/>
</field>
</field>
Avatar
Discard
Best Answer

Hello Everyone,
I think you just need to follow some simple steps just mentioned below.


1) In Python File Create a field

priority = fields.Selection([
(0, 'Very Low'),
(1, 'Low'),
(2, 'Medium'),
(3, 'High')])


2) In View file Create field 

<field name="priority" widget="priority"/>
Avatar
Discard
Best Answer

If you use new api, there must be 'Selection' instead of 'selection'...Try this one

priorityNew = fields.Selection(AVAILABLE_PRIORITIES, 'Priority', select=True)                    

(put crm_claim in depends, if not)

Hope this will help you...

Avatar
Discard
Author

Hi, thanks for your answer, but if I use Selection, I get this error 2016-05-27 07:19:14,151 3295 CRITICAL base openerp.modules.module: Couldn't load module carlosUpgrade 2016-05-27 07:19:14,151 3295 CRITICAL base openerp.modules.module: 'module' object has no attribute 'Selection' I have crm_claim in the depends section of __openerp__

Best Answer

Hi,

i think you don't need to modify or change the priority widget, you must use it by the same name in xml code and determine your levels on the selection fields.

if you want 5 levels you must start from '0' to  '5' , thats mean 5 levels ,

if you want 3 levels you must start from '0' to  '3' , thats mean 5 levels and so on.

example if you  need 3 levels

priorityNew = fields.selection(

[

('0', 'Low'),

('1', 'Normal'),

('2', 'High'),

('3', 'Very High'),

 

]

, 'Priority', select=True)

Avatar
Discard
Author

The thing is that priorities are set in the original module as _colums: { 'priority': fields.selection([('0','Low'), ('1','Normal'), ('2','High')], 'Priority'),

Author

Sorry about my previous post, I sent it by mistake before finishing writing it The thing is that priorities are set in the original module as _colums: { 'priority': fields.selection([('0','Low'), ('1','Normal'), ('2','High')], 'Priority'), ...} And I can't access (and modify) those values to add more priorities in my module, so that's why I'm trying to completely replace it

Related Posts Replies Views Activity
1
Jan 24
12566
1
May 24
676
0
Apr 22
1531
3
Aug 20
25723
2
Feb 17
2099