How to display button when checkbox is true if both are from different models.? - odoo

I am trying to add custom settings in purchase order.
In that I am facing problem to link action of checkbox with button. I am trying to display a button when the checkbox in purchase settings is "True" if not then do not display.
Here's my code:
I am using wizard which inherits purchase.config.settings to add a checkbox "allow_settings"
class ConfigSettingsWizard(models.TransientModel):
_inherit = 'purchase.config.settings'
allow_settings = fields.Boolean("settings")
inherited_purchase_config_settings_views.xml:
<record id="inherited_purchase_config_settings_form_views" model="ir.ui.view">
<field name="model">purchase.config.settings</field>
<field name="inherit_id" ref="purchase.view_purchase_configuration"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='group_warning_purchase']" position="after">
<label string="Setting"/>
<div>
<field name="allow_settings" class="oe_inline"/>
<label for="allow_settings"/>
</div>
</xpath>
</field>
</record>
And a model "Mymodel" which inherit purchase.order
class MyModel(models.Model):
_inherit = 'purchase.order'
xml:
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[#name='button_cancel']" position="after">
<button name="add_button" string="Add" type="object" class="btn-primary" />
</xpath>
</field>
Both button and the checkbox are in different models and are inherited from different models.
Is there any way to get data from one model to another model?

Try below code.
class ConfigSettingsWizard(models.TransientModel):
_inherit = 'purchase.config.settings'
allow_settings = fields.Selection([(0, 'Not Visible'),(1, 'Make visible')],
"Settings", implied_group='your_module.group_name')
In xml file:
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[#name='button_cancel']" position="after">
<button name="add_button" string="Add" type="object" class="btn-primary" groups="your_module.group_name" />
</xpath>
</field>
Hope it will help you.

Related

How to do Prototpye inherit in odoo

i suppose I've not fully undrestood the prototype inheritance in Odoo.
I try to inherit crm.lead
The Model :
` class learn_odoo(models.Model):
_name = 'learn_odoo.learn_odoo'
_inherit = ['crm.lead']
_description = 'learn_odoo.learn_odoo'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id')
job = fields.Char()`
The View :
`<record id="view_inherit_list_crm" model="ir.ui.view">
<field name="name">Learn Odoo</field>
<field name="model">learn_odoo.learn_odoo</field>
<field eval="1" name="priority"/>
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="after">
<field name="job"/>
</xpath>
</field>
</record>
<record id="learn_odoo.action_window" model="ir.actions.act_window">
<field name="name">Learn Odoo</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">learn_odoo.learn_odoo</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
</p>
<p>
</p>
</field>
</record>`
The problem I encountered :
From your question, what i understood is you are trying to inherit crm.lead if i am right then please remove the _name = 'learn_odoo.learn_odoo'
you have to do as i am doing below:
class learn_odoo(models.Model):
_inherit = 'crm.lead'
tag_ids = fields.Many2many('mail.channel','mail_channel_profile_crm', 'partner_id', 'tag_id', string='Tag')
job = fields.Char('Job')
also in __manifest__.py file add crm in depends.
If you are not clear about inheritance please go through the odoo docs for inheritance from this Link for inheritance select your odoo version from top right corner for better results.

Odoo 10 adding field to sale order line

I am trying to code a module to provide a markup cell in each sale order line for quotes (Odoo 10). But I consistently get an error while loading the quote/sale order. Any help is welcomed.
This is the view:
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_markup model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
</field>
</record>
</odoo>
And the model:
# -*- coding: utf-8 -*-
from odoo import api, fields, models
import odoo.addons.decimal_precision as dp
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=False, readonly=True)
markup_per = fields.Float(compute='_compute_markup_per', digits=dp.get_precision('.2f%'), store=False, readonly=False)
#api.depends('price_unit', 'purchase_price')
def _compute_markup(self):
for record in self:
if record.price_unit and record.purchase_price:
record.markup = record.price_unit - record.purchase_price
#api.depends('price_unit', 'purchase_price')
def _compute_markup_per(self):
for record in self:
if record.purchase_price > 0:
record.markup_per = 100.0 * (record.price_unit - record.purchase_price) / record.purchase_price
#api.onchange('markup_per')
def _onchange_markup_per(self):
if self.markup_per:
if self.markup_per > -9999.99 and self.markup_per < 9999.99:
self.price_unit = self.purchase_price * (1 + self.markup_per / 100.0)
But I am getting this error when I open a quote/sales order:
Uncaught TypeError: Type is not a constructor
http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119
Traceback: TypeError: Type is not a constructor
at for_ (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119:1208)
at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:312
at Function..map..collect (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:13:270)
at _.(anonymous function) [as map] (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:69:526)
at Class.setup_columns (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:261)
at Class. (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2036:480)
at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2099:11
at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:3202:136)
at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:547:681)
at fire (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:541:299)
Just change your xml view like this.
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_markup model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="before">
<field name="markup" string="Markup"/>
<field name="markup_per" string="Markup (%)"/>
</xpath>
</field>
</record>
</odoo>
Remove <label> from tree view definition. Use attribute string to change label.
Try below code.
<record id="view_order_form_markup_model" model="ir.ui.view">
<field name="name">sale.order.form.markup</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[#name="order_line"]/form/group/group/field[#name="price_unit"]' position="before">
<label for="markup" string="Markup"/><field name="markup"/>
<label for="markup_per" string="Markup (%)"/><field name="markup_per"/>
</xpath>
<xpath expr='//field[#name="order_line"]/tree/field[#name="price_unit"]' position="after">
<field name="markup"/>
<field name="markup_per" string="Markup (%)"/>
</xpath>
</field>
</record>
Hope this will help you.

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>

How can I call a template from an inherited form view in Odoo 8

I am a beginner to Odoo 8.
I want to use the template (template id = "Variants") that is in the website_sale module in the form view of "Order lines" that has an external_id (ref="sale.view_order_form").
so I made inheritance like this:
<record id="multiple_variante_sale_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook/page/field/form/group/group/field[#name='product_id']" position="after">
-- here I want to call the template of the wesite_sale <template id="Variants" > --
</xpath>
</field>
Can I do this? If yes, how?

ODOO 8 on_change

Please I am facing somes problems with the new odoo 8 api, I have the following classes
class TypeProcessus(models.Model):
_name = 'atom.promaintenance.type.processus'
name = fields.Char()
id_phases = fields.One2many('atom.promaintenance.phases','id_processus','Liste des Phases')
class Phases(models.Model):
_name = 'atom.promaintenance.phases'
name = fields.Char()
autoriserCommentaire = fields.Boolean()
autoriserPiecesJointes = fields.Boolean()
id_processus = fields.Many2one('atom.promaintenance.type.processus')
parent_id = fields.Many2one('atom.promaintenance.phases','Phase Parent', select=True, ondelete='cascade')
commentaire = fields.Text()
#api.one
#api.onchange('name')
def phases_write(self):
print 'test'
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<tree string="note_evaluation_tree" editable="bottom">
<field name="id_phases" />
</tree>
</sheet>
</form>
</field>
</record>
First of all my problem is when Creating a new Processus, and adding phases, there is a relation parent child between phases and the drop down list for parent stay empty unless u save the processus to make them available.
i managed to add onChange event to the phases to persist them to database but i can't figure out how to save those records with the new api system, thank you
If you mean what I understand, you need to use the widget one2many_list in the XML code, which by the way, I think is wrong. It should be something like this:
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<field name="id_phases" widget="one2many_list">
<tree string="note_evaluation_tree" editable="bottom">
<field name="name"/>
<field name="autoriserCommentaire"/>
<field name="autoriserPiecesJointes"/>
<field name="parent_id"/>
<field name="commentaire"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
The widget will allow you to add phases for a processus and then save it.
The new API uses self for all the record modifications. So in your case, if you want to change the name, write like this:
#api.one
#api.onchange('name')
def onchange_name(self):
self.name = 'what you want to save'