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

sales.order and account.invoice change

By
Pavel Pavlov
on 9/11/13, 5:56 PM 4,075 views

Hello,
UPDATE 2013.09.12: I’ll re-write the question(and split the code in different files), since looks like it got really confusing to follow..Basically I have the coding below at the moment. I've uploaded whole addon also to pavel-pavlov.com/share/openerp/help/30816/z_fivesol.zip

I've just added DEBUG trace and it shows up... I get in the console

"DEBUG oerpv8_dev1 openerp.addons.z_fivesol.z_fivesol_sale: Successfully set res['value']['zCodeFiveSol']: 'FS012345'."

=> So the problem is not in the .py code...

Current Question: What may be the reason that res['value'] is set properly, but not visible in the sale order line layout, via field name="zCodeFiveSol" ? Maybe I did something wrong in my view?

__init__.py

import z_fivesol_account
import z_fivesol_product
import z_fivesol_sale

__openerp__.py

{
    'name': 'Z_FiveSol Customisations',
    'version': '0.2',
    'category': 'Tools',
    'description': """This module contains custom Mods. Changelog: 
    In version 0.1: -Additional Product fields for internal ref code and external ref code  
    In version 0.2: -Additional Sale Order Line fields for internal ref code and external ref code""",
    'author': 'FiveSol',
    'depends': ['product', 'sale', 'stock', 'purchase', 'account'],
    'data': [
        'z_fivesol_account_view.xml',
        'z_fivesol_product_view.xml',
        'z_fivesol_sale_view.xml'
    ],
    'demo': [],
    'test': [],
    'installable': True,
    'auto_install': False,
    'images': [],   
    'css': [],
}

z_fivesol_sale.py

from openerp import tools
from openerp.osv import fields, osv
from openerp.tools.translate import _
import logging
_logger = logging.getLogger(__name__)

class sale_order_line(osv.osv):    
    _inherit = 'sale.order.line'
    _columns = {
                'zCodeFiveSol': fields.many2one('product.product', 'zCodeFiveSol'),
                'zBaumCode': fields.many2one('product.product', 'zBaumCode'),
                }    
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False, 
            fiscal_position=False, flag=False, context=None):

            res=super(sale_order_line, self).product_id_change(cr, uid, ids, 
            pricelist, product, qty, uom, qty_uos, uos, name, partner_id, lang, 
            update_tax, date_order, packaging=packaging, 
            fiscal_position=fiscal_position, flag=flag, context=context)
            res['value']['zCodeFiveSol'] = "1234555"     
            res['value']['zBaumCode'] = "6789"  
            _logger.debug('Successfully set res[\'value\'][\'zCodeFiveSol\']: %r.', res['value']['zCodeFiveSol'])
            return res
sale_order_line()

z_fivesol_sale_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
    <record id="zview_order_form" model="ir.ui.view">
                 <field name="name">sale.order.form.inherited</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='order_line']/tree/field[@name='name']" position="replace">
                    <field name="zCodeFiveSol"/>
                </xpath>         
            </field>
        </record> 
    </data>
</openerp>
1

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--Hiral Patel (hip)--


Hiral Patel (hip)
On 9/12/13, 5:17 AM

Try this:

class sale_order_line(osv.osv):    
    _inherit = 'sale.order.line'
    _columns = {
                'zCodeFiveSol': fields.many2one('product.product', 'zCodeFiveSol'),
                'zBaumCode': fields.many2one('product.product', 'zBaumCode'),
                }    
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
        res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
        uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging=packaging, 
        fiscal_position=fiscal_position, flag=flag, context=context)
        res['value']['zCodeFiveSol'] = "1234555"     
        res['value']['zBaumCode'] = "6789"  
        return res

sale_order_line()

Thanks for the replay. I've modified my class like that, but I still get "NameError: global name 'sale_order_line' is not defined" on line 58, which is the call res=super(sale_order_line, self).product_id_change(). I believe that for some reason I haven't included properly the inheritance, so my class doesn't know how to "super(sale_order_line, self)" properly... do I need some import on top of what I have already(see z_fivesol.py above) or maybe something else?

Pavel Pavlov
on 9/12/13, 5:26 AM

