Customer Invoice validate button - odoo

I have created a button named 'Confirm' in customer invoice. When i click 'Confirm' button 'state1' will be 'confirmed'. I want to hide Validate button when 'state1'='draft' and show the Validate button when 'state1'='confirmed'. I tried below code but it is not working. Can anyone help me?
<!-- inherit account invoice form -->
<record id="invoice_form_inheritai" model="ir.ui.view">
<field name="name">account.invoice.form.inheritai</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="invoice_print" position="after">
<field name="state1" invisible="1"/>
<button name="invoice_check" string="Confirm" type="object" attrs="{'invisible': [('state1','not in', ['draft'])]}" class="oe_highlight" groups="base.group_user"/>
</button>
<button name="invoice_open" position="replace">
<button name="invoice_open" state="draft" string="Validate" attrs="{'invisible': [('state1','!=', ['confirmed'])]}" groups="base.group_user"/>
</button>
</field>
</record>

<button name="invoice_open" string="Validate" attrs="{'invisible': [('state1','not in', ['confirmed']),('state','not in',['draft'])]}" groups="base.group_user"/>
Please avoid using both invisible attribute and states.

Try using 'states' instead of 'state'. And even attr won't be required. It will work automatically. Ex:
<button name="invoice_open" states="confirmed" string="Validate" groups="base.group_user"/>

Related

Place button in one2many field tree view

I want to add button in one2many tree view line. I have placed button in tree view and these button shows successfully.
But when i click on button, it display form define against one2many field instead of function call.
Need guidance how to call function/form on button click.
<page name="component_line_id" string="Component Lines">
<field name="component_line_id">
<tree>
<field name="purchase_order_id" required="1"/>
<field name="description"/>
<field name="payable_amount"/>
<field name="file_name" string="Attachment"/>
<button string="Create Bill" name="create_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
<button string="View Bill" name="view_bill" type="object" class="oe_highlight" icon="fa-icon_you_like"/>
</tree>
<form string="Component Lines">
<group>
<group>
<field name="purchase_order_id"/>
<field name="description"/>
<field name="payable_amount"/>
</group>
<group>
<field name="attachment_file" filename="file_name"/>
<field name="file_name" invisible="1"/>
</group>
</group>
</form>
</field>
</page>
I think you need to save the record first to be able to run the button. Are you sure it was not on edit mode?

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.

Odoo - Show a Overdue Balance Smart button in Res.partner(Customer View)

I want to show amount overdue of customer of all invoices in a smart button in Customer View of sales module. I have already developed a smart button same as Invoiced smart button in Customer View for just a start. But it not showing the same amount as that of Invoiced Button(always shows 0).
Copied this code in my custom module from partner.view in account
<record model="ir.ui.view" id="partner_view_buttons">
<field name="name">partner.view.buttons</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="priority" eval="20"/>
<field name="groups_id" eval="[(4, ref('account.group_account_invoice'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button type="action"
class="oe_stat_button"
id="invoice_button"
icon="fa-pencil-square-o"
name="%(account.action_invoice_refund_out_tree)d"
attrs="{'invisible': [('customer', '=', False)]}"
context="{'search_default_partner_id': active_id,'default_partner_id': active_id}">
<div class="o_form_field o_stat_info">
<span class="o_stat_value"><field name="total_invoiced" widget='monetary' options="{'currency_field': 'currency_id'}"/></span>
<span class="o_stat_text">Invoiced</span>
</div>
</button>
</div></field>
</record>
Should I write this(account.action_invoice_refund_out_tree) action also in my module? or will it be called automatically?

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.

OpenERP tree view

I want to replace one of the defaults buttons in treeview header by one with a funcionality made by my... I try using xpath in this way but not worked
<field name= "types_id" colspan="8" nolabel="1">
<tree options='{"deletable": false, "addable":null, "isClarkGable": false}'>
<field name="type_id"/>
<field name="fundamentation"/>
<xpath expr="//tree/button[#string='Add']" position="replace">
<button name="button_cancel" string="Mark to Cancel" type="object" icon="gtk-cancel"/>
</xpath>
</tree>
</field>
The option you are using is for field not for the tree tag. so your xml will be like,
<field name= "types_id" colspan="8" nolabel="1" options='{"deletable": false, "addable":null}'>
<tree delete="false" string='YOUR STRING'>
<field name="type_id"/>
<field name="fundamentation"/>
<xpath expr="//tree/button[#string='Add']" position="replace">
<button name="button_cancel" string="Mark to Cancel" type="object" icon="gtk-cancel"/>
</xpath>
</tree>
</field>