Print Shipping Address or a custom Address field based on which field is populated

Hi all,

I have a scenario where some of our customers get us to ship direct to their customer. Therefore every Sales Order for that customer has a different shipping address. We also don’t want to add and store all of these addresses as they are usually once off - ie never ship there again.

I thought of setting up a custom field (or custom fields) where you’d enter a free text shipping address for that customer.

That means I need to then specify a statement on my Custom Print for Sales Order saying print this field when customer = X but print the normal shipping_address field when customer <> X. What’s the statement to do this?

Alternatively I could make the Sales_Order.Shipping_Address editable but I don’t think that’s possible - You can’t change properties on non-custom fields?


Add custom field to fetch custom_address OR Text field to Enter Address.

You need to create custom print format.
If SO has custom_address
Print custom_address
Print customer_shipping_address

This way you can save all address in database and also print which address you want.

{% if doc.custom_address %}
        {{ doc.custom_address }}
    {% else %}
        {{ doc.customer_shipping_address }}
{% endif %}
1 Like

Thanks @kolate_sambhaji that worked. My only issue now is formatting that address correctly when I print it. Because I’m using a text field it doesn’t recognise the line breaks I type in. So my address looks OK onscreen:

Department A
UQ Gatton

But prints as one line:

Shipping Address: Department A UQ Gatton LAWES QLD 4343

Any suggestions - I guess I might have to setup multiple fields and then print them one under the other?

@monojoker thats HTML for you!

You can do

<pre>{{ doc.customer_shipping_address }}</pre>
1 Like

Thanks @rmehta I ended up going with:

doc.manual_address_1.replace('\n', "<br/>")

Works perfectly and another thanks to @max_morais_dmm for his help!