Browse Source

[IMP] realocate methods in respective models

Gogs 7 years ago
parent
commit
a750dc6512

+ 9 - 1
__init__.py

@@ -1,2 +1,10 @@
 # -*- coding: utf-8 -*
-from models import eiru_pos
+from models import account_journal
+from models import account_payment_term
+from models import account_period
+from models import account_voucher
+from models import product_template
+from models import res_company
+from models import res_currency
+from models import res_partner
+from models import sale_order

+ 1 - 1
__openerp__.py

@@ -4,7 +4,7 @@
     'author': "Robert Gauto",
     'category': 'Uncategorized',
     'version': '0.1',
-    'depends': ['base'],
+    'depends': ['base', 'sale', 'account'],
     'data': [
         'templates.xml'
     ]

+ 4 - 2
models/account_journal.py

@@ -4,5 +4,7 @@ class AccountJournal(models.Model):
     _inherit = 'account.journal'
 
     @api.model
-    def _get_journals(models.Model):
-        pass
+    def get_journals(self):
+        journal = self.env['account.journal']
+
+        print journal

+ 1 - 1
models/account_payment_term.py

@@ -4,5 +4,5 @@ class AccountPaymentTerm(models.Model):
     _inherit = 'account.payment.term'
 
     @api.model
-    def _get_account_payment_terms(self):
+    def get_account_payment_terms(self):
         pass

+ 2 - 2
models/account_period.py

@@ -1,8 +1,8 @@
 from openerp import api, fields, models
 
 class AccountPeriod(models.Model):
-    _inherit: = 'account.period'
+    _inherit = 'account.period'
 
     @api.model
-    def _get_periods(self):
+    def get_periods(self):
         pass

+ 2 - 2
models/account_voucher.py

@@ -1,8 +1,8 @@
 from openerp import api, fields, models
 
 class AccountVoucher(models.Model):
-    _inherits = 'account.voucher' 
+    _inherit = 'account.voucher' 
 
     @api.model
-    def _perform_payment(self):
+    def perform_payment(self):
         pass

+ 0 - 245
models/eiru_pos.py

@@ -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

+ 76 - 3
models/product_template.py

@@ -1,8 +1,81 @@
 from openerp import api, fields, models
 
 class ProductTemplate(models.Model):
-    inherit = 'product.template'
+    _inherit = 'product.template'
 
     @api.model
-    def _get_products(self):
-        pass
+    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 attribute
+                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

+ 14 - 3
models/res_company.py

@@ -1,8 +1,19 @@
 from openerp import api, fields, models
 
 class ResCompany(models.Model):
-    inherit = 'res.company'
+    _inherit = 'res.company'
 
     @api.model
-    def _get_company(self):
-        pass
+    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
+            }
+        }

+ 30 - 3
models/res_currency.py

@@ -1,8 +1,35 @@
 from openerp import api, fields, models
 
 class ResCurrency(models.Model):
-    inherit = 'res.currency'
+    _inherit = 'res.currency'
 
     @api.model
-    def _get_currencies(self):
-        pass
+    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

+ 28 - 3
models/res_partner.py

@@ -1,8 +1,33 @@
 from openerp import api, fields, models
 
 class ResPartner(models.Model):
-    inherit = 'res.partner'
+    _inherit = 'res.partner'
 
     @api.model
-    def _get_customers(self):
-        pass
+    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

+ 50 - 3
models/sale_order.py

@@ -1,8 +1,55 @@
 from openerp import api, fields, models
 
 class SaleOrder(models.Model):
-    inherit = 'sale.order'
+    _inherit = 'sale.order'
 
     @api.model
-    def _process_order(self)
-        pass
+    def process_pos_order(self, customer_id, cart_items):
+        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 {}

+ 2 - 1
src/store/actions.js

@@ -19,7 +19,8 @@ const actions = {
         })
     },
     completeSale({ getters }) {
-        let pos = new openerp.web.Model('eiru.pos')
+        let pos = new openerp.web.Model('sale.order')
+
         pos.call('process_pos_order', [
             getters.getCartItems,
             getters.getSelectedCustomer.id

+ 2 - 1
src/store/modules/company.js

@@ -23,7 +23,8 @@ const mutations = {
 const actions = {
     fetchCompany({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('eiru.pos')
+            let pos = new openerp.web.Model('res.company')
+
             pos.call('get_company').then(response => {
                 commit('setCompany', {
                     company: response

+ 2 - 1
src/store/modules/currencies.js

@@ -17,7 +17,8 @@ const mutations = {
 const actions = {
     fetchCurrencies({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('eiru.pos')
+            let pos = new openerp.web.Model('res.currency')
+
             pos.call('get_currencies').then(response => {
                 commit('pushCurrencies', {
                     currencies: response

+ 2 - 1
src/store/modules/customers.js

@@ -31,7 +31,8 @@ const mutations = {
 const actions = {
     fetchCustomers({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('eiru.pos')
+            let pos = new openerp.web.Model('res.partner')
+
             pos.call('get_customers').then(response => {
                 commit('pushCustomers', {
                     customers: response

+ 2 - 1
src/store/modules/products.js

@@ -40,7 +40,8 @@ const mutations = {
 const actions = {
     fetchProducts ({ commit, dispatch }) {
         return new Promise((resolve, reject) => {
-            let pos = new openerp.web.Model('eiru.pos')
+            let pos = new openerp.web.Model('product.template')
+
             pos.call('get_products').then(response => {
                 commit('pushProducts', {
                     products: response