Odoo Events add field to form - odoo

I am using Odoo 11 and I am trying to add a field to the event registration form. The registration form actually on the website.
I was able to add to the attendee form but this does not show on the website registration form.
models
class EventRegistration(models.Model):
_inherit = "event.registration"
firstname = fields.Char(
string="Firstname",
index=True,
)
lastname = fields.Char(
string="Lastname",
index=True,
)
name = fields.Char(
string="Name",
compute="_compute_name",
readonly=True,
store=True
)
team = fields.Char(
string="Team",
store=True,
)
View file
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="view_event_registration_form_inherit_firstname">
<field name="name">event.registration.form</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_form" />
<field name="name">event.registration.view.form.inherit.firstname</field>
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="name" position="after">
<field name="firstname"/>
<field name="lastname"/>
<field name="team"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_event_registration_tree_inherit_firstname">
<field name="name">event.registration.tree</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_event_registration_tree" />
<field name="arch" type="xml">
<field name="name" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="name" position="after">
<field name="firstname"/>
<field name="lastname"/>
<field name="team"/>
</field>
<field name="partner_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<record model="ir.ui.view" id="view_registration_search_inherit_firstname">
<field name="name">event.registration.search</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event.view_registration_search" />
<field name="arch" type="xml">
<xpath expr="//search/filter[last()]" position="after">
<field name="firstname" string="Firstname" filter_domain="[('firstname', 'ilike', self)]"/>
<field name="lastname" string="Lastname" filter_domain="[('lastname', 'ilike', self)]"/>
</xpath>
<xpath expr="//search/group" position="inside">
<filter string="Lastname" domain="[]" context="{'group_by': 'lastname'}"/>
<filter string="Firstname" domain="[]" context="{'group_by': 'firstname'}"/>
</xpath>
</field>
</record>
</odoo>
When I click register now I want to add the field team. As you can see from the picture the code adds to the attendee page .

To add a field to the event registration form you have to inherit the template 'registration_attendee_details'. External id is website_event.registration_attendee_details.

Related

How to set specific fields as readonly for specific user in odoo 15?

