Skip to content

Commit

Permalink
[IMP] payment: support defining payment providers for specific countr…
Browse files Browse the repository at this point in the history
…ies.
  • Loading branch information
rmu-odoo authored and tivisse committed Oct 20, 2016
1 parent cac170d commit 542201e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions addons/payment/models/payment_acquirer.py
Expand Up @@ -78,6 +78,10 @@ class PaymentAcquirer(models.Model):
journal_id = fields.Many2one(
'account.journal', 'Payment Journal',
help="Account journal used for automatic payment reconciliation.")
country_ids = fields.Many2many(
'res.country', 'payment_country_rel',
'payment_id', 'country_id', 'Countries',
help="This payment gateway is available for selected countries. If none is selected it is available for all countries.")

pre_msg = fields.Html(
'Help Message', translate=True,
Expand Down
1 change: 1 addition & 0 deletions addons/payment/views/payment_views.xml
Expand Up @@ -82,6 +82,7 @@
<field name="auto_confirm" widget="radio"/>
<field name="save_token" widget="radio" attrs="{'invisible': [('token_implemented', '=', False)]}"/>
<field name="journal_id" attrs="{'required': [('auto_confirm', '=', 'generate_and_pay_invoice')], 'invisible': [('auto_confirm', '!=', 'generate_and_pay_invoice')]}"/>
<field name="country_ids" widget="many2many_tags"/>
<label for="view_template_id" groups="base.group_no_one"/>
<div groups="base.group_no_one">
<field name="view_template_id" nolabel="1"/>
Expand Down
25 changes: 17 additions & 8 deletions addons/website_quote/views/website_quote_templates.xml
Expand Up @@ -337,14 +337,23 @@
<div class="col-md-6">
<h4>Payment Method:</h4>
<ul class="list-unstyled">
<t t-set="payment_methods_available" t-value="False"/>
<li t-foreach="acquirers or []" t-as="acquirer">
<label t-if="buttons.get(acquirer.id)">
<input t-att-value="acquirer.id" type="radio" name="acquirer" t-att-checked="acquirers[0] == acquirer"/>
<img class="media-object" style="width: 60px; display: inline-block;"
t-att-title="acquirer.name"
t-att-src="'/payment_%s/static/src/img/%s_icon.png' % (acquirer.provider, acquirer.provider)"/>
<span t-field="acquirer.name"/>
</label>
<t t-if="not acquirer.country_ids or quotation and quotation.partner_id.country_id in acquirer.country_ids">
<label t-if="buttons.get(acquirer.id)">
<input t-att-value="acquirer.id" type="radio" name="acquirer" t-att-checked="acquirers[0] == acquirer"/>
<img class="media-object" style="width: 60px; display: inline-block;"
t-att-title="acquirer.name"
t-att-src="'/payment_%s/static/src/img/%s_icon.png' % (acquirer.provider, acquirer.provider)"/>
<span t-field="acquirer.name"/>
</label>
<t t-set="payment_methods_available" t-value="True"/>
</t>
</li>
<li t-if="not payment_methods_available">
<div class="alert alert-warning">
<span>No payment gateway is available for your country</span>
</div>
</li>
</ul>
</div>
Expand All @@ -353,9 +362,9 @@
<div t-att-data-id="acquirer.id" class="oe_quote_acquirer_button hidden pull-right">
<div t-raw="buttons.get(acquirer.id)"/>
<div t-field="acquirer.pre_msg"/>
<button type="button" class="btn btn-link" data-dismiss="modal" style="padding: 0">Cancel</button>
</div>
</t>
<button type="button" class="btn btn-link" data-dismiss="modal" style="padding: 0">Cancel</button>
</div>
</div>
<!-- end website_sale code -->
Expand Down
14 changes: 11 additions & 3 deletions addons/website_sale/views/templates.xml
Expand Up @@ -1341,17 +1341,25 @@
<div class="col-lg-5 col-sm-6">
<h4>Payment Method:</h4>
<ul class="list-unstyled">
<t t-set="payment_methods_available" t-value="False"/>
<t t-set="partner_country" t-value="website_sale_order and website_sale_order.partner_invoice_id.country_id"/>
<t t-foreach="acquirers or []" t-as="acquirer">
<li>
<li t-if="not acquirer.country_ids or partner_country in acquirer.country_ids">
<label t-if="acquirer.button">
<input t-att-value="acquirer.id" type="radio" name="acquirer" t-att-checked="acquirers[0] == acquirer" />
<span t-field="acquirer.image_small" t-att-title="acquirer.name" t-field-options='{"widget": "image", "style":"max-width: 60px; display: inline-block"}'/>
<span t-field="acquirer.name" />
<span t-if="acquirer.fees_active">(processing fees apply)</span>
</label>
<t t-set="payment_methods_available" t-value="True"/>
</li>
</t>
<li t-if="tokens">
<li t-if="not payment_methods_available">
<div class="alert alert-warning">
<span>No payment gateway is available for your country</span>
</div>
</li>
<li t-if="any(token for token in tokens if not token.acquirer_id.country_ids or partner_country in token.acquirer_id.country_ids)">
<label>
<input type="radio" name="acquirer" />
<span class='fa fa-2x fa-credit-card'/>
Expand All @@ -1360,7 +1368,7 @@

<div class="list-group">
<t t-foreach='tokens' t-as='token'>
<a class="list-group-item btn_payment_token" t-att-data-acquirer="token.acquirer_id.id" t-att-data-token='token.id'>
<a t-if="not token.acquirer_id.country_ids or partner_country in token.acquirer_id.country_ids" class="list-group-item btn_payment_token" t-att-data-acquirer="token.acquirer_id.id" t-att-data-token='token.id'>
<span class="js_radio fa fa-circle-o"></span>&amp;nbsp;
<t t-esc="token.name" />
<t t-if="len(set(tokens.mapped('acquirer_id')))>1">
Expand Down

0 comments on commit 542201e

Please sign in to comment.