Odoo - Smart buttons
-
Upload
odoo -
Category
Technology
-
view
7.716 -
download
1
description
Transcript of Odoo - Smart buttons
![Page 1: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/1.jpg)
Smart Buttons in v8Géry Debongnie
![Page 2: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/3.jpg)
What are Smart Buttons?
![Page 4: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/4.jpg)
Smart Buttons
![Page 5: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/5.jpg)
Smart Buttons (2)
FromFrom
ToTo
![Page 6: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/6.jpg)
Smart Buttons (3)
Two biggest advantages:
dynamic,
customizable.
·
·
![Page 7: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/7.jpg)
From Regular to Smartit's not hard
![Page 8: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/8.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/10.jpg)
Where is the magic?(next slide)
![Page 11: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/11.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/12.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/13.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/14.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/15.jpg)
Customize your buttons
We can customize in two ways:
![Page 16: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/16.jpg)
Customizing Content
![Page 17: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/17.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/18.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/19.jpg)
Customizing Look
![Page 20: Odoo - Smart buttons](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/20.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/21.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022081717/554df258b4c905f6598b51fb/html5/thumbnails/22.jpg)
Thank you!