Below given are fields of my model out of which half fields is for sales and half of them is for accounts. (I have mentioned by comment)
class emd_sales(models.Model):
_name = 'emd.sales'
_inherit = ['mail.thread', 'mail.activity.mixin']
_rec_name = 'tender_no'
#sales fields
date = fields.Date(string='Date', tracking=True, default=fields.Date.context_today)
company_id = fields.Many2one('emd.company', string='Company')
customer_id = fields.Many2one('res.partner', string='Customer')
product_id = fields.Many2one('product.template', string="Product", tracking=True)
product_desc = fields.Char(string='Product Description')
tender_no = fields.Char(string='Tender Number')
tender_due_date = fields.Date(string='Tender Due Date', tracking=True)
mode_of_sd = fields.Selection([('DD', 'DEMAND DRAFT'), ('BANK TRANSFER', 'BANK TRANSFER'), ('FDR', 'FDR'),
('ONLINE TRANSFER', 'ONLINE TRANSFER'), ('CREDIT CARD', 'CREDIT CARD')],
required=True) # status bar
amount = fields.Integer(string='Amount')
# accounts fields
bank_guarantee_no = fields.Integer(string='Bank Guarantee No.')
date = fields.Date(string='Date', tracking=True)
instrument_no = fields.Integer(string='Instrument Number')
bank_name = fields.Char(string='Bank Name')
period = fields.Selection([
('12 Months', '12 Months'),
('18 Months', '18 Months'),
('24 Months', '24 Months'),
('36 Months', '36 Months')
])
expiry_date = fields.Date(string='Expiry Date', tracking=True)
remarks = fields.Text(string='Remarks')
Below given is my form view :
<group>
<group>
<field name="date"/>
<field name="company_id"/>
<field name="customer_id"/>
<field name="product_id"/>
<field name="product_desc"/>
<field name="tender_no"/>
<field name="tender_due_date"/>
<field name="mode_of_sd" widget="radio"/>
<field name="amount"/>
</group>
<group>
<field name="bank_guarantee_no" groups="account.group_account_manager"/>
<field name="date" groups="account.group_account_manager"/>
<field name="instrument_no" groups="account.group_account_manager"/>
<field name="bank_name" groups="account.group_account_manager"/>
<field name="period" groups="account.group_account_manager"/>
<field name="expiry_date" groups="account.group_account_manager"/>
<field name="remarks" groups="account.group_account_manager"/>
<!-- <field name="attachment" widget="many2many_binary"/>-->
</group>
</group>
I wanted to make the sales fields as readonly for specific user.
As per the right answer I wrote the below code :
<record id="emd_form_view_inherit" model="ir.ui.view">
<field name="name">emd.form.view.inherit</field>
<field name="model">emd.accounts</field>
<field name="inherit_id" ref="emd.emd_accounts_form_view"/>
<field name="groups_id" eval="[(6, 0, [ref('account.group_account_manager')])]"/>
<field name="arch" type="xml">
<field name="date" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="company_id" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="customer_id" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="product_id" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="product_desc" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="tender_no" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="tender_due_date" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="mode_of_sd" widget="radio" position="attributes">
<attribute name="readonly">1</attribute>
</field>
<field name="amount" position="attributes">
<attribute name="readonly">1</attribute>
</field>
</field>
</record>
But when I login as admin , I am not able to edit those sales field. I want admin can edit all the fields.
You can extend the view and set the readonly attribute and define the groups allowed to use/access the current view.
If the view extends an existing view, the extension will only be applied for a given user if the user has access to the provided groups_id.
Example:
<record id="emd_sales_form_view_inherit" model="ir.ui.view">
<field name="name">emd.sales.form.view.inherit</field>
<field name="model">emd.sales</field>
<field name="inherit_id" ref="module_test.emd_sales_form_view"/>
<field name="groups_id" eval="[(6, 0, [ref('module_test.group_sale_user')])]"/>
<field name="arch" type="xml">
<field name="date" position="attributes">
<attribute name="readonly">1</attribute>
</field>
</field>
</record>
Odoo will apply the extension view and set the date field reaonly attribute to 1 if the current user belongs to module_test.group_sale_user group
You have to extend that particular view and add the security groups.
see the example below.
<record id="xmlid" model="ir.ui.view">
<field name="name">model.name</field>
<field name="model">model.name</field>
<field name="inherit_id" ref="modulename.view_xml_id"/>
<field name="groups_id" eval="[(4, ref('base.group_user'))]"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="attributes">
<attribute name="readonly">1</attribute>
</xpath>
</field>
</record>

2 fields in tree view

In the product category, I added a product_ids field and I want to display it with a tree view showing name and default_code of products. For some reason I get the error "Field default_code does not exist"
<record id="view_product_category_qty_discount" model="ir.ui.view">
<field name="name">product.category.inherit.qty.discount.Config Hetlita</field>
<field name="model">product.category</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_category_form_view" />
<field name="arch" type="xml">
<form position="inside">
<group col="2" colspan="2">
<separator string="Quantity for discount" colspan="2"/>
<field name="qty_for_discount" />
</group>
<group>
<field name="product_ids" widget="many2many_tags"/>
<tree>
<field name="name"/>
<field name="default_code"/>
</tree>
</group>
</form>
</field>
</record>
class ProductCategory(models.Model):
_inherit = 'product.category'
qty_for_discount = fields.Float(string='Qty For Discount')
product_ids = fields.Many2many(
'product.template', string='Products')
That's because there is no default_code on model product.template but instead on its variants with model product.product. I would change the field on product.category to a One2Many on product.product:
product_ids = fields.One2many(
comodel_name='product.product',
inverse_name='categ_id',
string='Products')
And there is a mistake in your xml:
<group>
<field name="product_ids">
<tree>
<field name="name"/>
<field name="default_code"/>
</tree>
</field>
</group>

Group by field name

