This question has been flagged
2 Replies
7916 Views

I would like to see a street + city of a partner underneath the delivery address selector on a sale order screen. I had another solution where I added a text field to sale.order and a onchange function, but I think theres a better way.


Here is what I have in the view:

<field name="partner_shipping_id">

                                <tree>

                                <field name="street" string="Street"/>

                                </tree>

                            </field>


I have also tried using mode=form but none of these seem to alter the default behavior of showing the delivery address contact name...

Avatar
Discard
Best Answer

Rays way is one way, probably best if you are not wanting to write code.  But to make it display like the customer in the above screen shot then you just add the context key "show_address".  If you really wanted it like the above shot and just street and city on one line, then overriding name_get with a new context key say "show_street_city" is a more perfomant and neater way to do it as its all done in one function call.

Otherwise you end up with same issue when you want to do on pickings or invoices for example.

If you look at name_get in res_partner.py it will show you the already existing context keys and how they are formatted, so pretty straightforward.

Avatar
Discard
Author

the show address attribute doesnt show for when sale is in a unsaved state. I want my users to see the address and confirm it with a customer before hitting confirm sale/save

True, thats because the edit widget is only one line tall. You could still set a context key, to display on one line mind you. We just do that, and also make the whole address searchable, but then we got 80,000 delivery addresses, no one is searching by name, always by street or GEO.

Works out quite nice because as they type the address the search list narrows and they can see the address to pick.

Author

So you override get_name so that it displays street1+2+city etc, but what if the delivery address and base partner record are the same? How would you see the customer name?

Best Answer

You can create a new field on the sale.order model to contain this data, and add that field to the view:


NEW FIELD:


ADDED TO THE VIEW:



Code for the field calculation:

for record in self:
  record['x_street_city'] = record.partner_shipping_id.street + " " + record.partner_shipping_id.city

Avatar
Discard
Author

this was similar to my first attempt, except I used one of the on change method: I need it to show while the sale is in a draft so that the user can pick a customer and without saving, have it show the delivery address (to confirm with customer before sale is processed). I think there must be a way of showing this without having to add another field though

Hello,

Thanks for the above.

I am trying to do the some but its giving some error as dependencies is also required.

Can you please let me know what to add in dependencies?

Thanks

partner_shipping_id