0% found this document useful (0 votes)
445 views

Smartbuttons Odoo

Smart Buttons in v8 allow buttons in Odoo to be dynamic and customizable. They can contain any HTML or Odoo widget content within the button tag. This makes buttons more informative by displaying fields, charts, or other elements. Developers can customize the look of Smart Buttons and the dynamic content displayed by adding fields and widgets. Common uses include displaying aggregate field values or trend charts directly on a button to provide more context before initiating an action.

Uploaded by

Hendra So
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
445 views

Smartbuttons Odoo

Smart Buttons in v8 allow buttons in Odoo to be dynamic and customizable. They can contain any HTML or Odoo widget content within the button tag. This makes buttons more informative by displaying fields, charts, or other elements. Developers can customize the look of Smart Buttons and the dynamic content displayed by adding fields and widgets. Common uses include displaying aggregate field values or trend charts directly on a button to provide more context before initiating an action.

Uploaded by

Hendra So
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Smart Buttons in v8

Gry Debongnie
Content
1. What are Smart Buttons?
2. From Regular Buttons to Smart Buttons
3. Magic! (not really)
4. Customizing the Look
5. Customizing the Content
What are Smart Buttons?
Smart Buttons
Smart Buttons (2)
From From
To To
Smart Buttons (3)
Two biggest advantages:
dynamic,
customizable.

From Regular to Smart


it's not hard
Converting a plain button

Before:
<button <button class="oe_inline" type="action"
string="Opportunities"
name="..." context="..."/> />
After:
<button <button class="oe_inline oe_stat_button" type="action"
string="Opportunities"
name="..." context="..."/> />
Converting a plain button (2)
Just add 'icon' attribute.
<button <button class="oe_inline oe_stat_button" type="action"
string="Opportunities"
icon="fa-star"
name="..." context="..."/> />
Font awesome:
http://fortawesome.github.io/Font-Awesome/
Where is the magic?
(next slide)
Button tag can contain
anything
Before, the button tag was self-closed:
<button/> <button/>
Now, it can contain literally anything:
<button> <button>
literally anything
</button> </button>
The form view parse the button and render anything inside
(html/Odoo widgets)
Example (html)
Pure html : Full control on the content
<button <button class="..." type="..." name="..." context="...">>
<p> <p>Hello <strong> <strong>Odoo</strong></p> </strong></p>
</button> </button>
Result:
Example (html+eld)
<button <button class="..." type="..." name="..." icon="fa-star">>
<span><field <span><field name="opportunity_count"/> /> Opportunities</span> </span>
</button> </button>
Result:
This is fully dynamic!
Common situation:
One2many elds
Example: phonecall_ids in res.partner.
Step 1: add functional !eld phonecall_count to res.partner
Step 2: add !eld with widget 'statinfo'
<button <button class="..." type="..." name="..." icon="..." context="...">>
<field <field string="Calls" name="phonecall_count" widget="statinfo"/> />
</button> </button>
Customize your buttons
We can customize in two ways:
Customizing Content
Case study: Sum of all
invoices for a customer
1. add functional !eld
'total_invoiced':: fields..function((_invoice_total,,
string=="Total Invoiced",,
type=='float'))
def def _invoice_total((self,, cr,, uid,, ids,, field_name,, arg,, context==None): ):
result == {} {}
account_invoice_report == self..pool..get(('account.invoice.report'))
for for partner in in self..browse((cr,, uid,, ids,, context==context): ):
... ...
return return result
Case study: Sum of all
invoices for a customer (2)
2. add !eld to button
<button <button type="action" class="oe_stat_button"
icon="fa-pencil-square-o" name="..." context="..." >>
<field <field name="total_invoiced" widget="statinfo"/> />
</button> </button>
3. pro!t!
Customizing Look
PercentPie Widget
Percentage (integer between 0 and 100)
<button <button name="..." type="action" class="oe_stat_button">>
<field <field name="received_ratio"
string="Received"
widget="percentpie"/> />
</button> </button>
Bar Chart Widget
Need to display some kind of trends? Use BarChart Widget!
<button <button name="..." type="action" class="oe_stat_button">>
<field <field name="opened_daily"
string="Opened Daily"
widget="barchart"/> />
</button> </button>
(see mass_mailing.py for full details)
Thank you!

You might also like