콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
11518 화면

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>
아바타
취소
베스트 답변

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"),
}
아바타
취소
베스트 답변

_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

아바타
취소
작성자 베스트 답변

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.

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

베스트 답변

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
3월 16
5994
3
11월 22
7505
1
3월 15
6386
0
12월 24
9504
3
9월 24
21763