[6.0.1] Invoicing an outgoing picking list from a sale order including service products

Bug #737786 reported by Jordi Esteve (www.zikzakmedia.com)
36
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Medium
OpenERP R&D Addons Team 2

Bug Description

If you invoice an outgoing picking list whose sale order includes service products, and the purchase module is installed, you can get the following error because action_invoice_create() tries to get an analytical account but the inherit _get_account_analytic_invoice() method defined in purchase module is called.

It could be fixes if line 104 of file purchase/stock.py:
        if move_line.purchase_line_id:

is changed to:
        if picking.purchase_id and move_line.purchase_line_id:

  File "server/bin/addons/stock/wizard/stock_invoice_onshipping.py", line 93, in open_invoice
    res = self.create_invoice(cr, uid, ids, context=context)
  File "server/bin/addons/purchase/purchase.py", line 835, in create_invoice
    res = super(stock_invoice_onshipping,self).create_invoice(cr, uid, ids, context=context)
  File "server/bin/addons/stock/wizard/stock_invoice_onshipping.py", line 131, in create_invoice
    context=context)
  File "server/bin/addons/delivery/stock.py", line 81, in action_invoice_create
    context=context)
  File "server/bin/addons/sale/stock.py", line 167, in action_invoice_create
    user, picking, sale_line)
  File "server/bin/addons/purchase/stock.py", line 104, in _get_account_analytic_invoice
    if move_line.purchase_line_id:
  File "server/bin/osv/orm.py", line 287, in __getattr__
    raise AttributeError(e)
AttributeError: "Field 'purchase_line_id' does not exist in object 'browse_record(sale.order.line, 393)'"

Related branches

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Jordi,

I have tested your scenario with latest trunk at my end but I am not able to reproduce it.
Would you please elaborate with more information or provide the proper steps to reproduce it.

Thanks.

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
SG E-ndicus(Selvam) (e-ndicus) wrote :

Jordi,

  You seem to be right. I am also facing the issue.

Revision history for this message
Samuel Bissig (Toradex) (samuel.b) wrote :

This affects me as well. I don't understand how it could work (as reported in issue #737786). I checked with exactly the same settings as proposed by the movie in #737786 without success.

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello,

I have tested this scenario again with stable6.02 and trunk both.
But all are working as expected and I am not faced any type of the problem.

I have checked _get_account_analytic_invoice() method also in purchase/stock.py.
This method is only call when the invoice create from incoming shipment (In Picking) with analytic account.

So would you please check this with latest code.
I have attached a video for your reference so would you please check it again and notify us where you faced the problem.

Thanks and waiting for your reply!

Revision history for this message
Amit Parik (amit-parik) wrote :
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Jordi,

I have tested your scenario again But all are working as expected.

For more information you can check the above video.

If you still faced the problem then you can reopen this with proper steps.

Thank you!

Changed in openobject-addons:
status: Incomplete → Invalid
Revision history for this message
Ken Chen (ken-chen) wrote :

I'm facing the same problem too. How actually this can be solved??

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello guys,

I confirm this issue. It was a blocker here in one project.

I fixed it a few weeks ago, with the attached patched.

Basically, the _get_account_analytic_invoice methods will be called bot for sale and purchase potentially on which the picking is potentially based. They are called in an order that depends on the your module installation order. There is a particular order that screw it all. This also explains why OpenERP SA guys didn't spot the issue yet.

How I fixed it:
Better refactorings might exist but here is what I did:
purchase/stock.py#_get_account_analytic_invoice only makes sense if there is actually a purchase order line related to the move (not the case if you invoice a delivery).
So I added that test inside purchase/stock.py.
On the other side, in sale/stock.py, there will be no stock stock.move here. So instead of passing a sale.order.line to the call chain, that would blow out later in purchase/stock.py, I simply pass nothing.

See attached patch please.
NB: as I explained it to OpenERP SA, I do not agree on the new 'private module exception" license under the current terms that don't protect against a SaaS loophole. Thanks.

Changed in openobject-addons:
status: Invalid → New
Revision history for this message
Ken Chen (ken-chen) wrote :

i've tested, if i install Sales and Account module first, afterward add Purchase Module then other core modules. It is working fine. But i'm not sure how the module installation sequence will causing this problem.

Changed in openobject-addons:
status: New → Confirmed
Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Jordi ,samuel, Raphael, ken chen,

please any one provide me a proper steps on this.

Because still I am not able to reproduce it at my end.
I have tested all scenario which you have specified.

I have tasted this with latest stable 6.0.2 and trunk both. But I never seen the purchase/stock,py 's action_invoice_create called. Every time the action_invoice_create method called from sale module.

So would you please check this again and provide me the proper steps and also provide the information which modules you have installed.