Can you restart your server & check it again? I applied above code and it's solves your problem of "NameError: global name 'sale_order_line' is not defined"

Hiral Patel (hip)
on 9/12/13, 5:38 AM

Hello Hiral, I've uninstalled the addon, restarted the server, installed it again(but with separated classes in different .py and .xml files, so that I can focus on the problems one by one) and now it doesn't show error "NameError: global name 'sale_order_line' is not defined", but it doesn't populate the field too... I've re-written the initial questions and posted current coding... Any further ideas? Thanks for your help?

Pavel Pavlov
on 9/12/13, 6:52 AM
1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 9/11/13, 7:34 PM

Hello.

Q1 and Q3: you have to inherit sale order line and invoice line.

You have to do something like this:

class custom_sale_order_line(osv.osv)
_inherit='sale.order.line'

def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
        lang=False, update_tax=True, date_order=False, packaging=False,
        fiscal_position=False, flag=False, context=None):



    res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
        uom, qty_uos, uos, name, partner_id,
        lang, update_tax, date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

    res['value']['custom_field']=#assign some value to be displayed 

    return res

Invoice lines object has a onchange_product too. So you have to do this to pull the field.

And Q2: add 'account' on __openerp__.py to depends

Thank you again! :) I followed your suggestions and it worked for Q2, but not for Q1 ... When I click Add order line I get "# NameError: global name 'sale_order_line' is not defined", but I'm not able to understand why? I've listed it as _inherit = 'sale.order.line' and _name = 'sale.order.line' . I've updated the .py & .xml files in the initial memo, since I can post only 500 chars here without code :( Could you please check again? I guess I'm missing something small again. Thank you fro your help so far!

Pavel Pavlov
on 9/12/13, 4:13 AM

I think you will need to add the field to both the form view and tree view. Add your field to a xpath in the form view or the order line and that should solve your problem.

kaynis
on 9/12/13, 4:39 AM

Thank you for your replay, current issue I'm trying to solve is why I get "NameError: global name 'sale_order_line' is not defined" in the .py file, I believe this is not related to the views at all, but I didn't inherit properly the sales_order_line class...

Pavel Pavlov
on 9/12/13, 5:28 AM

There is a problem with your new code. If you are adding product.product with a many2one you can't give them an arbitrary value, you have to give it the id of a product. if you are populating a char or integer... you can do that, but since you are returning a many2one you have to return the id of a product registered in the system.

GH Mediacloud, Grover Menacho
on 9/12/13, 11:28 PM
0
Pavel Pavlov
On 9/14/13, 11:20 AM

Hello,

Finally sovled the problem thanks to your help. The fields work properly. Pasting here the code in case someone needs it. Works properly on my OpenERP version 8.0alpha1 . In case this is not the best way to write the code, please feel free to comment. Thanks once again for your help!

I'm not allowed to mark my reply as solution, so I guess it'll stay at the end of the page... sorry for that!

Regards, Pavel Pavlov

z_fivesol_sale.py

from openerp import tools
from openerp.osv import fields, osv
from openerp.tools.translate import _
#Import the logger for debug code
import logging
_logger = logging.getLogger(__name__)

#iherit sale.order.line and extend it with the required fields
class sale_order_line(osv.osv):    
    _inherit = 'sale.order.line'
    _columns = {
                'zCodeFiveSol': fields.char('zCodeFiveSol', size=20, required=True, readonly=True, states={'draft': [('readonly', False)]}),
                'zBaumCode': fields.char('zBaumCode', size=20, required=True, readonly=True, states={'draft': [('readonly', False)]})
                }   
    #iherit sale.order.line->product_id_change 
    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False, context=None):
        #first call super and fill the res array, then process the additioanl fields.   
        res=super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty,
        uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging=packaging, 
        fiscal_position=fiscal_position, flag=flag, context=context)        

        #Will need to get the data from the product.product model to fill up the initial values for my fields.
        context_partner = {'lang': lang, 'partner_id': partner_id}
        product_obj = self.pool.get('product.product')
        product_obj = product_obj.browse(cr, uid, product, context=context_partner)
        #if product is already selected, then assign the additional fields, else don't do anything.
        if product_obj.id:
            fscode = self.pool.get('product.product').zCodeFiveSol_get(cr, uid, [product_obj.id], context=context_partner)[0][1]
            res['value']['zCodeFiveSol'] = fscode
            fscode = self.pool.get('product.product').zBaumCode_get(cr, uid, [product_obj.id], context=context_partner)[0][1]
            res['value']['zBaumCode'] = fscode  
            _logger.debug("Successfully set res['value']['zCodeFiveSol'] to %r and res['value']['zCodeFiveSol'] to %r", res['value']['zCodeFiveSol'], res['value']['zBaumCode'])
        return res

