+ All Categories
Transcript
Page 1: Odoo - Smart buttons

Smart Buttons in v8Géry Debongnie

Page 2: Odoo - Smart buttons

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

Page 3: Odoo - Smart buttons

What are Smart Buttons?

Page 4: Odoo - Smart buttons

Smart Buttons

Page 5: Odoo - Smart buttons

Smart Buttons (2)

FromFrom

ToTo

Page 6: Odoo - Smart buttons

Smart Buttons (3)

Two biggest advantages:

dynamic,

customizable.

·

·

Page 7: Odoo - Smart buttons

From Regular to Smartit's not hard

Page 8: Odoo - Smart buttons

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="..."/>/>

Page 9: Odoo - Smart buttons

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/

Page 10: Odoo - Smart buttons

Where is the magic?(next slide)

Page 11: Odoo - Smart buttons

Button tag can containanything

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)

Page 12: Odoo - Smart buttons

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:

Page 13: Odoo - Smart buttons

Example (html+field)<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!

Page 14: Odoo - Smart buttons

Common situation:One2many fields

Example: phonecall_ids in res.partner.

Step 1: add functional field phonecall_count to res.partner

Step 2: add field with widget 'statinfo'

<button<button class="..." type="..." name="..." icon="..." context="...">> <field<field string="Calls" name="phonecall_count" widget="statinfo"/>/></button></button>

Page 15: Odoo - Smart buttons

Customize your buttons

We can customize in two ways:

Page 16: Odoo - Smart buttons

Customizing Content

Page 17: Odoo - Smart buttons

Case study: Sum of allinvoices for a customer

1. add functional field

'total_invoiced':: fields..function((_invoice_total,, string=="Total Invoiced",, type=='float'))

defdef _invoice_total((self,, cr,, uid,, ids,, field_name,, arg,, context==None):): result == {}{} account_invoice_report == self..pool..get(('account.invoice.report')) forfor partner inin self..browse((cr,, uid,, ids,, context==context):): ...... returnreturn result

Page 18: Odoo - Smart buttons

Case study: Sum of allinvoices for a customer (2)

2. add field 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. profit!

Page 19: Odoo - Smart buttons

Customizing Look

Page 20: Odoo - Smart buttons

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>

Page 21: Odoo - Smart buttons

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)

Page 22: Odoo - Smart buttons

Thank you!


Top Related