Odoo: How to count in Tree View when group_by? - odoo-8

I'm trying to count plan_payment_number in tree view when group_by, but SUM by default in Odoo v8. I need only count plan_payment_number.
This is what I have now:
And this is what I need:
I tried with count = "true". My code on the tree view:
<record id="view_plan_car_tree" model="ir.ui.view">
<field name="name">plan.car.tree</field>
<field name="model">plan.car</field>
<field name="arch" type="xml">
<tree colors="blue:state == 'draft';black:state ==
'done';gray:state == 'cancel'" string="Payments">
<field name="number"/>
<field name="plan_payment_number" />
<field name="date_to"/>
<field name="name"/>
<field name="state"/>
<field name="contract_id"/>
<field name="partner_id"/>
<field name="initial_quota"/>
<field name="capital_quota"/>
<field name="administrative_quota"/>
<field name="pay_type"/>
<field name="company_id" groups="base.group_multi_company"
widget="selection"/>
<field name="plan_run_id" invisible="1"/>
</tree>
</field>
</record>

My solution for this problem is:
class plan_car(models.Model):
_inherit = 'plan.car'
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None,
context=None, orderby=False, lazy=True):
res = super(plan_car, self).read_group(cr, uid, domain, fields, groupby,
offset, limit=limit, context=context, orderby=orderby, lazy=lazy)
if 'plan_payment_number' in fields:
for line in res:
if '__domain' in line:
lines = self.search(cr, uid, line['__domain'], context=context)
pending_value = 0
for current_account in self.browse(cr, uid, lines,
context=context):
pending_value += 1
line['plan_payment_number'] = pending_value
return res

Related

Odoo v11: How to pass a parameter to cron job

Here's my code snippet. I want to pass param1 to cron job.
How do I do that?
class MyTask(models.Model):
_name = "my.task"
#api.model
def cron_do_task(self, param1)
print(param1)
<record id="cron_do_task" forcecreate='True' model="ir.cron">
<field name="name">Do -Task</field>
<field eval="False" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">15</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_my_task"/>
<field name="state">code</field>
<field name="code">model.cron_do_task(???)</field>
</record>
I believe args is no more available in v11

Hide lines in odoo treeview

I want to hide equipments that are not in an inventory. I've tried with
<record id="view_inventory_equipment_tree" model="ir.ui.view">
<field name="name">maintenance.equipment.tree</field>
<field name="model">maintenance.equipment</field>
<field name="domain">[('inventory_id','=',False)]</field>
<field name="arch" type="xml">
<tree string="Lot/Serial Number Inventory">
<field name="name"/>
<field name="serial_no"/>
<field name="category_id"/>
<field name="inventory_id"/>
<field name="cost"/>
</tree>
</field>
</record>
But that did not work, also there is no luck with
<field name="domain_force">[('inventory_id','=',False)]</field>
My model:
class MaintenanceEquipment(models.Model):
_name = 'maintenance.equipment'
_description = 'Equipment'
name = fields.Char('Equipment Name', required=True, translate=True)
inventory_id = fields.Many2one('maintenance.equipment.inventory', string='Equipment Inventory', track_visibility='onchange')
Put domain in action window record. Domain not work in directly with any view like tree or form view.

Odoo 8 - Calendar View Error

Get an error: Odoo Warning - Insufficient fields for Calendar View! and the calendar, of course,never shows up.
I'm missing something but don't know what;
I have this view fragment:
<record model="ir.actions.act_window" id="action_soft_apps_event">
<field name="name">Applications</field>
<field name="res_model">soft.app</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="arch" type="xml">
<calendar string="App Releases" color="dev_id" date_start="release" date_delay="1">
<field name="name"/>
<field name="desc"/>
<field name="downloads"/>
<field name="valid"/>
</calendar>
</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Register a new App</p>
</field>
</record>
And the model is the following:
class soft_app(osv.osv):
"""Apps"""
_name = 'soft.app'
_columns = {
'name': fields.char('Name', size=32, required=True, help='This is the name of the application'),
'desc': fields.text('Description', help='A brief description of the application'),
'dev_id': fields.many2one('soft.dev','Developer',required=True, help='The app\'s developer'),
'release': fields.datetime('Release Date', help='The date that the app was released'),
'downloads': fields.integer('Download Count', help='Total amount of downloads'),
'user_ids': fields.many2many('soft.user','soft_user_app_rel','app_id','user_id','Users Downloaded', help='Users that have downloaded the app'),
'os_ids': fields.many2many('soft.os','soft_os_app_rel','app_id','os_id','Operating Systems', help='Operating systems survey data'),
'valid': fields.boolean('Is Valid', help='Checks if the app is validated')
}
soft_app()
I think you have to create separate calendar view and action
Like:
Calendar view
<record id="view_invoice_line_calendar" model="ir.ui.view">
<field name="name">account.invoice.calendar</field>
<field name="model">account.invoice</field>
<field name="arch" type="xml">
<calendar string="Invoices" color="journal_id" date_start="date_invoice">
<field name="partner_id"/>
<field name="amount_total"/>
</calendar>
</field>
</record>
Action
<record id="action_invoice_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,graph</field>
<field name="view_id" ref="invoice_tree"/>
<field name="context">{'type':'out_invoice'}</field>
<field name="search_view_id" ref="view_account_invoice_filter"/>
</record>

