odoo many2many show selection Odoo10 - odoo

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>

Related

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

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.

proper way to replace view form

I need to override account.account_aged_balance_view in order to hide a field (Period Length (days)) as well add new field in the same time.
I tried the following in my custom module view:
<openerp>
<data>
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<form string="Report Options">
<separator string="Aged Partner Balance"/>
<label string="Dariel Partner Balance is a more detailed report of your receivables by intervals. When opening that report, Odoo asks for the name of the company, the Start Date and the size of the interval to be analyzed (in days). Odoo then calculates a table of credit balance by start Date. So if you request an interval of 30 days Odoo generates an analysis of creditors for the past month, past two months, and so on. "/>
<group col="4">
<field name="date_from"/>
<newline/>
<field name="result_selection" widget="radio"/>
<field name="target_move" widget="radio"/>
</group>
<field name="journal_ids" required="0" invisible="1"/>
</form>
</field>
</record>
</data>
</openerp>
those XML appended to the modal form instead of replacing the original form, like shown in the image.
so, am I doing it right (ofcourse it's not right) or how the proper way of doing it?
You can both replace the whole form view or remove and add only the fields you want. You have to use the xpath to do that.
To replace the whole view:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//form' position='replace'>
< your form view >
</xpath>
</field>
</record>
Or you can remove only what you don't want and add what you want with:
<record id="account_aged_balance_view" model="ir.ui.view">
<field name="name">Aged Partner Balance</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr='//field[#name="period_length"]' position='replace'/>
<xpath expr='//field[#name=" < name of the field you want to put yours after > "]' position='after'>
<field name=' < your field name > '/>
</xpath>
</field>
</record>
I did not try it, but it should work.

Odoo v9: choose view for "create and edit"

I'm using Odoo 9.
How can I set the view used when the user clicks on "create and edit" in a Many2one field?
Create new view for model. Here example for crm.team:
<record id="test_my" model="ir.ui.view">
<field name="name">my.module.form</field>
<field name="model">crm.team</field>
<field name="arch" type="xml">
<form>
<field name="name"/>
</form>
</field>
</record>
And set id of view using context:
<!-- many2one field -->
<field name="team_id" context="{'form_view_ref':'my_module.test_my'}"/>

Can't remove top "Save" button from 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.

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'