Can't remove top "Save" button from Odoo - odoo

I want to remove the top "Save" button from the formview of my custom module.
I know that we perform this by setting write/create to false in the XML, which I did and can't figure out why it is still there.
My view:
<record id="view_module_genall_form" model="ir.ui.view">
<field name="name">module.genall.form</field>
<field name="model">module.genall</field>
<field name="arch" type="xml">
<form string="Automatically generate bills" edit="false" create="false" delete="false" write="false">
<button name="generate_all" type="object" string="Generate bills" icon="oe_highlight"/>
</form>
</field>
</record>
The related action:
<record model="ir.actions.act_window" id="action_module_genall">
<field name="name">Automatically generate bills</field>
<field name="res_model">alkivi.genall</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_module_genall_form" />
</record>
Do you have an idea ? Thanks!

From it's title it looks like the purpose of your form is to run a server method to perform some business logic.
For that you should use a Wizard instead of a regular Model: for that the module.genalshould be a models.TransientModel instead of a models.Model.

Related

How to edit invoice template on Odoo15

I created custom fields in Odoo v15.
PROBLEM
Now I would like to add them to invoice template.
How I could do it?
You need to inherit the form view (account.invoice.form) and add your custom fields to the view. Or if you want to test the view you can enable debug mode and click "Edit FormView" at the top right of your form view to (temporarily) edit the form view directly.
See my example below:
<record id="account_invoice_form_custom" model="ir.ui.view">
<field name="name">account.invoice.form.custom</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="custom_field"/>
</field>
</field>
</record>

odoo many2many show selection Odoo10

we have a list of items in one model named us_inventory_line. We have another model named ladings...
class inventory_line(models.Model):
# ...
lading_item = fields.Many2one('res.lading', ondelete='set null', string="lading", index=True)
class Lading(models.Model):
# ...
us_inventory_line_item = fields.One2many(comodel_name='rodals.us_inventory_line', string="shippments", inverse_name='lading_item')
In the form, we have just simply put the field that represent one2many:
<!-- Form -->
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item"/>
</group>
</sheet>
</form>
</field>
</record>
When the application is opened, when the user opens the lading page, he is only able to add new us_inventory_line.
How do we go about in order to connect the tow ? Like the user need to choose, from a list of us_inventory_line that does not have a lading (because if its has lading, this means that its already shipped).
Thank you very much for the help !
<record model="ir.ui.view" id="us_inventory_line_form_view">
<field name="name">lading.form</field>
<field name="model">rodals.lading</field>
<field name="arch" type="xml">
<form string="Invetory Line Form">
<sheet>
<group>
<field name="delivery_date"/>
<field name="us_inventory_line_item">
<tree string="US Inventory Item">
<field name="lading_item"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>

Open parent model with event_open_popup

I've got two models : maintenance.intervention and maintenance.intervention.task
In model intervention, there's a One2many relation toward task.
When I display the tasks in calendar view and click on one of them, instead of opening a form view for the task model, I'd like to open the form view of parent intervention. (In edition mode if possible)
The field with the parent id is "intervention_id".
Q1 : Is it possible ?
Q2 : How to do it ?
The code below opens the correct view, but doesn't have the data needed.
<record id="view_maintenance_intervention_tasks_calendar" model="ir.ui.view">
<field name="name">maintenance.intervention.tasks.calendar</field>
<field name="model">maintenance.intervention.task</field>
<field eval="2" name="priority"/>
<field name="arch" type="xml">
<calendar color="user_id" date_start="date_start" date_stop="date_end" string="Task" quick_add="False"
event_open_popup="%(module.views_maintenance_intervention_form)s">
<field name="hour_to"/>
<field name="technician"/>
<field name="client_name"/>
<field name="installation_zip"/>
<field name="installation_city"/>
<field name="intervention_type"/>
<field name="name"/>
<field name="intervention_code"/>
<field name="intervention_id" invisible="1"/>
</calendar>
</field>

How to hide fields based on condition in odoo?

I have created few custom fields for products.Products appear in sales,purchase,warehouse and manufacturing module.I want to make my custom fields appear only in manufacturing module and hide everywhere else.So how to put condition on invisible attribute.I tried like this and got error as Unknown field _name in domain
attrs="{'invisible': [('_name', '!=', 'mrp.bom')]}"
Python file,
from openerp import fields,models, api
class product_template(models.Model):
_inherit = "product.template"
rim_weight = fields.Float(string='Rim Weight(KG)', readonly=True, compute='_compute_one_rim_weight')
width = fields.Float(string='Width(cm)',default='50')
length = fields.Float(string='Length(cm)',default='63')
gsm = fields.Float(string='Gram per square meter(gsm)',default='230')
Xml file,
<record id="product_template_form_view_dis_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.dis.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#string='Accounting']" position='after'>
<page string='Cover Page Paper'>
<group>
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
</group>
</page>
</xpath>
</field>
</record>
There are many ways to do this, however I suggest following options to you.
Modify an existing action and set context inside that and based on that context just write condition in view. (Remember here you need to override an action, and if you want to create another then you need to redefine menu to assign new action to that menu).
Create new view and set this view reference in an action of that model in which you want to show these fields. In new view you need to visible those fields, no need to extend product template existing view.
However the 1st solution is easy to achieve and 2nd one is lengthy.
Example of 1st solution:
<record id="action_name" model="ir.actions.act_window">
<field name="name">Name</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context" eval="{'is_manufacturing_model':True}" />
</record>
And then in view just write like this
<page string='Cover Page Paper'>
<group invisible="context.get('is_manufacturing_model',False)">
<field name="width"/>
<field name="length"/>
<field name="gsm"/>
<field name="rim_weight"/>
<group>
</page>

Passing active_id to action window in openerp7

I building a custom module in openerp version 7. I'm facing problems in trying to link an anchor tag in a kanban view item to an action window which will open the clicked on item in a form view.
Here's a sinppet of the kanban view
<a type="action" name="myaction">
<img t-att-src="kanban_image('vessel', 'image_medium', record.id.value)" class="oe_employee_picture" />
</a>
Here's the action that will be invoked on click
<record model="ir.actions.act_window" id="myaction">
<field name="name">Vessel</field>
<field name="res_model">vessel</field>
<field name="view_type">form</field>
<field name="view_id" ref="crew_management.view_crew_management_vessels_form"/>
<field name="view_mode">form</field>
<field name="context">{'id': active_id}</field>
</record>
Currently when clicking on the link it opens the correct form view but empty. It seems that the active id of the selected item is not passed somehow.
To pass the active id of an object use res_id instead.
<field name="context">{'res_id': active_id}</field>
The complete code would be
<a type="action" name="action_id">
<!-- Anything Here -->
</a
<record model="ir.actions.act_window" id="action_id">
<field name="name">demo</field>
<field name="res_model">demo</field>
<field name="view_type">form</field>
<field name="view_id" ref="my_module.demo_view_id"/>
<field name="view_mode">form</field>
<field name="context">{'res_id': active_id}</field>
</record>
try passing <field name="context">{'active_id': active_id}</field>