Development: 5 mixins and objects you will want to inherit

Public Channel / Odoo Experience 2016

By Damien Bouvy - Odoo Developer

Share on Social Networks

Share Link

Use permanent link to share in social media

Share with a friend

Please login to send this presentation by email!

Embed in your website

Select page to start with

3.

11.

16.

17. 2016

2. © Randall Munroe - http://www.xkcd.com

1. 2016

4. 0 1 1 2 3

7. 0 1 1 2 3 'utm.mixin' 'rating.mixin'

15. 0 1 1 2 3 'utm.mixin' 'Rating.mixin' 'website.seo.metadata' 'mail.thread' 'mail.alias.mixin' 'website.published.mixin

10. Complexity Power 0 1 1 2 3 'utm.mixin' 'Rating.mixin' 'website.seo.metadata' 'website.published.mixin

8. ● ● class BlogPost ( models . Model ): _name = "blog.post" _description = "Blog Post" _inherit = [ 'website.seo.metadata' ]

5. ● ● ○ ● class MyModel ( models . Models ): _name = 'my_module.my_model' _inherit = [ 'utm.mixin' ] _description = 'My Tracked Object'

9. ● ● ● class BlogPost ( models . Model ): _name = "blog.post" _description = "Blog Post" _inherit = [ 'website.seo.metadata' , 'website.published.mixin' ]

6. ● ● ● ● class MyModel ( models . Models ): _name = 'my_module.my_model' _inherit = [ 'rating.mixin' , 'mail.thread' ] user_id = fields . Many2one ( 'res.users' , 'Responsible' ) partner_id = fields . Many2one ( 'res.partner' , 'Customer' )

13. ● ● ● ● ● message_ids = fields.Many2one( 'mail.message' , 'Messages' ) message_follower_ids = fields.Many2one( 'mail.followers' , 'Followers' ) @api.multi def message_post (self, subject, body, **kwargs): [...] @api.multi def message_subscribe (self, partner_ids, channel_ids): [...] @api.model def message_new (self, message): [...]

12. ● ● ● ● class BusinessTrip ( models . Model ): _name = 'business.trip' _inherit = [ 'mail.thread' ] _description = 'Business Trip' < div class = " oe_chatter " > < field name = " message_follower_ids " widget = " mail_followers " /> < field name = " message_ids " widget = " mail_thread " /> </ div > { ' name ' : Trips, ' version ' : 1.0, ' depends ' : ['mail'], }

14. ● ● ● ● class BusinessTrip (models . Model): _name = 'business.trip' _inherit = [ 'mail.thread' , 'mail.alias.mixin' ] _description = 'Business Trip' name = fields . Char(track_visibility = 'onchange' ) partner_id = fields . Many2one( 'res.partner' , 'Responsible' , track_visibility = 'onchange' ) guest_ids = fields . Many2many( 'res.partner' , 'Participants' ) state = fields . Selection([( 'draft' , 'New' ), ( 'confirmed' , 'Confirmed' )], track_visibility = 'onchange' ) expense_ids = fields . One2many( 'business.expense' , 'trip_id' , 'Expenses' ) alias_id = fields . Many2one( 'mail.alias' , string = 'Alias' , ondelete = "restrict" , required = True) def get_alias_model_name (self, vals): """ Specify the model that will get created when the alias receives a message """ return 'business.expense' def get_alias_values (self): """ Specify some default values that will be set in the alias at its creation """ values = super(BusinessTrip, self) . get_alias_values() # alias_defaults holds a dictionnary that will be written # to all records created by this alias # # in this case, we want all expense records sent to a trip alias # to be linked to the corresponding business trip values[ 'alias_defaults' ] = { 'trip_id' : self . id} # we only want followers of the trip to be able to post expenses # by default values[ 'alias_contact' ] = 'followers' return values class BusinessExpense (models . Model): _name = 'business.expense' _inherit = [ 'mail.thread' ] _description = 'Business Expense' name = fields . Char() amount = fields . Float( 'Amount' ) trip_id = fields . Many2one( 'business.trip' , 'Business Trip' ) partner_id = fields . Many2one( 'res.partner' , 'Created by' )

Views

  • 7 Total Views
  • 0 Website Views
  • 7 Embeded Views

Actions

  • 0 Social Shares
  • 0 Likes
  • 0 Dislikes
  • 0 Comments

Share count

  • 0 Facebook
  • 0 Twitter
  • 0 LinkedIn
  • 0 Google+

Embeds 2

  • 1 accounts.odoo.com
  • 2 onlinesync.odoo.com