sale_order_line()

z_fivesol_sale_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="zview_order_form" model="ir.ui.view">
            <field name="name">sale.order.form.inherited</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='order_line']/tree/field[@name='name']" position="replace">
                    <field name="zCodeFiveSol"/>
                </xpath>         
                <xpath expr="//field[@name='order_line']/form/group/group/field[@name='price_unit']" position="after">
                    <field name="zCodeFiveSol"/>
                    <field name="zBaumCode"/>
                </xpath>                          
            </field>
        </record>            
    </data>
</openerp>
0

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--Hiral Patel (hip)--


Hiral Patel (hip)
On 9/12/13, 4:42 AM

Hello,

You have following lines:

class zsale_order_line(osv.osv):
   "Custome code"
sale_order_line()

Either change sale_order_line() to zsale_order_line() or remove sale_order_line() line.

0
Pragmatic
On 9/12/13, 5:31 AM

After solve both issues, one issue remaining related to "zinvoice_form" form view, Here : In Py File: * you have inherit account.invoice.line and add new fields.

In xml File: * You have created view for account.invoice and try to add new field which u have mention in account.invoice.line class, so you have to need to inherit account.invoice.line form view to add these fields instead of account.invoie form view.

Thank you. I'll get to fixing the views after the "NameError: global name 'sale_order_line' is not defined" error for res=super(sale_order_line, self).product_id_change is solved. Currently I'd really love to find out how to correct the inheritance problem.

Pavel Pavlov
on 9/12/13, 5:44 AM

Hello, I tried also changing <field name="model">sale.order</field> to <field name="model">sale.order.line</field> in my z_fivesol_sale_view.xml, but it didn't change anything... I expected to get at least an error if the model is wrong... Please be more specific if I didn't understand your suggestion. Thank you!

Pavel Pavlov
on 9/12/13, 4:08 PM
0

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 9/12/13, 4:06 PM

Make sure there is no zip file in the addons you are using. I suspect thats the issue when you say your code does not get executed and it throws the same error.

In either case, replace sale_order_line by another name and use it in super.

Thanks.

Hello, thanks for the replay! Actually looks like after the final adjustments, that I've listed in the initial comment, looks like my code is executed, because I see that the _logger.debug() is dumped in the command prompt. I've double checked there are no archives in my addon or in sale & account addons. I don't think there can be archives, since I sync trunc directly from LAUNCHub via bazaar client for eclipse/pydev/. The question is why my cede is executed, but I don't see any change in the web view ... I've been struggling whole day with no result... :(

Pavel Pavlov
on 9/12/13, 4:13 PM

Do send your module to me on contact@serpentcs.com .Lets fix this! its hard to sleep with unfixed issues.

Serpent Consulting Services Pvt. Ltd.
on 9/12/13, 4:26 PM

Hello, thank you for your help! I've uploaded my addon to pavel-pavlov.com/share/openerp/help/30816/z_fivesol.zip in case someone else would like to take a look too.. looking forward to your suggestion. The final result I'm trying to acheive is to be able to configure in Sales-> Product -> Form view the two additional fields, then when I do Sales-> Sales Order and choose the product, the <field name="zCodeFiveSol"/> should show the code that I've typed in for hte product earlier in the Product menu. But even if you help me to find why current code is not working will be great! Thanks!

Pavel Pavlov
on 9/12/13, 4:50 PM

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

1 follower(s)

Stats

Asked: 9/11/13, 5:56 PM
Seen: 4075 times
Last updated: 3/16/15, 8:10 AM