How can I make an invoice from custom module ?? I know I need to make Create method for invoice but where to put that method ?? I am beginner in odoo - odoo

This is my Custom Module :
When I Click on Create invoice button it shows wizard as shown below :
But when I try to Create regular invoice it shows error :
I Changed the invoicing policy of product from "delivered quantities" to "ordered quantities" but still it throws same error.
xml code adding buttons :
<header>
<button name="action_draft" string="Draft" type="object" data-hotkey="r"/>
<button name="action_in_progress" string="In Progress" type="object" data-hotkey="p"/>
<button name="action_done" string="Done" type="object" states="in_progress"/>
<button name="action_cancel" string="Cancel" type="object" data-hotkey="x"/>
<field name="state" widget="statusbar" nolabel="1"/>
<button name="331" string="Create Invoice" type="action" data-hotkey="x" states="done"/>
</header>

You need to create a python function that does it and then to call that function by naming a button as your function.
Odoo tutorial explaining how to proceed
Code example about how to create an account.move
Don't forget to add taxes if you need to.

Related

How to add a new button inside the action menu Odoo 12?

Im trying to add a button inside the action in the model named 'consultation', After clicking the button i need to open up the wizard i created follow,But im stuck in some errors
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="specialist_no_show" model="ir.ui.view">
<field name="name">specialist no show</field>
<field name="model">specialist.no.show</field>
<field name="arch" type="xml">
<form string="No Show">
<group>
<group>
<field name="partner_id" readonly="1"/>
</group>
</group>
<footer>
<button name="update_no_show" string="Confirm" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
<act_window name="No Show"
id="specialist_no_show"
res_model="specialist_no_show" #model created for the wizard
binding_model="consultation" #model where i want to show the button in the action
binding_views="form"
view_mode="list"
target="new"
/>
</odoo>
I can spot some problems that you can try:
The XML ID for the form and the act_window must be different. In your example it is both specialist_no_show
The res_model must be specialist.no.show
The structure for the act_window is different depending on your Odoo Version (see below).
For Odoo Version 12.0
<act_window name="No Show"
id="action_specialist_no_show"
res_model="specialist.no.show"
src_model="consultation"
view_mode="form"
target="new"
/>
For Odoo Version 13.0
<act_window name="No Show"
id="action_specialist_no_show"
res_model="specialist.no.show"
binding_model="consultation"
view_mode="form"
target="new"
/>
Also, the error logs would be helpful as #Kenly suggested. Always post those.

how hide button if have same name with different field based on user selection

For example below mentioned code
<button name="invoice_recreate" string="Recreate Invoice"/>
<button name="invoice_corrected" string="Ignore Exception" />
Add the field selection to the view and the attrs attribute to the button like this:
<field name="selection_field" invisible="1" />
<button name="invoice_recreate"
string="Recreate Invoice"
attrs="{'invisible': [('selection_field', '=', 'value')]}" />
<button name="invoice_corrected"
string="Ignore Exception"
attrs="{'invisible': [('selection_field', '!=', 'value')]}" />
I am not sure if this is what you are asking for, let me know if you are asking anything different

How can I change boolean_button terminology?

I have defined a button with the boolean_button widget
<button name="toggle_enable" type="object" class="oe_stat_button" icon="fa-unlink">
<field name="enabled" widget="boolean_button" options='{"terminology": "active"}'/>
</button>
I've tried to change the terminology to Exported / Not exported but I have not succeeded. Can someone tell me if it is possible to define a new terminology?
In Odoo v10, you can do it as following :
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-check-square" >
<field name="active" widget="boolean_button" options='{"terminology": {
"string_true": "Production Environment",
"hover_true": "Switch to test environment",
"string_false": "Test Environment",
"hover_false": "Switch to production environment"
}}'/>
</button>
</div>
But in Odoo v9, by default it is not there.

Perform "actions" in status bar widget

I have a field with a status bar widget, and I want if I press a button in the statusbar a function is launched, (something like onchange), some help??
You can use directly the onchange or you can extend the statusbar widget.
Try this:
xml file
<button name="action_draft" type="object"
string="Reset to draft"
states="confirm"/>
<button name="action_confirm" type="object"
string="Confirm" states="draft"
class="oe_highlight"/>
<field name="state" widget="statusbar"/>
.py file
def action_draft(self):
self.state = 'draft'
def action_confirm(self):
self.state = 'confirm'

Display a simple message box

How to display a simple message box inside method of a button at the user click.
When the user click on the button he see a message box.
If you just want to show a message box before executing the button function then you need to add an attribute conform in your button xml tag. For example
<button name="button_process" string="Proceed" confirm="Do you want to proceed?" type="object" class="oe_highlight"/>
When user click on this button Proceed a dialog box will be showed with message "Do you want to proceed?", when you click ok on that dialog box, then only the button_process will be executed.
I have Just Add small method in .py file and generate the message box on button click
XML File
<record id="view_hr_payroll_payslip_wizard" model="ir.ui.view">
<field name="name">hr.payroll.payslip.wizards</field>
<field name="model">hr.payroll.payslip.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="moves" version="7.0">
<footer>
<button name="generate_msg" string="Click To Me" type="object" class="oe_highlight"/>or
</footer>
</form>
</field>
</record>
same name of method are define in my button name attribute in my .py file
from openerp.tools.translate import _
def generate_msg(self, cr, uid, ids, context=None):
raise osv.except_osv(_("Warning!"), _(" Hello Mehdi Mokni !!."))
python Library can be added for covert your message in your Language
I hope this should helpful for you ..:)