openerp-expert-framework team mailing list archive
-
openerp-expert-framework team
-
Mailing list archive
-
Message #00342
Re: fields.selection - inherit problem
Raphaël Valyi escribió:
like the Tryton forks does: passing on_change arguments
as dictionaries and merging values (and passing the context as well by
the way) instead of using positional arguments.
That looks like the way to go for me. Having some care I think we could
even do a smooth transition (backwards compatible)...
We might turn something like this:
/<field name="product_id" on_change="product_id_change(product_id,
uos_id, quantity, name, parent.type, parent.partner_id,
parent.fiscal_position, price_unit,
parent.address_invoice_id,{'price_type':parent.price_type})"/>/
*def* product_id_change(self, cr, uid, ids, product, uom, qty=0,
name='', type='out_invoice', partner_id=False, fposition_id=False,
price_unit=False, address_invoice_id=False, context=None):
...
res = self.pool.get('product.product').browse(cr, uid, product,
context=context)
...
result['uos_id'] = uom *or* res.uom_id.id *or* False
...
*return* {'value':result, 'domain':domain}
Into this:
/<field name="product_id" on_change="on_change_product_id({
'product_id': product_id, 'uom_id': uos_id, 'quantity': quantity,
'name': name, 'type': parent.type, 'partner_id': parent.partner_id,
'//fiscal_position_id': parent.fiscal_position, 'price_unit':
price_unit, 'address_invoice_id': parent.address_invoice_id }, {
'price_type':parent.price_type })"/>/
*def* product_id_change(self, cr, uid, ids, product, uom, qty=0,
name='', type='out_invoice', partner_id=False, fposition_id=False,
price_unit=False, address_invoice_id=False, context=None):
/ """
Just a wrapper to be backwards compatible
"""/
*return* self.on_change_product_id(cr, uid, ids, { 'product_id':
product, 'uom_id': uom, 'quantity': qty, 'name': name, 'type': type,
'partner_id': partner_id, 'fiscal_position_id': fposition_id,
'price_unit': price_unit, 'address_invoice_id': address_invoice_id },
context)
*def* on_change_product_id(self, cr, uid, ids, args=None, context=None):
/"""
The real deal...
"""/
...
*if* args.get('product_id'):
res = self.pool.get('product.product').browse(cr, uid,
args.get(product, context=context)
...
result['uos_id'] = args.get('uom_id', res.uom_id and
res.uom_id.id)
...
*return* {'value':result, 'domain':domain}
Overall I would like we plan long term solutions for those modularity
issues as this let modules non compatible (so the multiply in a non
manageable way instead of working well together) and non
straightforward to install. For the on_change limitation, it the
solution would just be to copy the Tryton solution and plan the API
change over the major versions.
+1
For the selection, I don't know about the solution yet (disclaimer: I
didn't think about it either).
Turn this:
*class* account_invoice(osv.osv):
...
_columns = {
...
'type': fields.selection([
('out_invoice','Customer Invoice'),
('in_invoice','Supplier Invoice'),
('out_refund','Customer Refund'),
('in_refund','Supplier Refund'),
],'Type', readonly=True, select=True),
Into this:
*class* account_invoice(osv.osv):
...
_options = {
'type': [
('out_invoice', 'Customer Invoice'),
('in_invoice', 'Supplier Invoice'),
('out_refund', 'Customer Refund'),
('in_refund', 'Supplier Refund'),
]
}
_columns = {
...
'type': fields.selection(_options['type'],'Type', readonly=True,
select=True),
...
So you can extend the openobject later on another module like this:
*class* extend_account_invoice_options(osv.osv):
_inherit='account.invoice'
...
options = self.pool.get(_inherit)._options
options['type'].append( ('new_invoice_type', 'New invoice type') )
Even more, we could create some wrappers on the orm layer, so the code
looks a bit cleaner:
*class* orm_template(object):
_options = {}
...
*def* add_option(self, selection, code, description):
self._options[selection] = list(set(self._options.get(selection,
[]).append( (code, description) )
*class* account_invoice(osv.osv):
...
self.add_option('type', 'out_invoice', 'Customer Invoice'),
self.add_option('type', 'in_invoice', 'Supplier Invoice'),
self.add_option('type', 'out_refund', 'Customer Refund'),
self.add_option('type', 'in_refund', 'Supplier Refund'),
_columns = {
...
'type': fields.selection(self._options['type'], 'Type',
readonly=True, select=True),
...
*class* extend_account_invoice_options(osv.osv):
_inherit='account.invoice'
...
self.add_option('type', 'new_invoice_type', 'New invoice type')
--
Borja López Soilán
borjals@xxxxxxxxx
Pexego Sistemas Informáticos S.L.
Avenida de Magoi 66 - 27002 Lugo (España)
Tel./Fax 982801517
http://www.pexego.es
AVISO LEGAL - CLÁUSULA DE PRIVACIDAD
Este mensaje se dirige exclusivamente a su destinatario y puede contener información privilegiada o confidencial. Si no es usted el destinatario indicado, queda informado de que la utilización, divulgación y/o copia sin autorización está prohibida en virtud de la legislación vigente. Si ha recibido este mensaje por error, le rogamos que nos lo comunique inmediatamente por esta misma vía y proceda a su destrucción.
Follow ups
References