Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master mollie #1

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
85ef8d2
[MOLLIE] init commit
pga-odoo Jul 14, 2021
c0d6b97
remove python depandacy
pga-odoo Jul 15, 2021
222e476
[WIP] add custom form
pga-odoo Jul 15, 2021
ca44d3d
WIP
pga-odoo Jul 18, 2021
b361132
WIP component
pga-odoo Jul 19, 2021
9dc8a25
WIP transection values
pga-odoo Jul 20, 2021
ca4bf45
WIP create payment via api
pga-odoo Jul 20, 2021
58ca368
WIP completed whole flow
pga-odoo Jul 21, 2021
f46ede9
WIP completed direct card payment
pga-odoo Jul 21, 2021
4bf7e81
WIP added payment fallback
pga-odoo Jul 21, 2021
fd4cf34
WIP added vouchers and webhook
pga-odoo Jul 21, 2021
ccc3ed0
vouchers improvements
pga-odoo Jul 22, 2021
a35941c
Ref
pga-odoo Jul 22, 2021
226c333
Ref
pga-odoo Jul 22, 2021
1f65586
Ref
pga-odoo Jul 22, 2021
85c9d65
Ref
pga-odoo Jul 22, 2021
8005a82
Ref
pga-odoo Jul 22, 2021
cc447b5
Ref
pga-odoo Jul 22, 2021
9f30b96
webhook comments
pga-odoo Jul 22, 2021
4bee2d7
remove keys from data
pga-odoo Jul 22, 2021
f3b0597
ref mollie.py
pga-odoo Jul 22, 2021
6496a9a
merge api methods
pga-odoo Jul 22, 2021
f8845ec
merge api methods
pga-odoo Jul 22, 2021
ef31e71
reg
pga-odoo Jul 22, 2021
6a060fd
ref
pga-odoo Jul 22, 2021
239d6ff
ref
pga-odoo Jul 22, 2021
ad2e773
ref
pga-odoo Jul 22, 2021
62dab24
ref
pga-odoo Jul 22, 2021
2e55290
ref
pga-odoo Jul 22, 2021
a42cf9b
ref
pga-odoo Jul 22, 2021
62b47a8
ref
pga-odoo Jul 22, 2021
957afba
ref
pga-odoo Jul 22, 2021
66edc6a
ref
pga-odoo Jul 22, 2021
eddc2f1
ref
pga-odoo Jul 22, 2021
0a62608
ref
pga-odoo Jul 22, 2021
fe5fe19
ref
pga-odoo Jul 22, 2021
22af1d5
css ref
pga-odoo Jul 22, 2021
5e6faeb
ref
pga-odoo Jul 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
vouchers improvements
  • Loading branch information
pga-odoo committed Jul 22, 2021
commit ccc3ed0fcb6dff6e58f40d8a217bf49e09ad9d8f
36 changes: 13 additions & 23 deletions addons/payment_mollie/models/mollie.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

import logging

from odoo.osv import expression
from odoo import _, api, fields, models

_logger = logging.getLogger(__name__)
@@ -15,7 +16,7 @@ class MolliePaymentMethod(models.Model):

name = fields.Char(translate=True)
sequence = fields.Integer()
parent_id = fields.Many2one('payment.acquirer') # This will be always mollie
acquirer_id = fields.Many2one('payment.acquirer') # This will be always mollie
method_code = fields.Char(string="Method code")
payment_icon_ids = fields.Many2many('payment.icon', string='Supported Payment Icons')
active = fields.Boolean(default=True)
@@ -36,7 +37,7 @@ class MolliePaymentIssuers(models.Model):

name = fields.Char()
sequence = fields.Integer()
parent_id = fields.Many2one('mollie.payment.method')
acquirer_id = fields.Many2one('mollie.payment.method')
payment_icon_ids = fields.Many2many('payment.icon', string='Supported Payment Icons')
issuers_code = fields.Char()
active = fields.Boolean(default=True)
@@ -47,30 +48,19 @@ class MollieVoucherLines(models.Model):
_description = 'Mollie voucher method'

method_id = fields.Many2one('mollie.payment.method')
category_id = fields.Many2one('product.category')
mollie_voucher_category = fields.Selection(related="category_id.mollie_voucher_category", readonly=False)

def unlink(self):
for voucher_line in self:
voucher_line.mollie_voucher_category = False
return super().unlink()


class ProductCategory(models.Model):
_inherit = 'product.category'

