Thanks for your help, my inherit works perfect now. And a new problem appears, when I try add the shipping collumn ('frais' in french) in updating th price in the order, that works. But, just one time, I can't change the first value submitted.
class purchase_order(osv.osv):
_name='purchase.order'
_inherit='purchase.order'
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = super(purchase_order, self)._amount_all(cr, uid, ids, field_name, arg, context)
for order in self.browse(cr, uid, ids, context=context):
res[order.id]['amount_total'] += order.frais
return res
def _get_order(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
result[line.order_id.id] = True
return result.keys()
_columns = {
'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The amount without tax", track_visibility='always'),
'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The tax amount"),
'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums",help="The total amount"),
'frais':fields.float('Frais')
}
purchase_order()
Edit: It works perfect now.
Final code:
class purchase_order(osv.osv):
_name='purchase.order'
_inherit='purchase.order'
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
res = super(purchase_order, self)._amount_all(cr, uid, ids, field_name, arg, context)
for order in self.browse(cr, uid, ids, context=context):
res[order.id]['amount_total'] += order.frais
return res
def _get_order(self, cr, uid, ids, context=None):
result = {}
for line in self.pool.get('purchase.order.line').browse(cr, uid, ids, context=context):
result[line.order_id.id] = True
return result.keys()
_columns = {
'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The amount without tax", track_visibility='always'),
'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
store={
'purchase.order.line': (_get_order, None, 10),
}, multi="sums", help="The tax amount"),
'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
store={
'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['frais'], 10),
'purchase.order.line': (_get_order, None, 10),
}, multi="sums",help="The total amount"),
'frais':fields.float('Frais')
}