how to hide create and edit button of form and tree view of lot/serial number for stock user in odoo10 - odoo-10

I want to create and edit the lot/serial numbers only for admin and stock manager not for user.
<record id = "view_stock_production_lot_tree_inherit" model="ir.ui.view">
<field name ="name">Stock Production Lot Inherit</field>
<field name ="model">stock.production.lot</field>
<field name ="inherit_id" ref ="stock.view_production_lot_tree"/>
<field name ="groups_id" eval = "[(4,ref('stock.group_stock_user'))]"/>
<field name ="arch" type = "xml">
<xpath expr ="//tree" position = "attributes">
<attribute name ="options">{'no_create_edit': True, 'no_create':True}</attribute>
<attribute name ="groups">stock.group_stock_user</attribute>
</xpath>
</field>
</record>
but it does not work!!

Try with:
<attribute name ="groups">!stock.group_stock_user,stock.group_stock_manager</attribute>
or set groups specifically to stock.group_stock_manager only
<attribute name ="groups">stock.group_stock_manager</attribute>

Related

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.

conditionally hide a button openerp/odoo

I have a button which I need to show only if the user is a superuser (admin). My problem is that when I'm using xpath to include the attrs, nothing is working as expected. My code is:
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_id" position="after">
<field name="is_superuser"/>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[#string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr="//button[#name='action_cancel']" position="attributes">
<attribute name="attrs">{'invisible':[('is_superuser','=', True)]}</attribute>
</xpath>
</field>
</record>
here, is_superuser is a computed field, its code is:
is_superuser = fields.Boolean(compute='_is_super_user')
def _is_super_user(self):
if self._uid == SUPERUSER_ID:
self.is_superuser = True
else:
self.is_superuser = False
The original code for the button, in its original view is:
<button name="action_cancel" states="draft,assigned,confirmed" string="Cancel Move" type="object"/>
any idea, what I'm doing wrong ? Thanks in advance.
I would prefer to use Odoo's group access system for such behaviour. Just extend the button with the attribute groups and ofcourse the correct group (for example base.group_system or base.group_no_one for admins):
<field name="action_cancel" states="draft,assigned,confirmed" position="attributes">
<attribute name="groups">base.group_system</attribute>
</field>
The code that you are using should work :
first you need to put #api.depends() on the method definition, without putting any field so it will be computed every time the record is called.
second check the result of the compute field doe's it work like it should because the xml code is correct use print in console to see if the code i working is the method gets called.
I really appreciate all your help, but the above responses does not helped me. However, I found the answer for this question. Since, it has states included, we need to take that into account as well. We need to override the behavior of 'states' tag as well. so the code needs to be:
<xpath expr="//button[#name='action_cancel']" position="attributes">
<attribute name="states"></attribute>
<attribute name="attrs">{'invisible':['|', ('is_superuser','=', False), ('state', 'not in', ('draft','assigned','confirmed'))]}</attribute>
</xpath>

Error while showing button for specific user (Admin) odoo 8

I've inherited a form view and made some modifications using xpath. I need a button in the header of form view to show only to admin user. But when I'm putting the groups, its giving following error :
Error details:
error_details
My code is:
<record id="wms_stock_view_move_form" model="ir.ui.view">
<field name="name">wms.stock.view.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_form" />
<field name="arch" type="xml">
<field name="location_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<field name="location_dest_id" position="attributes">
<attribute name="domain">[('name','!=', 'Scrapped')]</attribute>
</field>
<xpath expr='//form[#string="Stock Moves"]' position='attributes'>
<attribute name="create">false</attribute>
<attribute name="edit">false</attribute>
<attribute name="delete">false</attribute>
</xpath>
<xpath expr='//button[#name="action_cancel"]' position='attributes'>
<attribute name="invisible">True</attribute>
</xpath>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</field>
</record>
I have to guess which button you want to set new groups to, because your error relates to action_done but your own answer to action_cancel. So let me do this abstractly. You already have the answer in your question. Use XPath to "find" the button and use position="attributes":
<xpath expr="//button[#name='button_name']" position="attributes">
<attribute name="groups">module_name.group_id</attribute>
</xpath>
I eventually solved my own question, the solution is:
<xpath expr='//button[#name="action_done"]' position='replace'>
<button name="action_done" states="draft,assigned,confirmed" string="Process Entirely" type="object" class="oe_highlight" position="replace" groups="base.group_no_one"/>
</xpath>

how to add fields in inherited notebook/page/field

I have inherited 'sales order' from 'sales' module.
I need to add two extra fields inside 'Order Lines' tab.
.py
class SalesOrderInherit(models.Model):
_inherit = "sale.order"
type = fields.Selection([('appointment', 'Appointment'), ('walkin', 'Walk-In')], string="Type")
I need to add type field inside 'Order Lines' tab.
Which table should i inherit?
How to write to add above field.
Got Solution
<record id="inherit_sale_order_line" model="ir.ui.view">
<field name="name">inherit.sale.order.line.form.view</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="priority" eval="50" />
<field name="arch" type="xml">
<xpath expr="//field[#name='order_line']/tree/field[2]" position="after">
<field name="type"/>
</xpath>
</field>
</record>

Resources