mollie_voucher_category = fields.Selection([('meal', 'Meal'), ('eco', 'Eco'), ('gift', 'Gift')])
method_id = fields.Many2one('mollie.payment.method')
category_ids = fields.Many2many('product.category')
product_ids = fields.Many2many('product.template')
mollie_voucher_category = fields.Selection([('meal', 'Meal'), ('eco', 'Eco'), ('gift', 'Gift')], required=True)


class ProductTemplate(models.Model):
_inherit = 'product.template'

def _get_mollie_voucher_category(self):
self.ensure_one()
mollie_voucher_category = False
category_id = self.categ_id
if category_id:
while not mollie_voucher_category and category_id:
mollie_voucher_category = category_id.mollie_voucher_category
category_id = category_id.parent_id
return mollie_voucher_category
domain = [('product_ids', 'in', self.ids)]
categories = self.mapped('categ_id')
if categories:
domain = expression.OR([domain, [('category_ids', 'parent_of', categories.ids)]])
voucher_line = self.env['mollie.voucher.line'].search(domain, limit=1)
return voucher_line and voucher_line.mollie_voucher_category or False
10 changes: 5 additions & 5 deletions addons/payment_mollie/models/payment_acquirer.py
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ class PaymentAcquirerMollie(models.Model):
mollie_api_key_test = fields.Char(string="Mollie Test API key", required_if_provider="mollie", groups="base.group_user")
mollie_api_key_prod = fields.Char(string="Mollie Live API key", required_if_provider="mollie", groups="base.group_user")
mollie_profile_id = fields.Char("Mollie Profile ID", groups="base.group_user")
mollie_methods_ids = fields.One2many('mollie.payment.method', 'parent_id', string='Mollie Payment Methods')
mollie_methods_ids = fields.One2many('mollie.payment.method', 'acquirer_id', string='Mollie Payment Methods')

# ------------------
# OVERRIDDEN METHODS
@@ -86,7 +86,7 @@ def _sync_mollie_methods(self, methods_data):
create_vals = {
'name': method_info['description'],
'method_code': method_info['id'],
'parent_id': self.id,
'acquirer_id': self.id,
'supports_order_api': method_info.get('support_order_api', False),
'supports_payment_api': method_info.get('support_payment_api', False)
}
@@ -174,10 +174,10 @@ def _mollie_get_supported_methods(self, order, invoice, amount, currency):
if not self.sudo().mollie_profile_id:
methods = methods.filtered(lambda m: m.method_code != 'creditcard')

remove_voucher_method, extra_params = True, {}
has_voucher_line, extra_params = False, {}
if order:
extra_params['amount'] = {'value': "%.2f" % order.amount_total, 'currency': order.currency_id.name}
remove_voucher_method = not any(map(lambda p: p._get_mollie_voucher_category(), order.mapped('order_line.product_id.product_tmpl_id')))
has_voucher_line = order.mapped('order_line.product_id.product_tmpl_id')._get_mollie_voucher_category()
if order.partner_invoice_id.country_id:
extra_params['billingCountry'] = order.partner_invoice_id.country_id.code
else:
@@ -192,7 +192,7 @@ def _mollie_get_supported_methods(self, order, invoice, amount, currency):
if amount and currency:
extra_params['amount'] = {'value': "%.2f" % amount, 'currency': currency.name}

if remove_voucher_method:
if not has_voucher_line:
methods = methods.filtered(lambda m: m.method_code != 'voucher')

# Hide based on country
5 changes: 3 additions & 2 deletions addons/payment_mollie/views/payment_views.xml
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
<field name="payment_icon_ids" widget="many2many_tags"/>
<field name="active" invisible="1"/>
<field name="active_on_shop" widget="boolean_toggle"/>
<field name="country_ids" widget="many2many_tags" optional="hide"/>
<field name="country_ids" widget="many2many_tags"/>
<field name="supports_order_api" invisible="1"/>
<field name="supports_payment_api" invisible="1"/>
<field name="payment_issuer_ids" widget="many2many_tags" invisible="1"/>
@@ -60,8 +60,9 @@
<page string="Voucher Configuration" name="voucher_config" attrs="{'invisible': [('method_code', '!=', 'voucher')]}">
<field name="mollie_voucher_ids">
<tree editable="bottom">
<field name="category_id"/>
<field name="mollie_voucher_category"/>
<field name="category_ids" widget="many2many_tags"/>
<field name="product_ids" widget="many2many_tags"/>
</tree>
</field>
</page>