I got problem while using many2many in attrs, it's fine with domain but got error while using in attrs. Do we have any solution or workaround for this issue?
<field name="visible_fields" widget="many2many_tags"/>
<field name="create_uid" attrs="{'invisible': [('id','not in', visible_fields or False)]}"/>
I don't think the 'or operation' inside the right branch can be parsed. I would try something like this:
<field name="create_uid" attrs="{'invisible': ['|',('id','not in', visible_fields), ('id','=',False)]}"/>
Related
First of all, everything i make is working on my local computer but this error happen when i tried to update this module inside of a server.
I add some fields to res.company
class InheritAccountMove(models.Model):
_inherit = 'res.company'
tax_office = fields.Many2one('tax.office', string='Tax Office')
building_no = fields.Char(string='Building Number')
district_name = fields.Char(string='District/Town')
e_invoice_username = fields.Char(string="E-Invoice API Username")
e_invoice_password = fields.Char(string="E-Invoice API Password")
e_invoice_catalog = fields.Char(string="E-Invoice API Catalog")
e_invoice_isyeri = fields.Char(string="E-Invoice API Isyeri")
e_invoice_wsdl = fields.Char(string="E-Invoice API wsdl")
This is the XML looklike
<record id="view_company_form_inherit" model="ir.ui.view">
<field name="name">company.form</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='vat']" position="after">
<field name="tax_office"/>
<field name="building_no"/>
<field name="district_name"/>
<field name="e_invoice_username"/>
<field name="e_invoice_password"/>
<field name="e_invoice_catalog"/>
<field name="e_invoice_isyeri"/>
<field name="e_invoice_wsdl"/>
</xpath>
</field>
</record>
Its returning:
***THERE IS NO FIELD "e_invoice_username" inside of res.company.***
this fields starting with e_invoice is new ones. tax_office, building_no and district name was created 1 week ago and only with them it was working good.
Error started when i add this e_invoice fields.
I tried uninstall whole module and upload again but nothing changed.
I didn't understand why this is happening ?
Any idea for this problem ?
Uninstall and Install module will not solve the issue. When you modify python code, you need to restart the Odoo service and then activate developer mode then go to Apps-> click update app list.
Suppose we have a model named 'repertoire' with a field Many2many 'documents_id'
and i have a button in the many2many tree view ,in that button i want to get the id of the 'repertoire' i'm in
is there any solution for this
I found the answer ,we can pass a context to the many2many field ,for example :
<field name="app_ids" string="Apps" context="{'current_instance_id': id}">
<tree editable="false" create="false" delete="true">
<field name="name"/>
<button type="object" name="updating_module" icon="fa-refresh"/>
</tree>
</field>
on my function i can retrieve it :
def updating_module(self):
instance_id = self.env.context.get('current_instance_id')
I have created a state on models
state = fields.Selection([
('new', 'New'),
('draft', 'Draft'),
('approved', 'Approved')
],default='new')
I make menuitems that are different for user and admin. But in the admin groups, i get an error after adding filters search.
<record id="view_admin_filter" model="ir.ui.view">
<field name="name">Admin</field>
<field name="model">mymodels</field>
<field name="arch" type="xml">
<search string="Admin">
<filter string="Draft" name="state" domain="[('state','=','draft')]"/>
</search>
</field>
</record>
and
<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{
"search_default_state": 1,
"default_state": 1}
</field>
<field name="domain">[]</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('view_admin_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('view_admin_form')})]"/>
<field name="search_view_id" ref="view_admin_filter"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create.
</p>
</field>
</record>
I found an error like this
ValueError: Wrong value for mail.mail.state: 1
I have tried to replace it like this
"search_default_state": 'draft',
"default_state": 'draft'}
but it still doesn't work and getting error
ValueError: Wrong value for mail.mail.state: u'draft'
how should I fix it?
From what you said you are setting a default value for state some where in your code
with a value that is not in selection.
like for example when you did this:
"default_state": 1
This will cause this error to happen because I'm sure that 1 is not valid value
instead doing this is correct.
"default_state": 'draft'
But only if your selection has this value 'draft'.
One thing you should know in XML removing the code of the context from the action
definition will not remove it from the data base (you will keep having the same problem).
To fix this problem remove this default values from your code then do it again step by step
and make sure you upgrade the moduel and restart the server.
<record id="open_module_tree_admin" model="ir.actions.act_window">
<field name="name">Admin</field>
<field name="res_model">mymodels</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{}</field> <!-- this will update the context to {} -->
.....
....
and check your python code for default value or onchange event make sure your not setting
the state field to a wrong value.
fields.Selection(.... default='draft')
Hope this helps you
And for your filter don't give them names like your fields names
<filter string="Draft" name="draft_state" domain="[('state','=','draft')]"/>
This way you can apply this filter in the context of the action like this:*
{'search_default_draft_state': 1}
I think it's safer.
I'm trying to create a form view.
<field name="is_positive" attrs="{'readonly':[('state','==','final')]}"/>
However there is many attributes like groups and invisible related to authorization so that certain group of people can see the field.
groups="base.group_hr_user"
But Is there a way for certain group can edit the field and the other group cannot?
add a new field to check whether the user is manager or user.
New Api Method
check_user = fields.Boolean(string='user',compute='_compute_user_check')
#api.multi
def _compute_user_check(self):
if self.user_has_groups('purchase.group_purchase_manager'):
self.check_user =True
In view
<field name="is_positive" attrs="{'readonly':[('check_user','=','True')]}"/>
First of all, you cannot use a domain like this one
<field name="is_positive" attrs="{'readonly':[('state','==','final')]}"/>
There is not a '==' operator, use = instead.
Now, to answer your question, if you want to create a special view for another group in which some elements are readonly for one group, and editable in the other, you have to it this way.
For the default view :
<record id="some_model_view" model="ir.ui.view">
<field name="name">some.model.form</field>
<field name="model">some.model</field>
<field name="arch" type="xml">
<form>
<field name="some_field" readonly="1"/>
</form>
<field/>
</record>
For a certain group :
<record id="some_model_view_for_other_group" model="ir.ui.view">
<field name="name">some.model.form</field>
<field name="model">some.model</field>
<field name="inherit_id" ref="my_module.some_model_view"
<field name="groups_id" eval="[(6, 0, [ref('some.first_group')])]" />
<field name="arch" type="xml">
<field name="some_field" position="attributes">
<attribute name="readonly">0</attribute>
</field>
<field/>
</record>
I will show one example to how this functionality works in sale group.
I make the unit price field in the sale order line makes readonly we select the user group user:own documents only The field is editable for other 2 groups user:All documets and manager
Firstly I create a boolean field for checking the user belongs to which group
is_own_user = fields.Boolean(string="Own user", compute='compute_own_user')
Then assigns the boolean field is True when the user belongs the group user:own documents only otherwise assigns to False
#api.depends('product_id')
def compute_own_user(self):
res_user_id = self.env['res.users'].search([('id', '=', self._uid)])
for rec in self:
if res_user_id.has_group('sales_team.group_sale_salesman') and not res_user_id.has_group('sales_team.group_sale_salesman_all_leads'):
rec.is_own_user = True
else:
rec.is_own_user = False
in xml make is_own_user invisible and replaces the unit price field
<xpath expr="//notebook/page/field[#name='order_line']/tree/field[#name='price_unit']" position="replace">
<field name="price_unit" attrs="{'readonly': [('isown_user', '=', True)]}" />
</xpath>
I am trying to customize the crm lead object. Class is defined this way
class yvleads(models.Model):
_inherit = 'crm.lead'
_name = 'crm.lead'
Now I added a menu item to display the added elements for which I have both a tree view and a form view. I have added a lett menu item referening a ir.actions.act_window. When this action is defined as
<record model="ir.actions.act_window" id="yvleads_mgt">
<field name="name">Leads Yves</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="tree_view_yves_leads"/>
</record>
this works fine for the list-tree view but when I click on any item or the create button, I get the default form view for crm.
To add my customized view for form also, my understanding of odoo documentation is that I should use view_ids element but I was not able to get it right
I have tried several syntaxes with/without brackets, using eval="" or inside the xml definition but with no success. Searching this forum for string name="view_ids" was not very helfull, may be it is not the best practice to do that? any help appreciated
<record model="ir.actions.act_window" id="yvleads_mgt">
<field name="name">Leads Yves</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_ids">(tree,tree_view_yves_leads),(form,form_view_yves_leads)</field>
</record>
this is the right syntax :
<field name="view_ids"
eval="
[
(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('tree_external_id')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('form_external_id')}),
]"
/>
The view_id you used in your action is valid only when you click on the menu connected to that action.
What you need to use is view inheritance, i.e. you need to redefine the existing views:
<record id="new_view" model="ir.ui.view">
<field name="name">new view</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm_lead.existing_view_id"/>
<field name="arch" type="xml">
<data>
...
</data>
</field>
</record>
inside the data tag you can accomplish the modifications you need following the instructions in the provided link.
In theory you could also change the whole view, but this could ba problematic if other modules inherits that same view.
This way every time you open crm.lead model in any way, your view is used.
Btw the correct syntax for view_ids would be:
<field name="view_ids" eval="[(6, False, [ref('view_id_1'), ref('view_id_2')])]">
I think very useful for this link so please check it.
https://www.odoo.com/forum/help-1/question/for-which-reason-can-i-add-a-value-to-view-ids-of-a-window-action-97682