hooks for extension

Registered by Ferdinand

during the community days 2010 we realized that some methods are to complex to allow easy extension

I'll try to define some problems
* computation of qty*price
** it would be desirable to create a separate function for this (at product_product)
* write (stock_picking, stock_move, account_move, account_move_line, ...)

Example bank_statement - button confirm
* writes twice into account_move_lines - no chance to add a data field
- solution
* button_confirm
** write_1
*** accmount_move_line.write
** write_2
*** accmount_move_line.write

whereas the intermediate write1 and write2 do nothing except calling accmount_move_line.write

this would allow to overwrite
* each of the bank_statement intermediate writes
* the account_move_line write.

ideally the write of resources is only defined and done in a method defined in the target class itself.

if this is the way to go it should be implemented in V6

Please comment

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

One solution is to refactor code.
Using multiple method instead of a big one.
So you will have more control on what to changes.

I have the same problem with document (in 5.0).

Document module is providing, storage method and other usefull stuff in one big method. To inherit this class you have to copy/paste the code.

------------------------------

We should use the "template method pattern" (http://en.wikipedia.org/wiki/Template_method_pattern) maybe combined with a "chain of responsibility" (http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern).
As an example, on the account_bank_statement button_confirm method we have some code like this:

    def button_confirm(self, cr, uid, ids, context={}):
                ...
                val = {
                    'name': move.name,
                    'date': move.date,
                    ...
                    'currency_id': st.currency.id,
                }
               ...
                torec.append(account_move_line_obj.create(cr, uid, val , context=context))

This could be improved to use the template method pattern:

    def _get_move_line_values(self, cr, uid, ids, val, move, st, context={}):
                return val

    def button_confirm(self, cr, uid, ids, context={}):
                ...
                val = {
                    'name': move.name,
                    'date': move.date,
                    ...
                    'currency_id': st.currency.id,
                }
               ...
                val = self._get_move_line_values(cr, uid, ids, val, move, st, context)
                torec.append(account_move_line_obj.create(cr, uid, val , context=context))

This would mean that another module would be able to extend the button_confirm just redefining the _get_move_line_values:

    def _get_move_line_values(self, cr, uid, ids, val, move, st, context={}):
                val2 = super(self, account_bank_statement)._get_move_line_values(cr, uid, ids, val, move, st, context)
                analytic_account_id = ...
                val2.update({'analytic_account_id': analytic_account_id})
                return val2

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.