odoo graph view measure are not displayed - view

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)

Related

Odoo: How to count in Tree View when group_by?

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

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 - Filter child records in parent class

I am using Odoo 10-e. I am working on a sample module.
I have 5 models (customer, product, order, order details, movement)
Customer :
class Customer(models.Model):
_name ="amgl.customer"
…… all other fields related to customer
product_ids = fields.Many2many('amgl.products', string='Products')
Products :
class Products(models.Model):
_name ="amgl.products"
…… all other fields related to product
customer_ids = fields.Many2many('amgl.customer', string='Customers')
Order :
class Order(models.Model):
_name ="amgl.order"
order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines')
…… all other fields related to Order
Order Details :
class OrderLine(models.Model):
_name = 'amgl.order_line'
order_id = fields.Many2one('amgl.order', string='Orders')
products = fields.Many2one('amgl.products', string="Products")
…… all other fields related to order details
Movement
class Movement(models.Model):
_name = 'amgl.metal_movement'
customer = fields.Many2one("amgl.customer", string="Customer", required=True)
order_lines = fields.One2many('amgl.order_line','metal_movement_id')
…… all other fields related to movement
What i am trying to do is, i am creating a movement form in which user will select a customer from customer drop down first then user will add order_lines and in that he will be able to add products i want to filter products which are associated with above selected customer . How can i do that ? I have been trying since last month.
Movement View
<odoo>
<data>
<record id="action_metal_movement" model="ir.actions.act_window">
<field name="name">Metal Movement Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">metal.movement</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create
</p><p>
<!-- More details about what a user can do with this object will be OK -->
</p>
</field>
</record>
<record id="form_metal_movement" model="ir.ui.view">
<field name="name">Metal Movement Request </field>
<field name="model">metal.movement</field>
<field name="arch" type="xml">
<form string="Metal Movement">
<sheet>
<group>
<group string="Metal Movement Request">
<field name="date_create" string="Date Created"/>
<field name="reference"/>
<field name="metal_movement_type"/>
<field name="first_approve"/>
<field name="second_approve" domain="[('id', '!=', first_approve)]"/>
<field name="customer"/>
<field name="sepcial_instruction" widget="html"/>
</group>
<group string="Metal Movement From">
<group colspan="6">
<field name="custodian"/>
<field name="mmf_name"/>
<field name="mmf_account_number"/>
<field name="mmf_account_type"/>
</group>
<group string="Metal Movement To" colspan="6">
<field name="mmt_name"/>
<field name="mmt_address" attrs="{'invisible':[('metal_movement_type', '=', 'IT')]}"/>
<field name="mmt_account_number" />
<field name="mmt_company" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU','IT'))]}"/>
<field name="pickup_date" string="Pick up Datetime" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU'))]}"/>
</group>
</group>
<group string="Metals To Be Moved" colspan="12">
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" domain="[('customer_ids','in', parent.customer)]" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
</group>
</group>
</sheet>
</form>
</field>
</record>
</data>
</odoo>
Thank you for updation of question.
First add customer in product field context.
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" context="{'customer_id':parent.customer}" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
Then in product's model write it's name_get method like this.
#api.multi
def name_get(self):
if self.env.context('customer_id',False):
customer = self.env['amgl.customer'].browse(self.env.context('customer_id',False))
for product in customer.product_ids:
res.append((product.id,product.name))
else:
res=super(product_product,self).name_get()
return res
Thats it.

The states of a model for the Workflows in Odoo

