3
votes

Is there a simple way of associating a new custom field (in the customer record or in an order items) in OpenERP (oodo) with an external link (ie Description or an iframe) so that it can link to a different system?

Is there a simple way of initializing this link with a (new) GUID, when the record is created?

Is there a simple way injecting client side JavaScript into standard OpenERP pages?

Do I need to create a new module for this?

1

1 Answers

6
votes

For OpenERP 7.0+

  1. You can add an additional field of type text/char for the link to any object like the sale.order/purchase.order/any other object. This is both possible per module or webclient (if you have technical rights).

  2. The simplest way to create a GUID whenever a record is created is to extend that record and override the constructor:

    class extended_sale_order(osv.osv):
      _name = 'sale.order'    # override current sale.order by replacing it (same name)
      _inherit = 'sale.order' # inherit from "original" sale.order
      _columns = {
                  'GUID': field.text('GUID') # add GUID textfield
      }
    
      def create(self, cr, uid, vals, context=None):
         '''
           On sale.order construction create a GUID and replace the GUID field in
           sale.order with the generated value.
         '''
         guid = generate_guid() # implement this or use oerp sequences
         vals['GUID'] = guid
         result = super(extended_sale_order,self).create(cr,uid,vals,context)
         return result
    
  3. Yes, you can add script/html directly into the views like described on OpenERP Bay Blog (I can't add more than 2 links.. spam protection probably, you can easily find the block with most search engines). The modifications can be done either with the web client and technical rights in the UI section or using a module which modifies the view - or by using the widget or another extension point for view related modifications which can use JS.

  4. The crucial part is where to put the GUID creation on record creation logic. If you can do that in JS - for example by creating a new GUID and put it in the field whenever a new record is created with the form - and you know the objects are always created per web-client form it is okay. For a hack. Writing a module and putting the logic into the Business-object is the clean solution for that. The development documentation for OERP modules is sufficient for this and there are good Tutorials out in the net for small problems like adding just an additional Field. An OpenERP Module Programmer would probably just

    • create a Module
    • inherit the Model/Object which should be modified
    • add a field which holds the guid/link
    • optionally create a calculated field which builds the link from the guid field so you only need to save the guid or which creates arbitrary html which should inserted into the view
    • add some logic to the constructor to create and save the guid
    • inherit the views where the link should be placed
    • add the fields/content which should be shown f.e. using the xpath expression to place your new viewpart/field/content behind some other field
    • install and test it
      • restart the server whenever python code is changed
      • update the the module whenever xml is changed

Or short, yes these modifications are simple if you have sufficient knowledge of the technical parts of OpenERP and yes you should put that in a module to keep it clean.