|
@@ -1,82 +1,24 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
from openerp import http
|
|
from openerp import http
|
|
from openerp.http import request as r
|
|
from openerp.http import request as r
|
|
-from helpers import (
|
|
|
|
- get_date,
|
|
|
|
- get_current_user,
|
|
|
|
- get_currencies_from_journal,
|
|
|
|
- get_journals,
|
|
|
|
- get_suppliers,
|
|
|
|
- get_products,
|
|
|
|
- get_picking_types,
|
|
|
|
- get_payment_terms,
|
|
|
|
- get_banks,
|
|
|
|
- get_bank_payment_types,
|
|
|
|
- get_cheque_types,
|
|
|
|
- get_pickings,
|
|
|
|
- make_gzip_response
|
|
|
|
-)
|
|
|
|
|
|
+from helpers import get_data, store_data
|
|
import logging
|
|
import logging
|
|
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
-class Purchases(http.Controller):
|
|
|
|
- '''
|
|
|
|
- '''
|
|
|
|
- def make_info_log(self, log):
|
|
|
|
- LOGGER.info('\033[1;34m[INFO] --> \033[m{}'.format(log))
|
|
|
|
-
|
|
|
|
- '''
|
|
|
|
- New purchase resource route
|
|
|
|
- '''
|
|
|
|
- @http.route('/eiru_purchases/init', auth='user', methods=['GET'], cors='*')
|
|
|
|
- def init_purchase(self, **kw):
|
|
|
|
- self.make_info_log('Preparing data to {}'.format(kw.get('mode')))
|
|
|
|
|
|
+def make_info_log(self, log):
|
|
|
|
+ LOGGER.info('\033[1;34m[INFO] --> \033[m{}'.format(log))
|
|
|
|
|
|
- mode = kw.get('mode', 'unknown')
|
|
|
|
- data = None
|
|
|
|
|
|
|
|
- if mode == 'purchase' or mode == 'expense':
|
|
|
|
- data = {
|
|
|
|
- 'date': get_date(),
|
|
|
|
- 'user': get_current_user(),
|
|
|
|
- 'currencies': get_currencies_from_journal(),
|
|
|
|
- 'journals': get_journals(),
|
|
|
|
- 'suppliers': get_suppliers(),
|
|
|
|
- 'products': get_products(kw.get('mode')),
|
|
|
|
- 'pickingTypes': get_picking_types(),
|
|
|
|
- 'paymentTerms': get_payment_terms(),
|
|
|
|
- 'banks': get_banks(),
|
|
|
|
- 'bankPaymentTypes': get_bank_payment_types(),
|
|
|
|
- 'chequeTypes': get_cheque_types()
|
|
|
|
- }
|
|
|
|
|
|
+class Purchases(http.Controller):
|
|
|
|
|
|
- if mode == 'product_picking':
|
|
|
|
- data = {
|
|
|
|
- 'date': get_date(),
|
|
|
|
- 'user': get_current_user(),
|
|
|
|
- 'currencies': get_currencies_from_journal(),
|
|
|
|
- 'suppliers': get_suppliers(),
|
|
|
|
- 'products': get_products()
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if mode == 'payment':
|
|
|
|
- data = {
|
|
|
|
- 'currencies': get_currencies_from_journal(),
|
|
|
|
- 'suppliers': get_suppliers(),
|
|
|
|
- 'journals': get_journals(),
|
|
|
|
- 'paymentTerms': get_payment_terms(),
|
|
|
|
- 'banks': get_banks(),
|
|
|
|
- 'bankPaymentTypes': get_bank_payment_types(),
|
|
|
|
- 'chequeTypes': get_cheque_types()
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if mode == 'product_taking':
|
|
|
|
- data = {
|
|
|
|
- 'stockPickings': get_pickings()
|
|
|
|
- }
|
|
|
|
|
|
+ @http.route('/eiru_purchases/init', auth='user', methods=['GET'])
|
|
|
|
+ def init_purchase(self, **kw):
|
|
|
|
+ mode = kw.get('mode')
|
|
|
|
+ make_info_log('Preparing data to {}'.format(mode))
|
|
|
|
|
|
- return make_gzip_response(data)
|
|
|
|
|
|
+ return get_data(mode)
|
|
|
|
|
|
# '''
|
|
# '''
|
|
# Create supplier and return data
|
|
# Create supplier and return data
|
|
@@ -86,7 +28,6 @@ class Purchases(http.Controller):
|
|
# self.make_info_log('Creating supplier')
|
|
# self.make_info_log('Creating supplier')
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
# '''
|
|
# '''
|
|
# Create product and return data
|
|
# Create product and return data
|
|
# '''
|
|
# '''
|
|
@@ -95,199 +36,10 @@ class Purchases(http.Controller):
|
|
# self.make_info_log('Creating product')
|
|
# self.make_info_log('Creating product')
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Number to invoice
|
|
|
|
- # '''
|
|
|
|
- # def validate_invoice(self, invoice_ids, type=None):
|
|
|
|
- # assert len(invoice_ids) == 1
|
|
|
|
-
|
|
|
|
- # invoice = request.env['account.invoice'].browse(invoice_ids)
|
|
|
|
-
|
|
|
|
- # invoice.action_number()
|
|
|
|
- # invoice.invoice_validate()
|
|
|
|
-
|
|
|
|
- # if type != 'purchase':
|
|
|
|
- # name = 'GASTO' + invoice.name[invoice.name.index('/'):]
|
|
|
|
- # invoice.write({
|
|
|
|
- # 'number': name,
|
|
|
|
- # 'internal_number': name
|
|
|
|
- # })
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Create voucher
|
|
|
|
- # '''
|
|
|
|
- # def create_account_voucher(self, account_move_id, journal_id, currency_id, paid_amount):
|
|
|
|
- # account_move = request.env['account.move'].browse(account_move_id)
|
|
|
|
- # account_journal = request.env['account.journal'].browse(journal_id)
|
|
|
|
-
|
|
|
|
- # account_voucher = request.env['account.voucher'].create({
|
|
|
|
- # 'reference': account_move.name,
|
|
|
|
- # 'type': 'payment',
|
|
|
|
- # 'journal_id': account_journal.id,
|
|
|
|
- # 'company_id': account_move.company_id.id,
|
|
|
|
- # 'pre_line': True,
|
|
|
|
- # 'amount': paid_amount,
|
|
|
|
- # 'period_id': account_move.period_id.id,
|
|
|
|
- # 'date': account_move.date,
|
|
|
|
- # 'partner_id': account_move.partner_id.id,
|
|
|
|
- # 'account_id': account_journal.default_debit_account_id.id,
|
|
|
|
- # 'currency_id': currency_id,
|
|
|
|
- # 'line_dr_ids': [[0, False, {
|
|
|
|
- # 'date_due': l.date_maturity,
|
|
|
|
- # 'account_id': l.account_id.id,
|
|
|
|
- # 'date_original': l.invoice.date_invoice,
|
|
|
|
- # 'move_line_id': l.id,
|
|
|
|
- # 'amount_original': abs(l.credit or l.debit or 0.0),
|
|
|
|
- # 'amount_unreconciled': abs(l.amount_residual),
|
|
|
|
- # 'amount': abs(l.credit) if account_move.date == l.date_maturity else 0.0,
|
|
|
|
- # 'reconcile': account_move.date == l.date_maturity,
|
|
|
|
- # 'currency_id': currency_id
|
|
|
|
- # }] for l in account_move.line_id]
|
|
|
|
- # })
|
|
|
|
-
|
|
|
|
- # account_voucher.action_move_line_create()
|
|
|
|
-
|
|
|
|
- # return account_voucher
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Close a invoice
|
|
|
|
- # '''
|
|
|
|
- # def close_invoice(self, invoice_ids):
|
|
|
|
- # assert len(invoice_ids) == 1
|
|
|
|
-
|
|
|
|
- # invoice = request.env['account.invoice'].browse(invoice_ids)
|
|
|
|
-
|
|
|
|
- # if invoice.residual == 0:
|
|
|
|
- # invoice.write({
|
|
|
|
- # 'state': 'paid'
|
|
|
|
- # })
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Create account bank statement
|
|
|
|
- # '''
|
|
|
|
- # def create_bank_statement(self, account_voucher_id, account_bank_statement_lines, date_today):
|
|
|
|
- # account_voucher = request.env['account.voucher'].browse(account_voucher_id)
|
|
|
|
- # account_bank_statement = request.env['account.bank.statement'].search([('journal_id', '=', account_voucher.journal_id.id), ('date', '=', date_today)])
|
|
|
|
-
|
|
|
|
- # account_bank_statement_values = {
|
|
|
|
- # 'date': date_today,
|
|
|
|
- # 'user_id': request.env.user.id,
|
|
|
|
- # 'journal_id': account_voucher.journal_id.id,
|
|
|
|
- # 'period_id': account_voucher.period_id.id,
|
|
|
|
- # 'line_ids': account_bank_statement_lines,
|
|
|
|
- # 'state': 'open' if account_voucher.journal_id.type == 'cash' else 'draft'
|
|
|
|
- # }
|
|
|
|
-
|
|
|
|
- # if account_bank_statement:
|
|
|
|
- # size = len(account_bank_statement)
|
|
|
|
-
|
|
|
|
- # if size == 1:
|
|
|
|
- # account_bank_statement.write(account_bank_statement_values)
|
|
|
|
- # else:
|
|
|
|
- # account_bank_statement[size - 1].write(account_bank_statement_values)
|
|
|
|
- # else:
|
|
|
|
- # account_bank_statement.create(account_bank_statement_values)
|
|
|
|
-
|
|
|
|
- # return account_bank_statement
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Create account bank statement lines
|
|
|
|
- # '''
|
|
|
|
- # def create_bank_statement_lines(self, account_voucher_id, reference=None):
|
|
|
|
- # account_voucher = request.env['account.voucher'].browse(account_voucher_id)
|
|
|
|
-
|
|
|
|
- # amount = account_voucher.amount
|
|
|
|
-
|
|
|
|
- # if account_voucher.type == 'payment':
|
|
|
|
- # amount = amount * -1
|
|
|
|
-
|
|
|
|
- # return [[0, False, {
|
|
|
|
- # 'name': account_voucher.reference,
|
|
|
|
- # 'amount': amount,
|
|
|
|
- # 'partner_id': account_voucher.partner_id.id,
|
|
|
|
- # 'voucher_id': account_voucher.id,
|
|
|
|
- # 'journal_id': account_voucher.journal_id.id,
|
|
|
|
- # 'account_id': account_voucher.account_id.id,
|
|
|
|
- # 'journal_entry_id': account_voucher.move_id.id,
|
|
|
|
- # 'currency_id': account_voucher.currency_id.id,
|
|
|
|
- # 'ref': 'POS/' + (reference or '')
|
|
|
|
- # }]]
|
|
|
|
-
|
|
|
|
- # '''
|
|
|
|
- # Purchase processing resource route
|
|
|
|
- # '''
|
|
|
|
- # @http.route('/eiru_purchases/process', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
|
- # def process_purchase(self, **kw):
|
|
|
|
- # mode = kw.get('mode')
|
|
|
|
- # self.make_info_log('Processing {}'.format(mode))
|
|
|
|
-
|
|
|
|
- # # Get date
|
|
|
|
- # date_now = datetime.now(self.get_timezone()).strftime(DATE_FORMAT)
|
|
|
|
- # self.make_info_log('Getting date')
|
|
|
|
-
|
|
|
|
- # # Get currency
|
|
|
|
- # currency_id = self.get_currency_id(kw.get('journalId'))
|
|
|
|
- # self.make_info_log('Getting currency')
|
|
|
|
-
|
|
|
|
- # # Get pricelist
|
|
|
|
- # pricelist_id = self.get_pricelist_id(currency_id)
|
|
|
|
- # self.make_info_log('Product pricelist checked')
|
|
|
|
-
|
|
|
|
- # invoice = None
|
|
|
|
-
|
|
|
|
- # if mode == 'purchase':
|
|
|
|
- # # Create purchase order
|
|
|
|
- # purchase_order = self.create_purchase_order(kw.get('supplierId'), kw.get('items'), date_now, currency_id, pricelist_id, kw.get('paymentTermId'))
|
|
|
|
- # self.make_info_log('Purchase order created')
|
|
|
|
-
|
|
|
|
- # # Confirm purchase
|
|
|
|
- # self.confirm_purchase_order(purchase_order.id)
|
|
|
|
- # self.make_info_log('Purchase order confirmed')
|
|
|
|
-
|
|
|
|
- # invoice = purchase_order.invoice_ids
|
|
|
|
- # invoice.write({
|
|
|
|
- # 'supplier_invoice_number': kw.get('supplierInvoiceNumber', None)
|
|
|
|
- # })
|
|
|
|
- # else:
|
|
|
|
- # invoice = self.create_invoice(kw.get('supplierId'), kw.get('items'), currency_id, kw.get('paymentTermId'), kw.get('supplierInvoiceNumber', None))
|
|
|
|
- # self.make_info_log('Invoice created')
|
|
|
|
-
|
|
|
|
- # invoice_ids = invoice.mapped(lambda x: x.id)
|
|
|
|
-
|
|
|
|
- # # Validate invoice
|
|
|
|
- # self.prepare_invoice(invoice_ids, currency_id, date_now)
|
|
|
|
- # self.make_info_log('Invoice prepared')
|
|
|
|
-
|
|
|
|
- # # Create invoice move lines
|
|
|
|
- # invoice_move_lines = self.create_invoice_move_lines(invoice_ids, float(kw.get('payment')), date_now)
|
|
|
|
- # self.make_info_log('Invoice move lines created')
|
|
|
|
-
|
|
|
|
- # # Create account move
|
|
|
|
- # account_move = self.create_account_move(invoice_ids, invoice_move_lines)
|
|
|
|
- # self.make_info_log('Account move created')
|
|
|
|
-
|
|
|
|
- # # Validate invoice
|
|
|
|
- # self.validate_invoice(invoice_ids, mode)
|
|
|
|
- # self.make_info_log('Invoice validated')
|
|
|
|
-
|
|
|
|
- # # Create account voucher
|
|
|
|
- # account_voucher = self.create_account_voucher(account_move.id, kw.get('journalId'), currency_id, float(kw.get('payment')))
|
|
|
|
- # self.make_info_log('Account voucher created')
|
|
|
|
-
|
|
|
|
- # # Close invoice
|
|
|
|
- # self.close_invoice(invoice_ids)
|
|
|
|
- # self.make_info_log('Attempt close invoice')
|
|
|
|
-
|
|
|
|
- # # Create account bank statement lines
|
|
|
|
- # account_bank_statement_lines = self.create_bank_statement_lines(account_voucher.id)
|
|
|
|
- # self.make_info_log('Bank statement lines created')
|
|
|
|
-
|
|
|
|
- # # Create account bank statement
|
|
|
|
- # self.create_bank_statement(account_voucher.id, account_bank_statement_lines, date_now)
|
|
|
|
- # self.make_info_log('Bank statement created')
|
|
|
|
-
|
|
|
|
- # return {
|
|
|
|
- # 'status': 'ok'
|
|
|
|
- # }
|
|
|
|
|
|
+ '''
|
|
|
|
+ Purchase processing resource route
|
|
|
|
+ '''
|
|
|
|
+ @http.route('/eiru_purchases/process', type='json', auth='user', methods=['POST'])
|
|
|
|
+ def process_purchase(self, **kw):
|
|
|
|
+ make_info_log('Processing {}'.format(kw.get('mode')))
|
|
|
|
+ return store_data(kw)
|