|
@@ -1,245 +0,0 @@
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-import logging
|
|
|
-from openerp import api, fields, models
|
|
|
-_logger = logging.getLogger(__name__)
|
|
|
-
|
|
|
-class EiruPOS(models.Model):
|
|
|
- _name = 'eiru.pos'
|
|
|
-
|
|
|
- # Get company
|
|
|
- @api.model
|
|
|
- def get_company(self):
|
|
|
- user = self.env.user
|
|
|
-
|
|
|
- return {
|
|
|
- 'id': user.company_id.id,
|
|
|
- 'name': user.company_id.name,
|
|
|
- 'currency': {
|
|
|
- 'id': user.company_id.currency_id.id,
|
|
|
- 'name': user.company_id.currency_id.name,
|
|
|
- 'display_name': user.company_id.currency_id.display_name,
|
|
|
- 'symbol': user.company_id.currency_id.symbol
|
|
|
- }
|
|
|
- # 'store': {
|
|
|
- # 'id': user.company_id.store_id.id,
|
|
|
- # 'name': user.company_id.store_id.name
|
|
|
- # }
|
|
|
- }
|
|
|
-
|
|
|
- # Get all products
|
|
|
- @api.model
|
|
|
- def get_products(self):
|
|
|
- domain = [('sale_ok', '=', True), ('active', '=', True)]
|
|
|
- products = []
|
|
|
-
|
|
|
- # map products
|
|
|
- for product in self.env['product.template'].search(domain):
|
|
|
- variants = []
|
|
|
-
|
|
|
- # map variants
|
|
|
- for variant in product.product_variant_ids:
|
|
|
- if not variant.active:
|
|
|
- continue
|
|
|
- attributes = []
|
|
|
-
|
|
|
- # map product attributes
|
|
|
- # for attribute_line in variant.attribute_line_ids:
|
|
|
- # values = []
|
|
|
-
|
|
|
- # # map product attributes values
|
|
|
- # for value in attribute_line.value_ids:
|
|
|
- # values.append({
|
|
|
- # 'id': value.id,
|
|
|
- # 'display_name': value.display_name,
|
|
|
- # 'name': value.name,
|
|
|
- # 'price_extra': value.price_extra
|
|
|
- # })
|
|
|
- # attributes.append({
|
|
|
- # 'id': attribute_line.id,
|
|
|
- # 'attribute': {
|
|
|
- # 'id': attribute_line.attribute_id.id,
|
|
|
- # 'name': attribute_line.attribute_id.name
|
|
|
- # },
|
|
|
- # 'values': values
|
|
|
- # })
|
|
|
-
|
|
|
- for attribute_value in variant.attribute_value_ids:
|
|
|
- attributes.append({
|
|
|
- 'id': attribute_value.id,
|
|
|
- 'name': attribute_value.name,
|
|
|
- 'display_name': attribute_value.display_name
|
|
|
- })
|
|
|
-
|
|
|
- variants.append({
|
|
|
- 'id': variant.id,
|
|
|
- 'display_name': variant.display_name,
|
|
|
- 'ean13': variant.ean13,
|
|
|
- 'image_medium': variant.image_medium,
|
|
|
- 'list_price': variant.list_price,
|
|
|
- 'name': variant.name,
|
|
|
- 'qty_available': variant.qty_available,
|
|
|
- 'attributes': attributes
|
|
|
- })
|
|
|
- products.append({
|
|
|
- 'id': product.id,
|
|
|
- 'display_name': product.display_name,
|
|
|
- 'ean13': product.ean13,
|
|
|
- 'image_medium': product.image_medium,
|
|
|
- 'list_price': product.list_price,
|
|
|
- 'name': product.name,
|
|
|
- 'qty_available': product.qty_available,
|
|
|
- 'category': {
|
|
|
- 'id': product.categ_id.id,
|
|
|
- 'display_name': product.categ_id.display_name,
|
|
|
- 'name': product.categ_id.name,
|
|
|
- 'account_journal': {
|
|
|
- 'id': product.categ_id.property_stock_journal.id,
|
|
|
- 'code': product.categ_id.property_stock_journal.code,
|
|
|
- 'company': {
|
|
|
- 'id': product.categ_id.property_stock_journal.company_id.id,
|
|
|
- 'name': product.categ_id.property_stock_journal.company_id.name,
|
|
|
- 'currency': {
|
|
|
- 'id': product.categ_id.property_stock_journal.company_id.currency_id.id,
|
|
|
- 'name': product.categ_id.property_stock_journal.company_id.currency_id.name
|
|
|
- }
|
|
|
- },
|
|
|
- 'currency': {
|
|
|
- 'id': product.categ_id.property_stock_journal.currency.id,
|
|
|
- 'name': product.categ_id.property_stock_journal.currency.name
|
|
|
- },
|
|
|
- 'display_name': product.categ_id.property_stock_journal.display_name,
|
|
|
- 'name': product.categ_id.property_stock_journal.name,
|
|
|
- }
|
|
|
- },
|
|
|
- 'uom': {
|
|
|
- 'id': product.uom_id.id,
|
|
|
- 'name': product.uom_id.name
|
|
|
- },
|
|
|
- 'uos': {
|
|
|
- 'id': product.uos_id.id,
|
|
|
- 'name': product.uos_id.name
|
|
|
- },
|
|
|
- 'variant_count': product.product_variant_count,
|
|
|
- 'variants': variants
|
|
|
- })
|
|
|
- return products
|
|
|
-
|
|
|
- # Get all currencies
|
|
|
- @api.model
|
|
|
- def get_currencies(self):
|
|
|
- domain = [('active', '=', True)]
|
|
|
- currencies = []
|
|
|
-
|
|
|
- # if self.env.user.store_id:
|
|
|
- # domain.append(('company_id', '=', self.env.user.store_id.company_id.id))
|
|
|
- # else:
|
|
|
- # domain.append(('company_id', '=', self.env.user.company_id.id))
|
|
|
-
|
|
|
- # print domain
|
|
|
-
|
|
|
- for currency in self.env['res.currency'].search(domain):
|
|
|
- currencies.append({
|
|
|
- 'id': currency.id,
|
|
|
- 'name': currency.name,
|
|
|
- 'display_name': currency.display_name,
|
|
|
- 'accuracy': currency.accuracy,
|
|
|
- 'base': currency.base,
|
|
|
- 'position': currency.position,
|
|
|
- 'rate': currency.rate,
|
|
|
- 'rounding': currency.rounding,
|
|
|
- 'symbol': currency.symbol,
|
|
|
- 'company': {
|
|
|
- 'id': currency.company_id.id,
|
|
|
- 'name': currency.company_id.name
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- return currencies
|
|
|
-
|
|
|
- @api.model
|
|
|
- def get_customers(self):
|
|
|
- domain = [('customer', '=', True), ('is_company', '=', False), ('active', '=', True)]
|
|
|
- customers = []
|
|
|
-
|
|
|
- for customer in self.env['res.partner'].search(domain):
|
|
|
- categories = []
|
|
|
-
|
|
|
- for category in customer.category_id:
|
|
|
- categories.append({
|
|
|
- 'id': category.id,
|
|
|
- 'name': category.name,
|
|
|
- 'display_name': category.display_name
|
|
|
- })
|
|
|
-
|
|
|
- customers.append({
|
|
|
- 'id': customer.id,
|
|
|
- 'name': customer.name,
|
|
|
- 'display_name': customer.display_name,
|
|
|
- 'image_medium': customer.image_medium,
|
|
|
- 'phone': customer.phone,
|
|
|
- 'mobile': customer.mobile,
|
|
|
- 'email': customer.email,
|
|
|
- 'categories': categories
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
- return customers
|
|
|
-
|
|
|
- @api.model
|
|
|
- def process_pos_order(self, cart_items, customer_id):
|
|
|
- order_line_values = []
|
|
|
- for item in cart_items:
|
|
|
- order_line_values.append([0, False, {
|
|
|
- 'product_id': int(item['id']),
|
|
|
- 'product_uom_qty': float(item['qty']),
|
|
|
- 'price_unit': float(item['list_price']),
|
|
|
- 'discount': 0
|
|
|
- }])
|
|
|
-
|
|
|
- order_values = {
|
|
|
- 'partner_id': customer_id,
|
|
|
- 'partner_invoice_id': customer_id,
|
|
|
- 'partner_shipping_id': customer_id,
|
|
|
- 'order_line': order_line_values,
|
|
|
- 'picking_policy': 'direct',
|
|
|
- 'order_policy': 'manual'
|
|
|
- }
|
|
|
-
|
|
|
- order = self.env['sale.order'].create(order_values)
|
|
|
-
|
|
|
- # Process order now
|
|
|
- order.action_button_confirm()
|
|
|
- invoice_id = order.action_invoice_create()
|
|
|
- invoice = {}
|
|
|
-
|
|
|
- if invoice_id:
|
|
|
- invoice = self.env['account.invoice'].browse(invoice_id)
|
|
|
- invoice.signal_workflow('invoice_open')
|
|
|
-
|
|
|
- for picking in order.picking_ids:
|
|
|
- picking.force_assign()
|
|
|
- picking.action_done()
|
|
|
-
|
|
|
- dummy, view_id = self.env['ir.model.data'].get_object_reference('account_voucher', 'view_vendor_receipt_dialog_form')
|
|
|
-
|
|
|
- return {
|
|
|
- 'id': invoice.id,
|
|
|
- 'view_id': view_id,
|
|
|
- 'name': invoice.name,
|
|
|
- 'display_name': invoice.display_name,
|
|
|
- 'currency_id': invoice.currency_id.id,
|
|
|
- 'partner_account_id': self.env['res.partner']._find_accounting_partner(invoice.partner_id).id,
|
|
|
- 'amount': invoice.type in ('out_refund', 'in_refund') and -invoice.residual or invoice.residual,
|
|
|
- 'reference': invoice.name,
|
|
|
- 'invoice_type': invoice.type,
|
|
|
- 'default_type': invoice.type in ('out_invoice', 'out_refund') and 'receipt' or 'payment',
|
|
|
- 'type': invoice.type in ('out_invoice','out_refund') and 'receipt' or 'payment'
|
|
|
- } if invoice_id else {}
|
|
|
-
|
|
|
-
|
|
|
-class eiru_pos_session(models.Model):
|
|
|
- _name = 'eiru.pos.session'
|
|
|
-
|
|
|
- # Get all sessions
|
|
|
- def get_sessions(self):
|
|
|
- pass
|