Thanks and waiting for your reply!

Changed in openobject-addons:
status: Confirmed → Incomplete
Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) wrote :

We have detected this problem with the following modules installed:

account
account_accountant
account_cancel
account_payment
account_voucher
analytic
base
base_action_rule
base_calendar
base_iban
base_setup
base_vat
board
crm
decimal_precision
delivery
hr
mail_gateway
point_of_sale
process
procurement
product
purchase
resource
sale
sale_crm
sale_order_dates
stock

But, as it has been written in previous comments, this behaviour could depend on the order the modules have been installed. IMHO my previous solution has a very little impact on the code of the stable version, so worth including it so the software will be more robust. This is the solution I have proposed:

It could be fixed if line 104 of file purchase/stock.py:
        if move_line.purchase_line_id:

is changed to:
        if picking.purchase_id and move_line.purchase_line_id:

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello everyone, thanks for the feedback and investigation on this issue.
It is indeed difficult to reproduce, but on 6.0 I did it by adding a dependency from purchase to sale. You can see easily in the database loading messages if the sales module is loaded before or after purchase. If it's loaded before you should be able to reproduce the bug.
The suggestion from Jordi seems a good approach to fix it, as it is consistent with the way we do the same test in the sale module. Also, be careful as passing False instead of sale_line as suggested by Raphael's patch is likely to break account_analytic_default (which also overrides this method and needs a move_line), so that would require more testing/patching - probably not worth it.

The one-line patch suggested by Jordi seems suitable for patching 6.0 as well as trunk, if the OPW team considers this issue critical enough for landing it in the stable branch.

Thanks!

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 2 (openerp-dev-addons2)
importance: Undecided → Medium
status: Incomplete → Confirmed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

BTW, in trunk/6.1 the module loading order will be more predictable, so this kind of semi-random issue should appear less often, making them easier to spot/solve.

Changed in openobject-addons:
status: Confirmed → In Progress
Revision history for this message
Atik Agewan(OpenERP) (aag-openerp) wrote :

Hello Jordi,

Thanks for reporting,
It has been fixed in lp:~openerp-dev/openobject-addons/trunk-bug-737786-aag
Revision ID: <email address hidden>
Revision num: 4926.
It will be available in trunk soon,

Changed in openobject-addons:
status: In Progress → Fix Committed
Changed in openobject-addons:
status: Fix Committed → Fix Released
Revision history for this message
qdp (OpenERP) (qdp) wrote :

merged into revision 5094 of trunk addons

Changed in openobject-addons:
milestone: none → 6.1
Revision history for this message
Joaquin Gutierrez (joaquin-sbhard) wrote :

In modulo addons\account_analytic_default\account_analytic_default.py when calling the class class stock_picking we get this error:

   File "netsvc.pyo", line 489, in dispatch
   File "service \ web_services.pyo", line 599, in dispatch
   File "osv \ osv.pyo", line 122, in wrapper
   File "osv \ osv.pyo", line 176, in execute
   File "osv \ osv.pyo", line 167, in execute_cr
   File "C: \ ERP \ Server \ addons \ stock \ wizard \ stock_invoice_onshipping.py", line 100, in open_invoice
   File "C: \ ERP \ Server \ addons \ purchase \ purchase.py", line 858, in create_invoice
   File "C: \ ERP \ Server \ addons \ stock \ wizard \ stock_invoice_onshipping.py", line 146, in create_invoice
   File "C: \ ERP \ Server \ addons \ delivery \ stock.py", line 81, in action_invoice_create
   File "C: \ ERP \ Server \ addons \ out \ stock.py", line 167, in action_invoice_create
   File "C: \ ERP \ Server \ addons \ account_analytic_default \ account_analytic_default.py", line 93, in _get_account_analytic_invoice
 AttributeError: 'bool' object has no attribute 'product_id'

 The previous patches are applied and I think this error is related to the previous one. Is this correct?

Revision history for this message
Joaquin Gutierrez (joaquin-sbhard) wrote :

Hi:

 If I apply this change indicated in the bug 741947 is working properly but this change is not included in the module or the fix.

 3) At file "account_analytic_default.py" from addon "account_analytic_default", at function "def _get_account_analytic_invoice":
   - rec = self.pool.get('account.analytic.default').account_get(cursor, user, move_line.product_id.id, partner_id and partner_id.id, user, time.strftime('%Y-%m-%d'), context={})
   + product_id = False or move_line and move_line.product_id.id
   + rec = self.pool.get('account.analytic.default').account_get(cursor, user, product_id, partner_id and partner_id.id, user, time.strftime('%Y-%m-%d'), context={})

Thank

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Bug attachments

Remote bug watches

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