Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[solved]Problem to inherits _amount_all function

By
vgze
on 4/22/13, 7:08 AM 4,669 views

Hello,

I need your help. That take 2 days that I work on the inheritance of the "_amount_all" function for add my shipping price value. But, my modification are not effective. Nothing happen, when I update the price.

Iuse openERP7 on Debian.

custom_achat.py

class purchase_order(osv.osv):
_name='purchase.order'
_inherit='purchase.order'
_columns = {
     'frais':fields.float('Frais')
}
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)
    res[purchase.id] += 5
    return res

custom_achat_viex.xml

<record model="ir.ui.view" id="purchase_order_form_inherit">
    <field name="name">purchase.order.form.inherit</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
        <field name="amount_untaxed" position="before">
            <field name="frais"/>
        </field>
    </field>
</record>
2
klacus
On 4/22/13, 7:30 AM

Or you can try to inherit the columns also, what is call this function too. Nothing need to change just call/put it in your inherited model. It works's in account

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)
    res[purchase.id] += 5
    return res


    _columns = {
    'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Purchase Price'), string='Total',
        store={
            'purchase.order.line': (_get_order, None, 10),
        }, multi="sums",help="The total amount"),
    'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Purchase Price'), string='Untaxed Amount',
        store={
            'purchase.order.line': (_get_order, None, 10),
        }, multi="sums", help="The amount without tax"),
}
1

Keyur

--Keyur--
1165
| 4 4 8
Ahmedabad, India
--Keyur--

Odoo Expert

Keyur
On 4/22/13, 12:15 PM

The value of amount_total field will only change when there will be any change in purchase.order.line. The field function will not call when there will be any change in purchase.order.So we need to write code explicitly that if there is a change in fraise, the value of amount_total need to be change.So it can be done as follow

'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
    store={
        'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['fraise'], 10),
        'purchase.order.line': (_get_order, None, 10),
    }, multi="sums",help="The total amount"),
1
vgze
On 4/22/13, 11:02 AM

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')
}

Can you debug your code? The _amount_all running again? May be the status of the order is change, according the work flow... So I think your problem is there. Please check the workflow, and try to debug the code.

klacus
on 4/23/13, 12:37 AM

Please read my above answer. Hope now your code works fine.

Keyur
on 4/23/13, 2:07 AM
1

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 4/22/13, 7:19 AM

_amount_all is a private function called from a function field. If you need to ihnerith it, you must insert the some function field in your code and in the relative function call the original _amount_all

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/22/13, 7:08 AM
Seen: 4669 times
Last updated: 3/16/15, 8:10 AM