← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 676169] Re: [6.0][purchase] wrong relational model: purchase m2O invoice; wrong invoiced status and % check

 

Hello,

It has been fixed in lp:~openerp-commiter/openobject-addons/rha-dev-
addons2

Revision ID: rha@xxxxxxxxxxx-20101209112145-hob1geqht0n9pw5d
Revision no: 4698

Thanks,
rha


** Changed in: openobject-addons
       Status: In Progress => Fix Committed

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/676169

Title:
  [6.0][purchase] wrong relational model: purchase m2O invoice; wrong invoiced status and % check

Status in OpenObject Addons Modules:
  Fix Committed

Bug description:
  Hello,

affects v5 and v6:

consider this very common business case: you order several items to your supplier. And just like you could do in OpenERP for sales (eg it's a matter of consistency also), your supplier delivers you the items with partial deliveries and you are invoiced upon those partial deliveries. Meaning that your purchase order is only paid when you paid all those n related invoices.

However, currently in OpenERP, purchase.order has a many2one field to account.invoice!!!
here is the code snippet from purchase/purchase.py:
'invoice_id': fields.many2one('account.invoice', 'Invoice', readonly=True, help="An invoice generated for a purchase order"),

This doesn't cover that case where several invoices are related to the purchase order!

Furthermore, the
_invoiced_rate and _invoiced functions are not implemented properly as they only consider the unique invoice_id (whichone?)
see the following code:

    def _invoiced(self, cursor, user, ids, name, arg, context=None):
        res = {}
        for purchase in self.browse(cursor, user, ids, context=context):
            if purchase.invoice_id.reconciled:
                res[purchase.id] = purchase.invoice_id.reconciled
            else:
                res[purchase.id] = False
        return res

    def _invoiced_rate(self, cursor, user, ids, name, arg, context=None):
        res = {}
        for purchase in self.browse(cursor, user, ids, context=context):
            tot = 0.0
            if purchase.invoice_id and purchase.invoice_id.state not in ('draft','cancel'):
                tot += purchase.invoice_id.amount_untaxed
            if purchase.amount_untaxed:
                res[purchase.id] = tot * 100.0 / purchase.amount_untaxed
            else:
                res[purchase.id] = 0.0
        return res

Note that fortunately, it seems that the purchase order lines and the account invoice lines are properly linked through a many2many relation.

I think we should have also a purchase.order many2many account.invoice relation instead and that we should iterate over the related invoice lines (from the potentially several invoices then) to compute the "invoiced" and "invoice_rate" status instead.

Notice that on Twitter, Joel Grand Guillaume (C2C), Carlos Liebana (Ting.es), ovnicraft (Gnuthink) and NeoPolus (Borja L.S.) just confirmed the bug and proposed solution. I think we need to refactor this urgently instead of dragging it all the v6 cycle once the schema is frozen wrongly...

Hope this helps.







References