invoice refund won't work with account_analytic_plans module

Registered by Raphaël Valyi - http://www.akretion.com

This blueprint originated from the following bug report that couldn't be fixed for v5.0:
https://bugs.launchpad.net/bugs/321886

Hi,

take a fresh install, possibly with the accounting profile.
install the account_tax_include module

Create an invoice with some invoice lines.
In one invoice line, create an analytic distribution (analytics_id field).

Now click on "make credit note" (that will make a refund), you'll get an
ugly stack trace.

This is because relationnal fields in account.analytic.line are handled
in a very weird way the the account/invoice.py#_refund_cleanup_lines
method . See the following code:

   def _refund_cleanup_lines(self, lines):
       for line in lines:
           del line['id']
           del line['invoice_id']
           if 'account_id' in line:
               line['account_id'] = line.get('account_id', False) and line['account_id'][0]
           if 'product_id' in line:
               line['product_id'] = line.get('product_id', False) and line['product_id'][0]
           if 'uos_id' in line:
               line['uos_id'] = line.get('uos_id', False) and line['uos_id'][0]
           if 'invoice_line_tax_id' in line:
               line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
           if 'account_analytic_id' in line:
               line['account_analytic_id'] = line.get('account_analytic_id', False) and line['account_analytic_id'][0]
           if 'tax_code_id' in line :
               if isinstance(line['tax_code_id'],tuple) and len(line['tax_code_id']) >0 :
                   line['tax_code_id'] = line['tax_code_id'][0]
           if 'base_code_id' in line :
               if isinstance(line['base_code_id'],tuple) and len(line['base_code_id']) >0 :
                   line['base_code_id'] = line['base_code_id'][0]
       return map(lambda x: (0,0,x), lines)

Of course this code has the relationnal fields of account.invoice.line hardcoded so it won't cope with extension fields such as the analytics_i field provided by the account_analytic_plans module.

Soultion:
1) Avoid to hardcode those relational fields in _refund_cleanup_lines if possible (use reflection instead?)
2) Else override _refund_cleanup_lines in the account_analytic_plans module but that's just ugly on ugly.

Hope this helps,

Raphaël Valyi.

** Affects: openobject-addons
    Importance: Undecided
        Status: New

--
invoice refund won't work with account_analytic_plans module
https://bugs.launchpad.net/bugs/321886
You received this bug notification because you are a direct subscriber
of the bug.

Status in OpenObject Addons Modules: New

Bug description:
Hi,

take a fresh install, possibly with the accounting profile.
install the account_tax_include module

Create an invoice with some invoice lines.
In one invoice line, create an analytic distribution (analytics_id field).

Now click on "make credit note" (that will make a refund), you'll get an ugly stack trace.

This is because relationnal fields in account.analytic.line are handled in a very weird way the the account/invoice.py#_refund_cleanup_lines method . See the following code:

   def _refund_cleanup_lines(self, lines):
       for line in lines:
           del line['id']
           del line['invoice_id']
           if 'account_id' in line:
               line['account_id'] = line.get('account_id', False) and line['account_id'][0]
           if 'product_id' in line:
               line['product_id'] = line.get('product_id', False) and line['product_id'][0]
           if 'uos_id' in line:
               line['uos_id'] = line.get('uos_id', False) and line['uos_id'][0]
           if 'invoice_line_tax_id' in line:
               line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
           if 'account_analytic_id' in line:
               line['account_analytic_id'] = line.get('account_analytic_id', False) and line['account_analytic_id'][0]
           if 'tax_code_id' in line :
               if isinstance(line['tax_code_id'],tuple) and len(line['tax_code_id']) >0 :
                   line['tax_code_id'] = line['tax_code_id'][0]
           if 'base_code_id' in line :
               if isinstance(line['base_code_id'],tuple) and len(line['base_code_id']) >0 :
                   line['base_code_id'] = line['base_code_id'][0]
       return map(lambda x: (0,0,x), lines)

Of course this code has the relationnal fields of account.invoice.line hardcoded so it won't cope with extension fields such as the analytics_i field provided by the account_analytic_plans module.

Soultion:
1) Avoid to hardcode those relational fields in _refund_cleanup_lines if possible (use reflection instead?)
2) Else override _refund_cleanup_lines in the account_analytic_plans module but that's just ugly on ugly.

Hope this helps,

Raphaël Valyi.

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

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.