Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
4 Risposte
11273 Visualizzazioni

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>
Avatar
Abbandona
Risposta migliore

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"),
}
Avatar
Abbandona
Risposta migliore

_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

Avatar
Abbandona
Autore Risposta migliore

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

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.

Risposta migliore

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"),
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
mar 16
5803
3
nov 22
7318
1
mar 15
6199
0
dic 24
9351
3
set 24
21426