I want to do Group by by City but this possibility doesn't shows up. where is my mistake? there is field city in python file and it's showing up in tree view but not really in Group by
<openerp>
<data>
<record id="vpicktree" model="ir.ui.view">
<field name="name">Picking tree city</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="arch" type="xml">
<field name="location_dest_id" position="after">
<field name="city"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
</search>
</field>
</record>
<record id="action_picking_tree_city" model="ir.actions.act_window">
<field name="name">City</field>
<field name="res_model">stock.picking</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,calendar</field>
<field name="domain"></field>
<field name="context">{ 'group_by':'city' }</field>
<field name="search_view_id" ref="stock.view_picking_internal_search"/>
</record>
</data>
</openerp>
The group by must be in search view not on the action setion as you did, so you have to edit your search view:
<record model="ir.ui.view" id="stock_picking_filter_city_search">
<field name="name">stock.picking.tree.filter_search</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<search string="City">
<filter name="city" string="City" context="{'group_by':'city'}"/>
<group expand="0" string="Grouper par">
<filter string="City" icon="terp-personal" domain="[]" context="{'group_by':'city'}"/>
</group>
</search>
</field>
</record>

Openerp 6.1 put product category in sale order line

I want to show the product category in the sale.order.line.tree view of a sales order with the following code which I wrote. It shows the category button under the group by button but on clicking it, I get the following error and I have don't know how to solve the bug:assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
AssertionError: Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True
Here is my code:
from osv import fields, osv<code>
class sales_order_line_category(osv.osv):
_name='sale.order.line'
_inherit='sale.order.line'
_columns={'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.categ_id'),
}
sales_order_line_category()
My view:
`<?xml version="1.0" encoding="utf-8"?>
<record id="view_sale_orderlinecategory" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit</field>
<field name="model">sale.order.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
<record id="view_sale_orderlinecategory2" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit2</field>
<field name="model">sale.order.line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<group expand="0" string="Group By..." >
<filter string="Category of Product" icon="terp-stock_symbol-selection" name="Category" context="{'group_by':'categ_id'}"/>
</group>
</field>
</record>
<record id="view_sale_orderlinecategory3" model="ir.ui.view">
<field name="name">sale.order.line.categoryinherit3</field>
<field name="model">sale.order,line</field>
<field name="type">search</field>
<field name="inherit_id" ref="sale.view_sales_order_uninvoiced_line_filter"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="categ_id" string="Category"/>
</field>
</field>
</record>
</data>
`
WOuld you please try with following code replace?
'categ_id': fields.related('product_id', 'categ_id', type='many2one', relation='product.category', store=True),
Check that your field categ_id must be appear in tree view of sale.order.line where you try to do group by categ_id
Hope this help

readonly in invoice lines based on a value in line

I have a field 'uneditable' in 'account.invoice.line'.
I want to disable editing the line record if uneditable is true but creating enw line should be allowed.
my view code is as follows
<record model="ir.ui.view" id="invoice_supplier_form_ext">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name='inherit_id' ref='account.invoice_supplier_form'/>
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<field name="product_id" position="before">
<field name="uneditable" invisible="1"/>
</field>
<field name="quantity" position="attributes">
<attribute name="attrs">{'readonly': [('uneditable','=', True)]}</attribute>
</field>
</data>
</field>
</record>
Please suggest me what i am doing wrong. I am getting error with this code in view and does not make the line readonly.
Actually your view is wrong. You have defined the fields 'quantity' and 'uneditable' in account.invoice.line and you are adding then in the invoice view. Please check the invoice_supplier_form view and add the fields correctly in the view.
<record model="ir.ui.view" id="invoice_line_form_ext">
<field name="name">account.invoice.line.form</field>
<field name="model">account.invoice.line</field>
<field name='inherit_id' ref='account.view_invoice_line_form'/>
<field name="type">form</field>
<field name="arch" type="xml">
<data>
<field name="product_id" position="before">
<field name="uneditable" invisible="1"/>
</field>
<field name="quantity" position="attributes">
<attribute name="attrs">{'readonly': [('uneditable','=', True)]}</attribute>
</field>
</data>
</field>
</record>