Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
11269 Lượt xem

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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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"),
}
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

_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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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')
}
Ảnh đại diện
Huỷ bỏ

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.

Câu trả lời hay nhất

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"),
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 16
5801
3
thg 11 22
7313
1
thg 3 15
6196
0
thg 12 24
9349
3
thg 9 24
21415