-
Notifications
You must be signed in to change notification settings - Fork 26
/
sale.py
85 lines (70 loc) · 2.38 KB
/
sale.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
"""
Invoice
:copyright: (c) 2014 by Openlabs Technologies & Consulting (P) Limited
:license: GPLv3, see LICENSE for more details.
"""
from trytond.pool import PoolMeta, Pool
from nereid import abort, Markup, render_template
__all__ = ['Sale', 'SaleLine']
__metaclass__ = PoolMeta
class Sale:
__name__ = 'sale.sale'
def ga_purchase_data(self, **kwargs):
'''
Return a dictionary that can be JSON serialised as expected by
google analytics as a purchase confirmation
'''
return {
'id': self.reference,
'revenue': str(self.total_amount),
'tax': str(self.tax_amount),
}
def _add_or_update(self, product_id, quantity, action='set'):
"""
Raise 400 if someone tries to add gift card to cart using
add_to_cart method
"""
Product = Pool().get('product.product')
if Product(product_id).is_gift_card:
abort(400)
return super(Sale, self)._add_or_update(product_id, quantity, action)
def _get_email_template_paths(self):
"""
Returns a tuple of the form:
(html_template, text_template)
"""
return (
'nereid_webshop/templates/emails/sale-confirmation-html.jinja',
'nereid_webshop/templates/emails/sale-confirmation-text.jinja'
)
class SaleLine:
__name__ = 'sale.line'
def add_to(self, sale):
"""
Copy sale line to new sale. and handle case of gift_card
"""
SaleLine_ = Pool().get('sale.line')
if not self.product.is_gift_card:
return super(SaleLine, self).add_to(sale)
values = {
'product': self.product.id,
'sale': sale.id,
'type': self.type,
'unit': self.unit.id,
'quantity': self.quantity,
'sequence': self.sequence,
'description': self.description,
'recipient_email': self.recipient_email,
'recipient_name': self.recipient_name,
'message': self.message,
'gc_price': self.gc_price,
'unit_price': self.unit_price
}
return SaleLine_(**values)
def render(self, purpose=None):
"""
Render the line
"""
return Markup(render_template('cart/sale-line.jinja',
line=self, purpose=purpose))