from odoo import models, fields, api,_
from odoo.exceptions import UserError, ValidationError,Warning
from psycopg2 import sql, DatabaseError
from datetime import datetime

from werkzeug import utils
import base64

class PaymentTransaction(models.Model):
    _inherit = 'payment.transaction'

    donation_ids = fields.Many2many('donation.donation', 'donation_transaction_rel', 'transaction_id', 'donation_id',
                                      string='Donations', copy=False, readonly=True)
    
    membership_ids = fields.Many2many('kalachakra.membership', 'membership_transaction_rel', 'transaction_id', 'membership_id',
                                      string='Membership', copy=False, readonly=True)


    def render_donation_button(self, donation, submit_txt=None, render_values=None):
        values = {
            'partner_id': donation.partner_id.id,
            'type': self.type,
        }
        if render_values:
            values.update(render_values)
        # Not very elegant to do that here but no choice regarding the design.
        self._log_payment_transaction_sent()
        return self.acquirer_id.with_context(submit_class='btn btn-primary', submit_txt=submit_txt or _('Pay Now')).sudo().render(
            self.reference,
            donation.amount_total,
            donation.currency_id.id,
            values=values,
        )
    def render_membership_button(self, membership, submit_txt=None, render_values=None):
        values = {
            'partner_id': membership.partner_id.id,
            'type': self.type,
        }
        if render_values:
            values.update(render_values)
        # Not very elegant to do that here but no choice regarding the design.
        self._log_payment_transaction_sent()
        return self.acquirer_id.with_context(submit_class='btn btn-primary', submit_txt=submit_txt or _('Pay Now')).sudo().render(
            self.reference,
            membership.amount,
            membership.currency_id.id,
            values=values,
        )