Skip to content

Commit

Permalink
[IMP] connector_easypost: Alert on invalid address
Browse files Browse the repository at this point in the history
* Hide “Validate” button and “or” when EasyPost returns an error
* Display any errors in the EasyPost Address validation Wizard
  • Loading branch information
Ted Salmon committed Dec 15, 2016
1 parent 1e1bab9 commit a9d5c9e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions connector_easypost/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def country_state_id(self, record):
'state_id': state_id.id,
}

@mapping
def validation_errors(self, record):
messages = []
for e in record.verifications.delivery.errors:
messages.append(e.message)
return {'validation_errors': ', '.join(messages)}

@mapping
def validation_status(self, record):
return {'validation_status': record.verifications.delivery.success}


@easypost
class EasypostAddressImporter(EasypostImporter):
Expand Down
8 changes: 8 additions & 0 deletions connector_easypost/wizards/easypost_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ class EasypostAddress(models.TransientModel):
help='EasyPost response mode.',
readonly=True,
)
validation_errors = fields.Char(
help='EasyPost Validation Error Message(s)',
readonly=True,
)
validation_status = fields.Boolean(
help='EasyPost Validation Success',
readonly=True,
)

@api.multi
def _default_partner_id(self):
Expand Down
12 changes: 11 additions & 1 deletion connector_easypost/wizards/easypost_address_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@
<field name="state_id" />
<field name="country_id" />
</group>
<group attrs="{'invisible':
[('validation_status', '=', True)]}">
<field name="validation_errors" />
<field name="validation_status" invisible="1" />
</group>
</group>
</sheet>
<footer>
<button name="action_validate"
type="object"
string="Validate"
class="oe_highlight"
attrs="{'invisible':
[('validation_status', '=', False)]}"
/>
or
<span attrs="{'invisible':
[('validation_status', '=', False)]}">
or
</span>
<button special="cancel"
string="Cancel"
/>
Expand Down

0 comments on commit a9d5c9e

Please sign in to comment.