Sales button "Invoice Corrected" does not set the order lines as invoiced

Bug #574348 reported by Borja López Soilán (NeoPolus)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
Undecided
Unassigned
Trunk
Fix Released
Undecided
JMA(Open ERP)

Bug Description

The "Invoice Corrected" button of the sale orders in "invoice_except" state, does not set the invoice lines as invoiced.

This means that wizards like the "make_invoice" one, will re-invoice those lines!

How to reproduce:

  - The user creates a new sale order (with manual invoice method: "Shipping & Manual Invoice", "Ordered Quantities").
  - The user confirms the sale order ("Confirm Order" button).
             => Order state is set to "Manual in Progress".
  - The user creates an invoice from the sale order (either using the "Create Invoice" button or "Make invoices" wizard).
             => The sale order is set to "In Progress".
             => The sale order lines state is set as "Done" and they are flagged as "Invoiced".

  - The user cancels the invoice ("Cancel" button)
             => The sale order state is automatically set to "Invoice Exception".
             => The sale order lines state is still "Done" but the "Invoiced" flag has been removed.
  - The user corrects the invoice ("Set to Draft" button), then confirms it ("Validate" button)
             => The sale order & lines remain in "invoice_except" state, waiting for human intervention.

  - The user edits the sale order, and confirms that the invoice has been corrected ("Invoice Corrected" button).
             => The sale order state is set to "Done".
             => PROBLEM: THE SALE ORDER LINES ARE NOT FLAGGED AS "Invoiced".

  - The user runs the "Make invoices" wizard for several orders including the 'invoice corrected' order.
            => PROBLEM: A new invoice was created for the sale order!!! with 0.00 total (lines are duplicated with negative and positive sign).
            => The sale order lines are now marked as "Invoiced"

Related branches

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

Additional notes:

Using the "Invoice Corrected" button of the sale order form, will signal the "invoice_corrected" signal, causing a transaction between the act_invoice_except and invoice_end workflow activities (trans_invoice_except_invoice_end).

The invoice_end activity (with id act_invoice_end), runs the action_invoice_end() action of the sale order object.

So, the problem is, that the action_invoice_end is not setting the lines as invoices.
Currently it does this:

            for line in order.order_line:
                if line.state == 'exception':
                    self.pool.get('sale.order.line').write(cr, uid, [line.id], {'state': 'confirmed'}, context=context)

And should do this instead:

            for line in order.order_line:
                invoiced = False
                for iline in line.invoice_lines:
                    if iline.invoice_id and iline.invoice_id.state == 'cancel':
                        continue
                    else:
                        invoiced = True
                state = (line.state == 'exception') and 'confirmed' or line.state
                self.pool.get('sale.order.line').write(cr, uid, [line.id], {'invoiced': invoiced, 'state': state})

-----

BTW: The problem is present in trunk too, though the trunk code is a bit different so the patch needs a small change.

Changed in openobject-addons:
status: New → Confirmed
Revision history for this message
JMA(Open ERP) (jma-openerp) wrote :

Hello Borja,

The patch really seems perfect and will surely solve the "invoiced" flag issue.

Apart from this, the behaviour seemed perfect. However, the following problem did not raise up at our end.
"PROBLEM: A new invoice was created for the sale order!!! with 0.00 total (lines are duplicated with negative and positive sign)."

Thank you for pointing this out.

Changed in openobject-addons:
assignee: nobody → JMA(Open ERP) (jma-openerp)
Changed in openobject-addons:
milestone: none → 5.0.15
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Thanks for everything Borja and JMA(OpenERP).

Its delightful to have quick responses from experts.

Fixed on : by revision

Stable : 2863 <email address hidden>
Trunk : 4144 <email address hidden>

Thanks.

Changed in openobject-addons:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.