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

How to disable auto-fill shipping address on sales order

By
kaynis
on 8/1/13, 6:04 AM 1,988 views

Hi all, Using V6 on Windows Can anyone help please me with this, I am trying to stop auto fill function onchange of partner id in sales order. We have lots of customers with many shipping addresses and the users of OpenERP always seem to put the wrong addresses in the shipping address location because the system fills it with a default one. I want the shipping address to be blank so that a user will have to select the correct shipping address everytime

    class sale_order(osv.osv):
        _inherit = "sale.order"
        def onchange_partner_id(self, cr, uid, ids, part, context=None):
            if not part:
                return {'value': { 'payment_term': False, 'fiscal_position': False, 'partner_invoice_id': False, 'partner_order_id': False,}} #'partner_shipping_id': False, 

    part = self.pool.get('res.partner').browse(cr, uid, part, context=context)
    addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['invoice', 'contact'])
    pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False
    payment_term = part.property_payment_term and part.property_payment_term.id or False
    fiscal_position = part.property_account_position and part.property_account_position.id or False
    dedicated_salesman = part.user_id and part.user_id.id or uid
    val = {
        'partner_invoice_id': addr['invoice'],
        'partner_order_id': addr['contact'],
    #            'partner_shipping_id': addr['delivery'],
        'payment_term': payment_term,
        'fiscal_position': fiscal_position,
        'user_id': dedicated_salesman,
    }
    if pricelist:
        val['pricelist_id'] = pricelist
    return {'value': val}

sale_order()

Does it work ?

Xsias
on 8/2/13, 1:06 PM
1
Xsias
On 8/1/13, 6:23 AM

(On the V7)

For a complete no-filling information, in XML : You can inherit the base view on a custom module and delete the onchange like that :

<record id="view_order_form_inherit" model="ir.ui.view">
    <field name="name">sale.order.form.inherit</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='partner_id']" position="replace">
            <field name="partner_id" domain="[('customer','=',True)]" context="{'search_default_customer':1, 'show_address': 1}" options='{"always_reload": True}'/>
        </xpath>
    </field>
</record>

For a targeted edit in Python (V7):

class sale_order(osv.osv):
    _inherit = "sale.order"
    def onchange_partner_id(self, cr, uid, ids, part, context=None):
        if not part:
            return {'value': { 'payment_term': False, 'fiscal_position': False}} #'partner_invoice_id': False, 'partner_shipping_id': False, 

        part = self.pool.get('res.partner').browse(cr, uid, part, context=context)
#        addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['delivery', 'invoice', 'contact'])
        pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False
        payment_term = part.property_payment_term and part.property_payment_term.id or False
        fiscal_position = part.property_account_position and part.property_account_position.id or False
        dedicated_salesman = part.user_id and part.user_id.id or uid
        val = {
#            'partner_invoice_id': addr['invoice'],
#            'partner_shipping_id': addr['delivery'],
            'payment_term': payment_term,
            'fiscal_position': fiscal_position,
            'user_id': dedicated_salesman,
        }
        if pricelist:
            val['pricelist_id'] = pricelist
        return {'value': val}
sale_order()

I've put unwanted code preceded by #

I don't know if it's working under V6, sorry.

Really appreciate the quick response. Thanks a lot but is it possible to disable the shipping address alone?

kaynis
on 8/1/13, 6:38 AM

I've just notice that you are on v6. My answer was about V7, but i thnk it's wok on v6 too.

If you just want to avoid the filling of shipping address you can try an inherit in python. You can edit the onchange_partner_id. I edit my answer with a solution.

Xsias
on 8/1/13, 6:50 AM

It's ok ? (I've disabled shipping and invoice addresses)

Xsias
on 8/1/13, 7:13 AM

Thank you so much mate will get back to you soon

kaynis
on 8/1/13, 7:16 AM

I realized that assumed that was on purpose to illustrate the effects of the commented codes. Thanks

kaynis
on 8/1/13, 7:18 AM

If my answer is good, don't hesitate to mark her as correct and vote for her.

Xsias
on 8/1/13, 10:13 AM

Hi I have tried your solution but i keep getting an error when I try to add a new sales order AttributeError: 'int' object has no attribute 'property_product_pricelist'

kaynis
on 8/2/13, 5:42 AM

My bad, i've commented a wrong line : part = self.pool.get('res.partner').browse(cr, uid, part, context=context) should not be commented. I've edited my answer.

Xsias
on 8/2/13, 5:56 AM
0
kaynis
On 8/2/13, 5:59 AM

I get this error when i select a partner on new sales order Client Traceback (most recent call last): File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 180, in dispatch File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\controllers\main.py", line 1032, in onchange File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\controllers\main.py", line 996, in call_common File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\controllers\main.py", line 1010, in _call_kw File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\openerplib\main.py", line 250, in proxy File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\openerplib\main.py", line 117, in proxy File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 608, in send

Server Traceback (most recent call last): File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\web\common\http.py", line 593, in send File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\netsvc.py", line 360, in dispatch_rpc File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\service\web_services.py", line 572, in dispatch File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 167, in execute_kw File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 121, in wrapper File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 176, in execute File "C:\Program Files (x86)\OpenERP 6.1-1\server.\openerp\osv\osv.py", line 164, in execute_cr File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\sale_journal\sale_journal.py", line 76, in onchange_partner_id File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\delivery\sale.py", line 33, in onchange_partner_id File "C:\Program Files (x86)\OpenERP 6.1-1\server\openerp\addons\sales_extended\sales_extended.py", line 19, in onchange_partner_id AttributeError: 'int' object has no attribute 'property_product_pricelist'

Have you tried my correction ? (Uncomment the line : part = self.pool.get('res.partner').browse(cr, uid, part, context=context) )

Xsias
on 8/2/13, 6:11 AM

Yes i did. I literally copied and pasted your comment

kaynis
on 8/2/13, 6:20 AM

Can you find your def onchange_partner_id() (in your installation) and past it here ? I need to see your original code.

Xsias
on 8/2/13, 6:31 AM

worked when i uncoment the "part" and "addr" but I now have a new problem. When I select a partner, the invoice address is inserted into the shipping address, which is ok but when i change the partner assuming a wrong partner was selected, the shipping address stays as the address first selected. ie assume select partner A, invoice address A in shipping address, change to partner B but shipping address still stays as invoice address A. By the way, Thanks a lot you have been very helpful.

kaynis
on 8/2/13, 7:03 AM

Can you post the actual code you use ? I'm a little bit confused.

Xsias
on 8/2/13, 7:42 AM

Please see code above in my initial question.

kaynis
on 8/2/13, 9:29 AM

It's a silly question but, do you test with a partner B who have an invoice address ?

Xsias
on 8/2/13, 9:40 AM

Yes I did. Sorry it seem our server has been down for a while I tested with few partners

kaynis
on 8/2/13, 11:22 AM

When you put some print variableIWantToPrint and look at the log, what do you see ? Test some importants variables like part or val.

Xsias
on 8/2/13, 11:49 AM

Good morning. Solved when i upgraded/updated base module. Thanks

kaynis
on 8/5/13, 4:50 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

0 follower(s)

Stats

Asked: 8/1/13, 6:04 AM
Seen: 1988 times
Last updated: 3/16/15, 8:10 AM