[IMP] account_report_company: make res.partner.commercial_partner_id field stored, for further reporting needs

This is not strictly necessary, but can be useful for other
modules in order to ease SQL reporting, without even needing
to store a denormalized copy of the "commercial partner" key
on the documents themselves.

Also renamed the Python fiel to something generic since
it now inherits multiple models.

bzr revid: odo@openerp.com-20130419134335-rhsg24f2uuwl3kla
This commit is contained in:
Olivier Dony 2013-04-19 15:43:35 +02:00
parent 26dd9bc343
commit 8503964216
2 changed files with 18 additions and 1 deletions

View File

@ -19,7 +19,7 @@
#
##############################################################################
import account_invoice
import account_report_company
import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -21,6 +21,23 @@
from openerp.osv import osv, fields
class res_partner(osv.Model):
_inherit = 'res.partner'
# indirection to avoid passing a copy of the overridable method when declaring the function field
_commercial_partner_id = lambda self, *args, **kwargs: self._commercial_partner_compute(*args, **kwargs)
_commercial_partner_id_store_triggers = {
'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)]),
['parent_id', 'is_company'], 10)
}
_columns = {
# make the original field stored, in case it's needed for reporting purposes
'commercial_partner_id': fields.function(_commercial_partner_id, type='many2one', relation='res.partner', string='Commercial Entity',
store=_commercial_partner_id_store_triggers)
}
class account_invoice(osv.Model):
_inherit = 'account.invoice'