Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
11274 Vizualizări

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>
Imagine profil
Abandonează
Cel mai bun răspuns

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"),
}
Imagine profil
Abandonează
Cel mai bun răspuns

_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

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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')
}
Imagine profil
Abandonează

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.

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

Cel mai bun răspuns

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"),
Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 16
5804
3
nov. 22
7318
1
mar. 15
6199
0
dec. 24
9352
3
sept. 24
21427