Skip to Content
Menu
This question has been flagged
2 Replies
6726 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()

Avatar
Discard

Does it work ?

Best Answer

(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.

Avatar
Discard
Author

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

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.

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

Author

Thank you so much mate will get back to you soon

Author

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

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

Author

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'

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.

Author Best Answer

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'

Avatar
Discard

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

Author

Yes i did. I literally copied and pasted your comment

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

Author

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.

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

Author

Please see code above in my initial question.

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

Author

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

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

Author

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