odoo graph view measure are not displayed

Model:
class AdherantsAnimals(models.Model):
_name = "adherants.animal"
IDENT_id = fields.Many2one(comodel_name='adherants.ident',inverse_name='ANIMAL_ids')
IDENT_NAME = fields.Char(related='IDENT_id.NOM',string="Adherant")
ANIMAL_TYPE_id = fields.Many2one('adherants.animal.categ',inverse_name='ANIMAL_ids',string="Categorie")
TYPE_id = fields.Many2one('adherants.animal.type')
TYPE = fields.Char(related="ANIMAL_TYPE_id.TYPE_ids.TYPE",string="Type",store=True)
NBR = fields.Integer(string='Totals', required=True)
Graph view:
<record model="ir.ui.view" id="adherants_animal_graph_view">
<field name="name">adherants.animal.graph</field>
<field name="model">adherants.animal</field>
<field name="arch" type="xml">
<graph type="pivot">
<field name="TYPE" type="row"/>
<field name="NBR" type="measure"/>
</graph>
</field>
</record>
the problem is thats in the the graph view a can't see NBR values ..
Thanks
NBR = fields.Integer(string='Totals', required=True, store=True)

on change method in openerp

i am trying onchange method programme in openerp using python. but there is no error at the same time there is no response while i change name in field.
xml coding (cus_view.xml)
<?xml version="1.0"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record model = "ir.ui.view" id = "custom_tree">
<field name = "name">Custom</field>
<field name = "model">cus.custom</field>
<field name = "type">form</field>
<field name = "arch1" type = "xml">
<tree string = "custom" version = "7.0">
<field name = "name"/>
<field name = "customer_name"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record model = "ir.ui.view" id = "custom_form">
<field name = "name">Custom</field>
<field name = "model">cus.custom</field>
<field name = "type">form</field>
<field name = "arch1" type = "xml">
<form string = "custom" version = "7.0">
<label for = "name" string = "Lab Id"/>
<field name = "name" style = "width:10%%" /><br/>
<label for = "customer_name" string = "Customer Name" />
<field name = "customer_name" style = "width:10%%" on_change="on_change_customer(customer_name)" /><br/>
<label for = "Street1" string = "Address"/>
<field name = "customer_street1" style = "width:10%%"/><br/>
<field name = "customer_street2" style = "width:10%%"/><br/>
<field name = "customer_city" style = "width:10%%"/><br/>
<field name = "customer_state" style = "width:10%%"/><br/>
<field name = "customer_zip" style = "width:10%%"/><br/>
<field name = "customer_country" style = "width:10%%"/><br/>
<label for ="customer_mobile" string = "Mobile"/>
<field name = "customer_mobile" style = "width:10%%"/><br/>
<label for ="customer_mail" string = "Email"/>
<field name ="customer_mail" style = "width:10%%"/>
</form>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record model = "ir.actions.act_window" id = "action_custom">
<field name = "name">Custom</field>
<field name = "res_model">cus.custom</field>
<field name = "view_type">form</field>
<field name = "view_mode">tree,form</field>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lab Information" id = "menu_cus_custom" action = "action_custom"/>
</data>
</openerp>
python coding (cus.py)
from osv import osv
from osv import fields
class cus(osv.osv):
_name = "cus.custom"
_description = "This table is for keeping personal data of student"
_columns = {
'name': fields.char('Lab Id',size=64,required=True),
'customer_name': fields.many2one('res.partner', 'Customer'),
'customer_street1': fields.char('Street', size=64),
'customer_street2': fields.char('Street', size=64),
'customer_city': fields.char('City', size=64),
'customer_state': fields.char('State', size=64),
'customer_zip': fields.char('Zip', size=64),
'customer_country': fields.char('Country', size=64),
'customer_mobile': fields.char('Mobile', size=64),
'customer_mail': fields.char('Mail', size=64)
}
def on_change_customer(self, cr, uid, ids, customer_name, context=None):
values = {}
if customer_name:
cust = self.pool.get('res.partner').browse(cr, uid, customer_name, context=context)
values = {
'customer_country': cust.name
}
return {'value' : values}
update your xml file, no need to write label for each, try this
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record id="custom_tree" model="ir.ui.view">
<field name="name">Custom</field>
<field name="model">cus.custom</field>
<field name="arch" type="xml">
<tree string="custom">
<field name = "customer_name"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="custom_form" model="ir.ui.view">
<field name="name">cus.custom</field>
<field name="model">cus.custom</field>
<field name="arch" type="xml">
<form string="custom" version="7.0">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<group>
<field name = "customer_name" on_change="on_change_customer(customer_name)"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</group>
</form>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record id="action_custom" model="ir.actions.act_window">
<field name="name">Custom</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">cus.custom</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="custom_form"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lab Information" id = "menu_cus_custom" action = "action_custom"/>
</data>
</openerp>
You have wrote onchange on label because of that its not responding. Try this,
<label for = "customer_name" string = "Customer Name"/>
<field name = "customer_name" onchange="on_change_customer(customer_name)" style = "width:10%%"/><br/>
There is one another mistake you have made, improve field name in tree view,
<field name = "customer_country"/>
This will work.

Resources