|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
from openerp import http
|
|
|
from openerp.http import request
|
|
|
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, float_round
|
|
|
from werkzeug.wrappers import Response
|
|
|
from werkzeug.datastructures import Headers
|
|
|
from datetime import datetime
|
|
@@ -19,8 +20,6 @@ except ImportError:
|
|
|
from StringIO import StringIO as IO
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
-DATE_FORMAT = '%Y-%m-%d'
|
|
|
-DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
|
|
GZIP_COMPRESSION_LEVEL = 9
|
|
|
|
|
|
'''
|
|
@@ -36,6 +35,48 @@ GZIP_COMPRESSION_LEVEL = 9
|
|
|
|
|
|
'''
|
|
|
class PosSales(http.Controller):
|
|
|
+
|
|
|
+ '''
|
|
|
+ Make JSON response
|
|
|
+ '''
|
|
|
+ def make_json_response(self, data=None, status=200):
|
|
|
+ return Response(json.dumps(data), status=status, content_type='application/json')
|
|
|
+
|
|
|
+ '''
|
|
|
+ Make GZIP to JSON response
|
|
|
+ '''
|
|
|
+ def make_gzip_response(self, data=None, status=200):
|
|
|
+ gzip_buffer = IO()
|
|
|
+
|
|
|
+ with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
|
|
|
+ gzip_file.write(json.dumps(data))
|
|
|
+
|
|
|
+ contents = gzip_buffer.getvalue()
|
|
|
+ gzip_buffer.close()
|
|
|
+
|
|
|
+ headers = Headers()
|
|
|
+ headers.add('Content-Encoding', 'gzip')
|
|
|
+ headers.add('Vary', 'Accept-Encoding')
|
|
|
+ headers.add('Content-Length', len(contents))
|
|
|
+
|
|
|
+ return Response(contents, status=status, headers=headers, content_type='application/json')
|
|
|
+
|
|
|
+ '''
|
|
|
+ '''
|
|
|
+ def make_info_log(self, log):
|
|
|
+ LOGGER.info(log)
|
|
|
+
|
|
|
+ '''
|
|
|
+ Get POS data
|
|
|
+ '''
|
|
|
+ def get_pos_data(self):
|
|
|
+ pos = request.env['eiru.pos'].search([])
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'imageType': pos.image_type,
|
|
|
+ 'allowCurrencyExchange': pos.allow_currency_exchange,
|
|
|
+ 'viewCurrencyExchanges': pos.view_currency_exchanges
|
|
|
+ }
|
|
|
|
|
|
'''
|
|
|
Get timezone
|
|
@@ -47,7 +88,7 @@ class PosSales(http.Controller):
|
|
|
Get server date
|
|
|
'''
|
|
|
def get_server_datetime(self):
|
|
|
- return datetime.now(self.get_timezone()).strftime(DATETIME_FORMAT)
|
|
|
+ return datetime.now(self.get_timezone()).strftime(DEFAULT_SERVER_DATETIME_FORMAT)
|
|
|
|
|
|
'''
|
|
|
Check if module is installed
|
|
@@ -74,7 +115,7 @@ class PosSales(http.Controller):
|
|
|
'city': user.company_id.city or None
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
'''
|
|
|
Get currencies from configured journals
|
|
|
'''
|
|
@@ -91,6 +132,7 @@ class PosSales(http.Controller):
|
|
|
'base': currency.base,
|
|
|
'symbol': currency.symbol,
|
|
|
'position': currency.position,
|
|
|
+ 'rateSilent': currency.rate_silent,
|
|
|
'decimalSeparator': currency.decimal_separator,
|
|
|
'decimalPlaces': currency.decimal_places,
|
|
|
'thousandsSeparator': currency.thousands_separator
|
|
@@ -103,12 +145,14 @@ class PosSales(http.Controller):
|
|
|
'''
|
|
|
def get_journals(self):
|
|
|
domain = [('type', 'in', ['bank', 'cash']), ('active', '=', True)]
|
|
|
+ has_subtype = self.is_module_installed('eiru_bank_payments_references')
|
|
|
|
|
|
return [{
|
|
|
'id': journal.id,
|
|
|
'name': journal.display_name,
|
|
|
'code': journal.code,
|
|
|
'type': journal.type,
|
|
|
+ 'subtype': (has_subtype and journal.subtype) or None,
|
|
|
'currencyId': journal.currency.id or journal.company_id.currency_id.id
|
|
|
} for journal in request.env['account.journal'].search(domain, order='id')]
|
|
|
|
|
@@ -135,28 +179,51 @@ class PosSales(http.Controller):
|
|
|
bank_types = []
|
|
|
|
|
|
if self.is_module_installed('eiru_bank_payments_references'):
|
|
|
+ domain = [('is_receipt', '=', True)]
|
|
|
+
|
|
|
bank_types = [
|
|
|
{
|
|
|
'id': type.id,
|
|
|
'name': type.display_name,
|
|
|
- 'code': type.code,
|
|
|
+ 'isReceipt': type.is_receipt,
|
|
|
+ 'isPayment': type.is_payment,
|
|
|
+ 'fieldsAllowed': map(lambda x: x.strip(), (type.fields_allowed or []).split(',')),
|
|
|
+ 'subtype': type.subtype,
|
|
|
'defaultState': type.default_state
|
|
|
- } for type in request.env['res.bank.payments.type'].search([('is_receipt', '=', True)])
|
|
|
+ } for type in request.env['res.bank.payments.type'].search(domain)
|
|
|
]
|
|
|
|
|
|
return bank_types
|
|
|
|
|
|
+ '''
|
|
|
+ Get cheque
|
|
|
+ '''
|
|
|
+ def get_cheque_types(self):
|
|
|
+ cheque_types = []
|
|
|
+
|
|
|
+ if self.is_module_installed('eiru_bank_payments_references'):
|
|
|
+ cheque_types = [
|
|
|
+ {
|
|
|
+ 'id': type.id,
|
|
|
+ 'name': type.display_name,
|
|
|
+ 'isBank': type.is_bank,
|
|
|
+ 'isCash': type.is_cash
|
|
|
+ } for type in request.env['res.bank.check.type'].search([])
|
|
|
+ ]
|
|
|
+
|
|
|
+ return cheque_types
|
|
|
+
|
|
|
'''
|
|
|
Get all active customers
|
|
|
'''
|
|
|
- def get_customers(self):
|
|
|
+ def get_customers(self, image_type='small'):
|
|
|
domain = [('customer', '=', True), ('active', '=', True)]
|
|
|
|
|
|
return [
|
|
|
{
|
|
|
'id': customer.id,
|
|
|
'name': customer.display_name,
|
|
|
- 'image': customer.image_small,
|
|
|
+ 'image': customer.image_small if image_type == 'small' else customer.image_medium,
|
|
|
'ruc': customer.ruc or None,
|
|
|
'phone': customer.phone or None,
|
|
|
'mobile': customer.mobile or None,
|
|
@@ -167,7 +234,7 @@ class PosSales(http.Controller):
|
|
|
'''
|
|
|
Get all saleable and active products
|
|
|
'''
|
|
|
- def get_products(self):
|
|
|
+ def get_products(self, image_type='small'):
|
|
|
domain = [('sale_ok', '=', True), ('list_price', '>', 0), ('active', '=', True)]
|
|
|
|
|
|
return [
|
|
@@ -176,7 +243,7 @@ class PosSales(http.Controller):
|
|
|
'name': product.display_name,
|
|
|
'ean13': product.ean13,
|
|
|
'defaultCode': product.default_code,
|
|
|
- 'image': product.image_small,
|
|
|
+ 'image': product.image_small if image_type == 'small' else product.image_medium,
|
|
|
'listPrice': product.list_price,
|
|
|
'variantCount': product.product_variant_count,
|
|
|
'quantity': 1,
|
|
@@ -189,7 +256,7 @@ class PosSales(http.Controller):
|
|
|
'name': variant.display_name,
|
|
|
'ean13': variant.ean13,
|
|
|
'defaultCode': product.default_code,
|
|
|
- 'image': variant.image_medium,
|
|
|
+ 'image': variant.image_small if image_type == 'small' else variant.image_medium,
|
|
|
'listPrice': variant.list_price,
|
|
|
'quantity': 1,
|
|
|
'price': variant.list_price,
|
|
@@ -220,117 +287,6 @@ class PosSales(http.Controller):
|
|
|
} for payment_term in request.env['account.payment.term'].search(domain)
|
|
|
]
|
|
|
|
|
|
- '''
|
|
|
- Make JSON response
|
|
|
- '''
|
|
|
- def make_json_response(self, data=None, status=200):
|
|
|
- return Response(json.dumps(data), status=status, content_type='application/json')
|
|
|
-
|
|
|
- '''
|
|
|
- Make GZIP to JSON response
|
|
|
- '''
|
|
|
- def make_gzip_response(self, data=None, status=200):
|
|
|
- gzip_buffer = IO()
|
|
|
-
|
|
|
- with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
|
|
|
- gzip_file.write(json.dumps(data))
|
|
|
-
|
|
|
- contents = gzip_buffer.getvalue()
|
|
|
- gzip_buffer.close()
|
|
|
-
|
|
|
- headers = Headers()
|
|
|
- headers.add('Content-Encoding', 'gzip')
|
|
|
- headers.add('Vary', 'Accept-Encoding')
|
|
|
- headers.add('Content-Length', len(contents))
|
|
|
-
|
|
|
- return Response(contents, status=status, headers=headers, content_type='application/json')
|
|
|
-
|
|
|
- '''
|
|
|
- '''
|
|
|
- def make_info_log(self, log):
|
|
|
- LOGGER.info(log)
|
|
|
-
|
|
|
- '''
|
|
|
- New purchase resource route
|
|
|
- '''
|
|
|
- @http.route('/eiru_sales/init', auth='user', methods=['GET'], cors='*')
|
|
|
- def init_sale(self, **kw):
|
|
|
- self.make_info_log('Sending JSON response')
|
|
|
-
|
|
|
- return self.make_gzip_response(
|
|
|
- {
|
|
|
- 'date': self.get_server_datetime(),
|
|
|
- 'user': self.get_user(),
|
|
|
- 'currencies': self.get_currencies_from_journals(),
|
|
|
- 'journals': self.get_journals(),
|
|
|
- 'customers': self.get_customers(),
|
|
|
- 'products': self.get_products(),
|
|
|
- 'paymentTerms': self.get_payment_terms(),
|
|
|
- 'banks': self.get_banks(),
|
|
|
- 'bankPaymentTypes': self.get_bank_payment_types()
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- '''
|
|
|
- Create customer and return data
|
|
|
- '''
|
|
|
- @http.route('/eiru_sales/create_customer', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
- def create_customer(self, **kw):
|
|
|
- self.make_info_log('Creating customer')
|
|
|
-
|
|
|
- customer = request.env['res.partner'].create({
|
|
|
- 'name': kw.get('name'),
|
|
|
- 'ruc': kw.get('ruc'),
|
|
|
- 'mobile': kw.get('mobile'),
|
|
|
- 'customer': True
|
|
|
- })
|
|
|
-
|
|
|
- return {
|
|
|
- 'id': customer.id,
|
|
|
- 'name': customer.display_name,
|
|
|
- 'image': customer.image_small,
|
|
|
- 'ruc': customer.ruc or None,
|
|
|
- 'phone': customer.phone or None,
|
|
|
- 'mobile': customer.mobile or None,
|
|
|
- 'email': customer.email or None
|
|
|
- }
|
|
|
-
|
|
|
- '''
|
|
|
- Create product and return data
|
|
|
- '''
|
|
|
- @http.route('/eiru_sales/create_product', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
- def create_product(self, **kw):
|
|
|
- self.make_info_log('Creating customer')
|
|
|
-
|
|
|
- product = request.env['product.template'].create({
|
|
|
- 'name': kw.get('name'),
|
|
|
- 'list_price': float(kw.get('price')),
|
|
|
- 'ean13': kw.get('ean13')
|
|
|
- })
|
|
|
-
|
|
|
- return {
|
|
|
- 'id': product.id,
|
|
|
- 'name': product.display_name,
|
|
|
- 'ean13': product.ean13,
|
|
|
- 'image': product.image_small,
|
|
|
- 'listPrice': product.list_price,
|
|
|
- 'variantCount': product.product_variant_count,
|
|
|
- 'quantity': 1,
|
|
|
- 'price': product.list_price,
|
|
|
- 'discount': 0,
|
|
|
- 'variants': [{
|
|
|
- 'id': variant.id,
|
|
|
- 'name': variant.display_name,
|
|
|
- 'ean13': variant.ean13,
|
|
|
- 'image': variant.image_small,
|
|
|
- 'listPrice': variant.list_price,
|
|
|
- 'quantity': 1,
|
|
|
- 'price': variant.list_price,
|
|
|
- 'discount': 0,
|
|
|
- } for variant in product.product_variant_ids if variant.active]
|
|
|
- }
|
|
|
-
|
|
|
'''
|
|
|
Get currency from journal
|
|
|
'''
|
|
@@ -354,16 +310,36 @@ class PosSales(http.Controller):
|
|
|
|
|
|
return pricelist
|
|
|
|
|
|
+ '''
|
|
|
+ '''
|
|
|
+ def compute_cart_item_price(self, price, currency_id, partner_id=None):
|
|
|
+ from_currency = request.env.user.company_id.currency_id
|
|
|
+ to_currency = request.env['res.currency'].search([('id', '=', currency_id)])
|
|
|
+
|
|
|
+ return from_currency.compute(price, to_currency)
|
|
|
+
|
|
|
+ '''
|
|
|
+ '''
|
|
|
+ def compute_cart_item_discount(self, price, product_id, currency_id):
|
|
|
+ from_currency = request.env.user.company_id.currency_id
|
|
|
+ to_currency = request.env['res.currency'].search([('id', '=', currency_id)])
|
|
|
+
|
|
|
+ product = request.env['product.product'].search([('id', '=', product_id)])
|
|
|
+ computed_price = from_currency.compute(price, to_currency)
|
|
|
+
|
|
|
+ return 1.0 - (price / product.list_price)
|
|
|
+
|
|
|
'''
|
|
|
Create sale order from cart items values
|
|
|
'''
|
|
|
def create_sale_from_cart(self, partner_id, cart_items, date_confirm, currency_id, pricelist_id, payment_term_id=None):
|
|
|
- return request.env['sale.order'].create({
|
|
|
+ values = {
|
|
|
'partner_id': partner_id,
|
|
|
'order_line': [[0, False, {
|
|
|
'product_id': int(line.get('id')),
|
|
|
'product_uom_qty': float(line.get('quantity')),
|
|
|
- 'price_unit': float(line.get('price'))
|
|
|
+ 'price_unit': self.compute_cart_item_price(float(line.get('price')), currency_id),
|
|
|
+ 'discount': self.compute_cart_item_discount(float(line.get('price')), float(line.get('id')), currency_id)
|
|
|
}] for line in cart_items],
|
|
|
'picking_policy': 'direct',
|
|
|
'date_confirm': date_confirm,
|
|
@@ -371,7 +347,11 @@ class PosSales(http.Controller):
|
|
|
'pricelist_id': pricelist_id,
|
|
|
'payment_term': payment_term_id,
|
|
|
'state': 'draft',
|
|
|
- })
|
|
|
+ }
|
|
|
+
|
|
|
+ # import web_pdb; web_pdb.set_trace()
|
|
|
+
|
|
|
+ return request.env['sale.order'].create(values)
|
|
|
|
|
|
'''
|
|
|
Confirm sale order
|
|
@@ -401,7 +381,7 @@ class PosSales(http.Controller):
|
|
|
invoice.write({
|
|
|
'currency_id': currency_id,
|
|
|
'date_invoice': date_today,
|
|
|
- 'date_due': date_due.strftime(DATE_FORMAT),
|
|
|
+ 'date_due': date_due.strftime(DEFAULT_SERVER_DATE_FORMAT),
|
|
|
'state': 'open'
|
|
|
})
|
|
|
|
|
@@ -412,24 +392,33 @@ class PosSales(http.Controller):
|
|
|
'''
|
|
|
def create_invoice_move_lines(self, invoice_id, paid_amount, date_today):
|
|
|
invoice = request.env['account.invoice'].browse(invoice_id)
|
|
|
+ context = dict(request.context, lang=invoice.partner_id.lang)
|
|
|
+
|
|
|
invoice_move_lines = invoice._get_analytic_lines()
|
|
|
decimal_precision = request.env['decimal.precision'].precision_get('Account')
|
|
|
|
|
|
- compute_taxes = request.env['account.invoice.tax'].compute(invoice)
|
|
|
+ compute_taxes = request.env['account.invoice.tax'].compute(invoice.with_context(context))
|
|
|
invoice.check_tax_lines(compute_taxes)
|
|
|
invoice._recompute_tax_amount()
|
|
|
|
|
|
- invoice_move_lines += request.env['account.invoice.tax'].move_line_get(invoice.id)
|
|
|
+ # import web_pdb; web_pdb.set_trace()
|
|
|
|
|
|
- total, total_currency, invoice_move_lines = invoice.compute_invoice_totals(invoice.company_id.currency_id, invoice.reference, invoice_move_lines)
|
|
|
+ invoice_move_lines += request.env['account.invoice.tax'].move_line_get(invoice.id)
|
|
|
+ total, total_currency, invoice_move_lines = invoice.with_context(context).compute_invoice_totals(invoice.company_id.currency_id, invoice.reference, invoice_move_lines)
|
|
|
|
|
|
- paid_percentage = paid_amount / round(total, decimal_precision)
|
|
|
+ paid_amount = float_round(paid_amount, precision_digits=decimal_precision)
|
|
|
+ paid_percentage = paid_amount / float_round(total_currency, precision_digits=decimal_precision)
|
|
|
distributed_percentage = -(paid_percentage / len(invoice.payment_term.line_ids))
|
|
|
|
|
|
+ diff_currency = invoice.currency_id != invoice.company_id.currency_id
|
|
|
+
|
|
|
+ if diff_currency:
|
|
|
+ paid_amount = invoice.currency_id.compute(paid_amount, invoice.company_id.currency_id)
|
|
|
+
|
|
|
payment_lines = []
|
|
|
|
|
|
for line in invoice.payment_term.line_ids:
|
|
|
- date_due = (parse(date_today) + rd(days=line.days + line.days2)).strftime(DATE_FORMAT)
|
|
|
+ date_due = (parse(date_today) + rd(days=line.days + line.days2)).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
|
|
|
|
|
if paid_percentage and paid_percentage < 1.0:
|
|
|
payment_lines.append([date_today, paid_percentage])
|
|
@@ -446,21 +435,34 @@ class PosSales(http.Controller):
|
|
|
payment_lines.append([date_due, line.value_amount])
|
|
|
|
|
|
for payment_line in payment_lines:
|
|
|
- current_price = round(total * payment_line[1], decimal_precision)
|
|
|
+ current_price = float_round(total * payment_line[1], precision_digits=decimal_precision)
|
|
|
|
|
|
if current_price < 0.0:
|
|
|
continue
|
|
|
|
|
|
paid_amount += current_price
|
|
|
|
|
|
+ # Compute move line price
|
|
|
+ if payment_line[1]:
|
|
|
+ price = current_price
|
|
|
+ else:
|
|
|
+ price = float_round(total - paid_amount, precision_digits=decimal_precision) or total
|
|
|
+
|
|
|
+ # Compute move line amount in currency
|
|
|
+ if diff_currency:
|
|
|
+ amount_currency = invoice.company_id.currency_id.with_context(context).compute(price, invoice.currency_id)
|
|
|
+ else:
|
|
|
+ amount_currency = False
|
|
|
+
|
|
|
+ # Create invoice move live value
|
|
|
invoice_move_lines.append({
|
|
|
'type': 'dest',
|
|
|
'name': '/',
|
|
|
- 'price': current_price if payment_line[1] else round(total - paid_amount, decimal_precision) or total,
|
|
|
+ 'price': price,
|
|
|
'account_id': invoice.account_id.id,
|
|
|
'date_maturity': payment_line[0],
|
|
|
- 'amount_currency': invoice.company_id.currency_id.compute(payment_line[1], invoice.currency_id) if invoice.currency_id != invoice.company_id.currency_id else False,
|
|
|
- 'currency_id': invoice.currency_id != invoice.company_id.currency_id and invoice.currency_id.id,
|
|
|
+ 'amount_currency': amount_currency,
|
|
|
+ 'currency_id': diff_currency and invoice.currency_id.id,
|
|
|
'ref': invoice.reference
|
|
|
})
|
|
|
|
|
@@ -584,7 +586,6 @@ class PosSales(http.Controller):
|
|
|
'ref': 'POS/' + (reference or '')
|
|
|
}]]
|
|
|
|
|
|
-
|
|
|
'''
|
|
|
Create account bank statement
|
|
|
'''
|
|
@@ -613,6 +614,128 @@ class PosSales(http.Controller):
|
|
|
|
|
|
return account_bank_statement
|
|
|
|
|
|
+ '''
|
|
|
+ New purchase resource route
|
|
|
+ '''
|
|
|
+ @http.route('/eiru_sales/init', auth='user', methods=['GET'], cors='*')
|
|
|
+ def init_sale(self, **kw):
|
|
|
+ self.make_info_log('Sending JSON response')
|
|
|
+
|
|
|
+ pos_data = self.get_pos_data()
|
|
|
+
|
|
|
+ return self.make_gzip_response(
|
|
|
+ {
|
|
|
+ 'pos': pos_data,
|
|
|
+ 'date': self.get_server_datetime(),
|
|
|
+ 'user': self.get_user(),
|
|
|
+ 'currencies': self.get_currencies_from_journals(),
|
|
|
+ 'journals': self.get_journals(),
|
|
|
+ 'customers': self.get_customers(image_type=pos_data['imageType']),
|
|
|
+ 'products': self.get_products(image_type=pos_data['imageType']),
|
|
|
+ 'paymentTerms': self.get_payment_terms(),
|
|
|
+ 'banks': self.get_banks(),
|
|
|
+ 'bankPaymentTypes': self.get_bank_payment_types(),
|
|
|
+ 'chequeTypes': self.get_cheque_types()
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ '''
|
|
|
+ Get products data only
|
|
|
+ '''
|
|
|
+ @http.route('/eiru_sales/get_images', auth='user', methods=['GET'], cors='*')
|
|
|
+ def get_images_only(self, **kw):
|
|
|
+ pos_data = self.get_pos_data()
|
|
|
+ image_type = str(pos_data['imageType'])
|
|
|
+
|
|
|
+ return self.make_gzip_response(
|
|
|
+ {
|
|
|
+ 'customers': self.get_customers(image_type=image_type),
|
|
|
+ 'products': self.get_products(image_type=image_type)
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ '''
|
|
|
+ Create customer and return data
|
|
|
+ '''
|
|
|
+ @http.route('/eiru_sales/create_customer', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
+ def create_customer(self, **kw):
|
|
|
+ self.make_info_log('Creating customer')
|
|
|
+
|
|
|
+ customer = request.env['res.partner'].create({
|
|
|
+ 'name': kw.get('name'),
|
|
|
+ 'ruc': kw.get('ruc'),
|
|
|
+ 'mobile': kw.get('mobile'),
|
|
|
+ 'customer': True
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'id': customer.id,
|
|
|
+ 'name': customer.display_name,
|
|
|
+ 'image': customer.image_small,
|
|
|
+ 'ruc': customer.ruc or None,
|
|
|
+ 'phone': customer.phone or None,
|
|
|
+ 'mobile': customer.mobile or None,
|
|
|
+ 'email': customer.email or None
|
|
|
+ }
|
|
|
+
|
|
|
+ '''
|
|
|
+ Save settings
|
|
|
+ '''
|
|
|
+ @http.route('/eiru_sales/save_settings', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
+ def save_settings(self, **kw):
|
|
|
+ self.make_info_log('save settings')
|
|
|
+
|
|
|
+ values = {}
|
|
|
+
|
|
|
+ if kw.get('setting') == 'imageType':
|
|
|
+ values['image_type'] = ('big', 'small')[kw.get('value', False)]
|
|
|
+
|
|
|
+ if kw.get('setting') == 'allowCurrencyExchange':
|
|
|
+ values['allow_currency_exchange'] = kw.get('value', False)
|
|
|
+
|
|
|
+ if kw.get('setting') == 'viewCurrencyExchanges':
|
|
|
+ values['view_currency_exchanges'] = kw.get('value', False)
|
|
|
+
|
|
|
+ pos = request.env['eiru.pos'].search([])
|
|
|
+ pos.write(values)
|
|
|
+
|
|
|
+ return self.get_pos_data()
|
|
|
+
|
|
|
+ '''
|
|
|
+ Create product and return data
|
|
|
+ '''
|
|
|
+ @http.route('/eiru_sales/create_product', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
+ def create_product(self, **kw):
|
|
|
+ self.make_info_log('Creating customer')
|
|
|
+
|
|
|
+ product = request.env['product.template'].create({
|
|
|
+ 'name': kw.get('name'),
|
|
|
+ 'listPrice': float(kw.get('price')),
|
|
|
+ 'ean13': kw.get('ean13')
|
|
|
+ })
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'id': product.id,
|
|
|
+ 'name': product.display_name,
|
|
|
+ 'ean13': product.ean13,
|
|
|
+ 'image': product.image_small,
|
|
|
+ 'listPrice': product.list_price,
|
|
|
+ 'variantCount': product.product_variant_count,
|
|
|
+ 'quantity': 1,
|
|
|
+ 'price': product.list_price,
|
|
|
+ 'discount': 0,
|
|
|
+ 'variants': [{
|
|
|
+ 'id': variant.id,
|
|
|
+ 'name': variant.display_name,
|
|
|
+ 'ean13': variant.ean13,
|
|
|
+ 'image': variant.image_small,
|
|
|
+ 'listPrice': variant.list_price,
|
|
|
+ 'quantity': 1,
|
|
|
+ 'price': variant.list_price,
|
|
|
+ 'discount': 0,
|
|
|
+ } for variant in product.product_variant_ids if variant.active]
|
|
|
+ }
|
|
|
+
|
|
|
'''
|
|
|
Process sale
|
|
|
'''
|
|
@@ -621,7 +744,7 @@ class PosSales(http.Controller):
|
|
|
self.make_info_log('Processing sale...')
|
|
|
|
|
|
# Get date
|
|
|
- date_now = datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
|
|
|
+ date_now = datetime.now(self.get_timezone()).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
|
|
self.make_info_log('[OK] Getting date')
|
|
|
|
|
|
# Get currency
|