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

AttributeError: "Field 'invoice_id' does not exist in object 'browse_record(sale.order.line)'

By
charlesraj
on 1/17/14, 8:48 AM 3,231 views

Hi.

for giving discount as fixed amount in sales order line the below mentoined code is used

in .PY file

class sale_order_line(osv.osv):

_inherit = 'sale.order.line'
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
    tax_obj = self.pool.get('account.tax')
    cur_obj = self.pool.get('res.currency')
    res = {}
    if context is None:
        context = {}
    for line in self.browse(cr, uid, ids, context=context):
        if line.amount_discount:
            price = line.price_unit - (line.discount or 0.0)
            taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)
            res[line.id] = taxes['total']
        if line.invoice_ids:
               cur = line.invoice_ids.currency_id
               res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])  
        else:
            price = line.price_unit  * (1 - (line.discount or 0.0) / 100.0)
            taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id)
            cur = line.order_id.pricelist_id.currency_id
            res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
    return res

_name = 'sale.order.line'
_description = 'Sales Order Line'
_columns = {
 'amount_discount': fields.float('Discount (Amount)', digits_compute= dp.get_precision('Discount')),    
 'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal', type="float",digits_compute= dp.get_precision('Account'), store=True),   
 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Product Price')),    
 'discount': fields.float('Discount (%)', digits_compute= dp.get_precision('Discount')),   
 'invoice_ids': fields.many2many('account.invoice', 'sale_order_invoice_rel', 'order_id', 'invoice_id', 'Invoices', readonly=True, ),
        }

sale_order_line()

IN xml file

<openerp>
<data>
 <record id="view_fixed_dis_line" model="ir.ui.view">
    <field name="name">fixed.dis.line</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
                <xpath expr="//field[@name='discount']" position="after">
                <field name ="amount_discount"/>
               </xpath> 
       </field>
 </record>

</data> </openerp>

This module installed succesfully without any error when adding product in the order line , while click on the update button The error will be displayed.

OpenERP Server Error

Client Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/http.py", line 204, in dispatch response["result"] = method(self, *self.params) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1128, in call_kw return self._call_kw(req, model, method, args, kwargs) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1120, in _call_kw return getattr(req.session.model(model), method)(args, **kwargs) File "/opt/openerp/server/openerp/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/opt/openerp/server/openerp/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/opt/openerp/server/openerp/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)

Server Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/opt/openerp/server/openerp/osv/osv.py", line 188, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper return f(self, dbname, args, *kwargs) File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/opt/openerp/server/openerp/addons/sale_stock/sale_stock.py", line 75, in create order = super(sale_order, self).create(cr, uid, vals, context=context) File "/opt/openerp/server/openerp/addons/sale/sale.py", line 336, in create return super(sale_order, self).create(cr, uid, vals, context=context) File "/opt/openerp/server/openerp/addons/mail/mail_thread.py", line 242, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context) File "/opt/openerp/server/openerp/osv/orm.py", line 4478, in create self.pool.get(object)._store_set_values(cr, user, ids, fields2, context) File "/opt/openerp/server/openerp/osv/orm.py", line 4627, in _store_set_values result = self._columns[f].get(cr, self, ids, f, SUPERUSER_ID, context=context) File "/opt/openerp/server/openerp/osv/fields.py", line 1133, in get result = self._fnct(obj, cr, uid, ids, name, self._arg, context) File "/opt/openerp/server/openerp/addons/discount/discount.py", line 44, in _amount_line if line.invoice_ids: File "/opt/openerp/server/openerp/osv/orm.py", line 486, in __getattr__ raise AttributeError(e) AttributeError: "Field 'invoice_id' does not exist in object 'browse_record(sale.order.line, 24)'"

How to solve this...........

Facing the same type of error.....any update?

dirtyHandsPHP
on 9/26/14, 5:19 AM

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

3 follower(s)

Stats

Asked: 1/17/14, 8:48 AM
Seen: 3231 times
Last updated: 3/16/15, 8:10 AM