File: web.py

package info (click to toggle)
tryton-modules-web-shop-vue-storefront-stripe 7.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 332 kB
  • sloc: python: 240; xml: 17; makefile: 11; sh: 3
file content (45 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval


class Shop(metaclass=PoolMeta):
    __name__ = 'web.shop'

    stripe_journal = fields.Many2One(
        'account.payment.journal', "Stripe Journal",
        domain=[
            ('stripe_account', '!=', None),
            ('currency', '=', Eval('currency', -1)),
            ],
        depends=['currency'])

    def vsf_order_create(self, data, sale, user):
        pool = Pool()
        Payment = pool.get('account.payment')
        PaymentGroup = pool.get('account.payment.group')
        sale = super().vsf_order_create(data, sale, user)
        payment_method = data['addressInformation']['payment_method_code']
        if payment_method == 'stripe':
            payment_method_additional = (
                data['addressInformation']['payment_method_additional'])
            payment = Payment()
            payment.company = sale.company
            payment.kind = 'receivable'
            payment.party = sale.party
            payment.origin = sale
            payment.amount = sale.total_amount
            payment.journal = self.stripe_journal
            payment.stripe_token = payment_method_additional['id']
            payment.stripe_chargeable = True
            payment.save()
            Payment.approve([payment])
            group = PaymentGroup(
                company=payment.company,
                journal=payment.journal,
                kind=payment.kind)
            group.save()
            Payment.process([payment], lambda: group)
        return sale