How to show currency symbol instead of currency name? - treeview

I created a module to show related Purchase Orders from projects:
After clicking the Compras (Purchases) button a custom tree view is shown with the currency_id field:
Is there a way to show the symbol of the currency instead of the name? Something like you would do for example using Django: currency_id.symbol. Even better, I want to drop the currency_id field and prepend the currency symbol in the total amount, is that possible? Something like S/. 336.30 in the amount_total field.
Here's my tree view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
....
....
<record id="purchase_order_project_tree" model="ir.ui.view">
<field name="name">purchase.order.tree</field>
<field name="model">purchase.order</field>
<field name="arch" type="xml">
<tree string="Compras"
colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')">
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="currency_id" />
<field name="amount_total" />
<field name="state"/>
</tree>
</field>
</record>
....
....
</data>
</openerp>

You can add a field called currency_symbol in your module (py) that gets the currency symbol when the currency changues with an on_changue to the currency. So you bring that field to the view, you cant directly do it from the XML.

When you click on the that button to get the tree get listed, you can override the "name_get" method of "Currency" and fetch the "currency symbol" instead of name. For this you can pass a flag in the context to limit this modification specific to your module only.
Hope this helps!!.

Related

Odoo res.groups Boolean instead of Dropdown

i have developed a custom module and in that custom module i am trying to give my own access rights.
for that purpose i have created a xml with access groups and a csv that specifies appropriate access right now all this is working quite fine
But i want the selection of access right to not be a dropdown but a boolean select field that lets me choose which level i would like to assign
<record id="group_user" model="res.groups">
<field name="name">Executive</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
<field name="category_id" ref="my_module.module_management"/>
</record>
now i get a dropdown on the user page in application however i would like for this to show below it in a boolean group
I show one example to how the boolean field is work in group
create a gruoup category A
<record model="ir.module.category" id="module_category_a">
<field name="name">A</field>
<field name="sequence">10</field>
</record>
Add manager group to the category A. Automatically checks the manager group
<record id="group_a_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_name.module_category_a"/>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
Add user group to category A.
<record id="group_a_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_name.module_category_a"/>
</record>
This will shows the groups manager and user under A.
There is a boolean field option for both user and manager.

add many2one field in inherited view

I want to display my Many2one field.
I inherited from the hr_timesheet_sheet.sheet model like this:
class list_activity_sheet(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
activity_id = fields.Many2one('list_activity_sheet.activity')
class List_activity(models.Model):
_name='list_activity_sheet.activity'
name= fields.Char('Description',required=True)
And for the View:
<openerp>
<data>
<record id="List_activity_form" model="ir.ui.view">
<field name="name">hr_timesheet_sheet.sheet.form.inherit</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/>
<field name="arch" type="xml">
<xpath expr="/form/sheet/notebook/page[#string='Details']/field/tree/field[#name='name']" position="after">
<field name="activity_id"></field>
</xpath>
</field>
</record>
</data>
When i install my addon , i got that message:
field activity_id doesn't exist in the view.
Does anyone know how to solve that?
You're working on the wrong model. If i understand your view definition correctly, you want to choose an activity on the sheet lines.
You have to inherit hr.analytic.timesheet for that instead of hr_timesheet_sheet.sheet. In Odoo 9+ you have to inherit account.analytic.line, because hr.analytic.timesheet was kicked out.

How to group or nest a tree view by a field in Odoo?

I want to create a nested tree view grouping by fields like the following image.
I did not find any source code within Odoo. How to do it?
When you create a search view with a group_by you can see the lines like that
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">account.invoice.select</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<search string="Search Invoice">
<filter string="Period" context="{'group_by':'period_id'}"/>
</search>
</field>
</record>
You must select it in the search view

inheritance view and adding fields

i have candidat model inherit the hr.emplyee model
i want to display the form view of hr.employee and add fields of my child model candidat
class hr_candidat(models.Model):
_name='hr_recrutement.candidat'
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
.
.
.
<record id="hr_recrutement_candidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr_recrutement.candidat</field>
<field name="arch" type="xml">
<form string="Candidat">
<sheet>
<group>
<field name="situation" />
.
.
</group>
</sheet>
</form>
</field>
</record>
I dont know how to display fields of hr.employee + my fields of candidat in view
Just we should set the below code from the view xml file and also
add the depended module as hr in your openerp.py and set the view xml file path as well.
Add below code in your .py file
class hr_employee(models.Model):
_inherit='hr.employee'
_description="Informations du Candidats"
situation=fields.Selection(string="Situation",selection=[('Nouveau','Nouveau'),('RDV Thechnique','RDV Technique'),('Annulation','Annulationn')])
Add below code in your .xml file
<record id="hr_recrutement_caindidat_form" model="ir.ui.view">
<field name="name">Candidat</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="field[#name='work_location']" position="after">
<field name="situation" />
</xpath>
</field>
</record>
Hear We have to set the position of your element based on xpath using before,after,inside,replace Attributes of xpath tag.
I hope my answer may helpful for you :)

Odoo - search_default does not work?

I created button in partner form to show another models relation with it. It is same button like Opportunities, Meetings, Sales button at partners form showing all its Opportunities, Meetings, Sales etc.
Code looks like this:
Model:
from openerp import models, fields
from openerp import api
class res_partner(models.Model):
_inherit = 'res.partner'
service_ids = fields.One2many('calendar.service', 'partner_id', 'Calendar Services')
service_count = fields.Integer('Services', compute='_count_services')
#api.one
#api.depends('service_ids')
def _count_services(self):
self.service_count = len(self.service_ids)
Action:
<record id="action_calendar_service" model="ir.actions.act_window">
<field name="name">Services</field>
<field name="res_model">calendar.service</field>
<field name="view_mode">tree,calendar,form</field>
<field name="view_id" ref="view_calendar_service_tree"/>
<field name="search_view_id" ref="view_calendar_service_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create new service.
</p>
</field>
</record>
View:
<record id="view_partners_form_service1" model="ir.ui.view">
<field name="name">view.res.partner.form.crm.inherited1</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="crm.view_partners_form_crm1"/>
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<button name="schedule_meeting" position="after">
<button
class="oe_inline oe_stat_button"
attrs="{'invisible': [('customer', '=', False)]}"
name="%(calendar_service.action_calendar_service)d"
icon="fa-star"
type="action"
context="{'search_default_partner_id': active_id}">
<field name="service_count" string="Services" widget="statinfo"/>
</button>
</button>
</field>
</record>
Everything works with that button except for one thing. It does not filter result with partner_id (the one that button was pressed) and it opens all 'calendar.service' records. But it should show only the ones from that specific partner. Does context="{'search_default_partner_id': active_id}"> need something more? What am I missing here?
Finally found what was missing. I needed to add this line:
<field name="partner_id" filter_domain="[('partner_id','child_of',self)]"/>
In my model search view. Without that it does not use search_default filter.

Resources