I am trying to implement Odoo publishing workflows for my custom model 'product_images.product_image'.
My models look like this:
# product_images/models/models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api, tools
class PublishingStatus(models.Model):
_name = 'product_images.publishing_status'
_description = 'Publishing status'
name = fields.Char(string="Name")
slug = fields.Char(string="Slug")
class ProductImage(models.Model):
_name = 'product_images.product_image'
_description = 'Product image'
name = fields.Char(string="Alternative text")
product_id = fields.Many2one('product.product', string='Product', ondelete='set null', index=True)
original_image = fields.Binary(string='Original image')
#api.model
def _get_default_state(self):
return self.env['product_images.publishing_status'].search([['slug', '=', 'draft']])
#api.model
def _get_all_states(self, groups, domain, order):
state_ids = self.env['product_images.publishing_status'].search([])
return state_ids
state_id = fields.Many2one(
'product_images.publishing_status',
string='Publishing status',
default=_get_default_state,
group_expand='_get_all_states',
)
#api.multi
def action_set_to_draft(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'draft']])
#api.multi
def action_request_for_approval(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'pending']])
#api.multi
def action_approve(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'approved']])
#api.multi
def action_reject(self):
self.state_id = self.env['product_images.publishing_status'].search([['slug', '=', 'rejected']])
Then I have some data records for the publishing statuses:
<!-- product_images/data/data.xml -->
<odoo>
<data>
<!-- explicit list view definition -->
<record model="product_images.publishing_status" id="product_images.publishing_status_draft">
<field name="name">Draft</field>
<field name="slug">draft</field>
</record>
<record model="product_images.publishing_status" id="product_images.publishing_status_pending">
<field name="name">Pending</field>
<field name="slug">pending</field>
</record>
<record model="product_images.publishing_status" id="product_images.publishing_status_approved">
<field name="name">Approved</field>
<field name="slug">approved</field>
</record>
<record model="product_images.publishing_status" id="product_images.publishing_status_rejected">
<field name="name">Rejected</field>
<field name="slug">rejected</field>
</record>
</data>
</odoo>
I also have some records to create a workflow which allows to switch between the publishing statuses:
<odoo>
<data>
<record model="workflow" id="product_images.wkf_image_publishing">
<field name="name">Product Image Publishing Workflow</field>
<field name="osv">product_images.product_image</field>
<field name="on_create">True</field>
</record>
<record model="workflow.activity" id="product_images.wkf_activity_draft">
<field name="name">Draft</field>
<field name="wkf_id" ref="product_images.wkf_image_publishing" />
<field name="flow_start" eval="True" />
<field name="kind">function</field>
<field name="action">action_set_to_draft()</field>
</record>
<record model="workflow.activity" id="product_images.wkf_activity_pending">
<field name="name">Pending</field>
<field name="wkf_id" ref="product_images.wkf_image_publishing" />
<field name="kind">function</field>
<field name="action">action_request_for_approval()</field>
</record>
<record model="workflow.activity" id="product_images.wkf_activity_approved">
<field name="name">Approved</field>
<field name="wkf_id" ref="product_images.wkf_image_publishing" />
<field name="flow_stop" eval="True" />
<field name="kind">function</field>
<field name="action">action_approve()</field>
</record>
<record model="workflow.activity" id="product_images.wkf_activity_rejected">
<field name="name">Rejected</field>
<field name="wkf_id" ref="product_images.wkf_image_publishing" />
<field name="flow_stop" eval="True" />
<field name="kind">function</field>
<field name="action">action_reject()</field>
</record>
<record model="workflow.transition" id="product_images.wkf_transition_draft_to_pending">
<field name="act_from" ref="product_images.wkf_activity_draft" />
<field name="act_to" ref="product_images.wkf_activity_pending" />
<field name="condition">name != "" and original_image != ""</field>
<field name="signal">pending</field>
</record>
<record model="workflow.transition" id="product_images.wkf_transition_pending_to_draft">
<field name="act_from" ref="product_images.wkf_activity_pending" />
<field name="act_to" ref="product_images.wkf_activity_draft" />
<field name="signal">draft</field>
</record>
<record model="workflow.transition" id="product_images.wkf_transition_pending_to_approved">
<field name="act_from" ref="product_images.wkf_activity_pending" />
<field name="act_to" ref="product_images.wkf_activity_approved" />
<field name="signal">approve</field>
</record>
<record model="workflow.transition" id="product_images.wkf_transition_pending_to_rejected">
<field name="act_from" ref="product_images.wkf_activity_pending" />
<field name="act_to" ref="product_images.wkf_activity_rejected" />
<field name="signal">reject</field>
</record>
</data>
</odoo>
And now the tickiest part! I need a form with the buttons to switch between workflow states and a status bar showing the currently active status. This is what I tried:
<record model="ir.ui.view" id="product_images.form">
<field name="name">Product Image</field>
<field name="model">product_images.product_image</field>
<field name="arch" type="xml">
<form>
<header>
<!--
<button name="draft"
type="workflow"
string="Set to draft"
attrs="{'invisible': [('state_id.slug','not in',['pending'])]}"
/>
<button name="pending"
type="workflow"
string="Request for approval"
attrs="{'invisible': [('state_id.slug','not in',['draft'])]}"
/>
<button name="approve"
type="workflow"
string="Approve"
attrs="{'invisible': [('state_id.slug','not in',['pending'])]}"
class="oe_highlight"
/>
<button name="reject"
type="workflow"
string="Reject"
attrs="{'invisible': [('state_id.slug','not in',['pending'])]}"
class="oe_highlight"
/>
-->
<field name="state_id" widget="statusbar" />
</header>
<sheet>
<group>
<field name="product_id" />
<field name="name" string="Alternative text" />
<field name="original_image" widget="image" class="oe_avatar" />
<field name="state_id" />
</group>
</sheet>
</form>
</field>
</record>
The problems I got:
The status bar is shown, but the current publishing status is not activated.
If I uncomment the buttons, they throw an error about invalid domain:
Uncaught Error: Unknown field state_id.slug in domain
[["state_id.slug","not in",["pending"]]]
What am I missing?
In domain attribute, we can not use parent field in left hand side. In your case, we need to add related field.
For example:
class ProductImage(models.Model):
_name = 'product_images.product_image'
slug = fields.Char(related='state_id.slug', string='Slug', store=True)
Put slug field after state_id in your view file
<field name="slug" invisible="1"/>
Now uncomment <button> codes.
Afterwards, restart Odoo server and upgrade your custom module.

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