|
@@ -8,7 +8,7 @@ from account_voucher import create_account_voucher
|
|
from http_response import make_gzip_response
|
|
from http_response import make_gzip_response
|
|
from product_pricelist import get_pricelist_id
|
|
from product_pricelist import get_pricelist_id
|
|
from product_template import get_products
|
|
from product_template import get_products
|
|
-from purchase_order import create_purchase_order, confirm_purchase_order
|
|
|
|
|
|
+from purchase_order import (get_purchase_orders, get_purchase_order, create_purchase_order, confirm_purchase_order, force_assign_picking, done_picking)
|
|
from res_bank_cheque_type import get_cheque_types
|
|
from res_bank_cheque_type import get_cheque_types
|
|
from res_bank_payments_type import get_bank_payment_types
|
|
from res_bank_payments_type import get_bank_payment_types
|
|
from res_bank import get_banks
|
|
from res_bank import get_banks
|
|
@@ -19,11 +19,12 @@ from server_date import get_date
|
|
from stock_picking_type import get_picking_types
|
|
from stock_picking_type import get_picking_types
|
|
from stock_picking import get_pickings
|
|
from stock_picking import get_pickings
|
|
|
|
|
|
-'''
|
|
|
|
-'''
|
|
|
|
|
|
+
|
|
def get_data(mode=None):
|
|
def get_data(mode=None):
|
|
data = {}
|
|
data = {}
|
|
|
|
|
|
|
|
+ check_base_currency()
|
|
|
|
+
|
|
if mode == 'purchase' or mode == 'expense':
|
|
if mode == 'purchase' or mode == 'expense':
|
|
data = {
|
|
data = {
|
|
'date': get_date(),
|
|
'date': get_date(),
|
|
@@ -31,7 +32,7 @@ def get_data(mode=None):
|
|
'currencies': get_currencies_from_journal(),
|
|
'currencies': get_currencies_from_journal(),
|
|
'journals': get_journals(),
|
|
'journals': get_journals(),
|
|
'suppliers': get_suppliers(),
|
|
'suppliers': get_suppliers(),
|
|
- 'products': get_products(kw.get('mode')),
|
|
|
|
|
|
+ 'products': get_products(mode),
|
|
'pickingTypes': get_picking_types(),
|
|
'pickingTypes': get_picking_types(),
|
|
'paymentTerms': get_payment_terms(),
|
|
'paymentTerms': get_payment_terms(),
|
|
'banks': get_banks(),
|
|
'banks': get_banks(),
|
|
@@ -50,13 +51,14 @@ def get_data(mode=None):
|
|
|
|
|
|
if mode == 'payment':
|
|
if mode == 'payment':
|
|
data = {
|
|
data = {
|
|
|
|
+ 'purchaseOrders': get_purchase_orders(),
|
|
'currencies': get_currencies_from_journal(),
|
|
'currencies': get_currencies_from_journal(),
|
|
'suppliers': get_suppliers(),
|
|
'suppliers': get_suppliers(),
|
|
'journals': get_journals(),
|
|
'journals': get_journals(),
|
|
'paymentTerms': get_payment_terms(),
|
|
'paymentTerms': get_payment_terms(),
|
|
'banks': get_banks(),
|
|
'banks': get_banks(),
|
|
'bankPaymentTypes': get_bank_payment_types(),
|
|
'bankPaymentTypes': get_bank_payment_types(),
|
|
- 'chequeTypes': get_cheque_types()
|
|
|
|
|
|
+ 'chequeTypes': get_cheque_types(),
|
|
}
|
|
}
|
|
|
|
|
|
if mode == 'product_taking':
|
|
if mode == 'product_taking':
|
|
@@ -67,18 +69,68 @@ def get_data(mode=None):
|
|
return make_gzip_response(data)
|
|
return make_gzip_response(data)
|
|
|
|
|
|
|
|
|
|
-'''
|
|
|
|
-'''
|
|
|
|
-def store_data(data=None):
|
|
|
|
|
|
+def process_data(data=None):
|
|
if not data:
|
|
if not data:
|
|
return {}
|
|
return {}
|
|
|
|
|
|
- def create_purchase():
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
- def create_expense():
|
|
|
|
- pass
|
|
|
|
-
|
|
|
|
|
|
+ def drafting_order(journal_id, supplier_id, cart_items, date_now, payment_term_id, warehouse_id):
|
|
|
|
+ currency_id = get_currency_id(journal_id)
|
|
|
|
+ pricelist_id = get_pricelist_id(currency_id)
|
|
|
|
+
|
|
|
|
+ order = create_purchase_order(supplier_id, cart_items, date_now, currency_id, pricelist_id, payment_term_id, warehouse_id)
|
|
|
|
+
|
|
|
|
+ return order.id, currency_id
|
|
|
|
+
|
|
|
|
+ def making_order(order_id):
|
|
|
|
+ if not order_id:
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+ order = get_purchase_order(order_id)
|
|
|
|
+ confirm_purchase_order(order.id)
|
|
|
|
+
|
|
|
|
+ return order.id
|
|
|
|
+
|
|
|
|
+ def paying_order(
|
|
|
|
+ order_id,
|
|
|
|
+ supplier_invoice_number=None,
|
|
|
|
+ supplier_id=None,
|
|
|
|
+ cart_items=None,
|
|
|
|
+ date_now=None,
|
|
|
|
+ payment_term_id=None,
|
|
|
|
+ warehouse_id=None
|
|
|
|
+ ):
|
|
|
|
+ invoice = None
|
|
|
|
+
|
|
|
|
+ if order_id:
|
|
|
|
+ order = get_purchase_order(order_id)
|
|
|
|
+ invoice = order.invoice_ids
|
|
|
|
+
|
|
|
|
+ if not invoice:
|
|
|
|
+ invoice = create_invoice(supplier_id, cart_items, currency_id, payment_term_id, supplier_invoice_number)
|
|
|
|
+
|
|
|
|
+ invoice_ids = invoice.mapped(lambda x: x.id)
|
|
|
|
+
|
|
|
|
+ prepare_invoice(invoice_ids, currency_id, date_now)
|
|
|
|
+ move_lines = create_invoice_move_lines(invoice_ids, payment, date_now)
|
|
|
|
+ account_move = create_account_move(invoice_ids, move_lines)
|
|
|
|
+
|
|
|
|
+ validate_invoice(invoice_ids, mode)
|
|
|
|
+
|
|
|
|
+ account_voucher = create_account_voucher(account_move.id, journal_id, currency_id, payment)
|
|
|
|
+ close_invoice(invoice_ids)
|
|
|
|
+
|
|
|
|
+ statement_lines = create_bank_statement_lines(account_voucher.id)
|
|
|
|
+ bank_statement = create_bank_statement(account_voucher.id, statement_lines, date_now)
|
|
|
|
+
|
|
|
|
+ return bank_statement.id
|
|
|
|
+
|
|
|
|
+ def complete_order(order_id):
|
|
|
|
+ if not order_id:
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+ force_assign_picking(order_id)
|
|
|
|
+ done_picking(order_id)
|
|
|
|
+
|
|
date_now = get_date()
|
|
date_now = get_date()
|
|
mode = data.get('mode')
|
|
mode = data.get('mode')
|
|
journal_id = data.get('journalId')
|
|
journal_id = data.get('journalId')
|
|
@@ -86,38 +138,70 @@ def store_data(data=None):
|
|
supplier_invoice_number = data.get('supplierInvoiceNumber', None)
|
|
supplier_invoice_number = data.get('supplierInvoiceNumber', None)
|
|
cart_items = data.get('items')
|
|
cart_items = data.get('items')
|
|
payment_term_id = data.get('paymentTermId')
|
|
payment_term_id = data.get('paymentTermId')
|
|
- payment = float(kw.get('payment'))
|
|
|
|
-
|
|
|
|
- currency_id = get_currency_id(journal_id)
|
|
|
|
|
|
+ warehouse_id = data.get('warehouseId', None)
|
|
|
|
+ payment = float(data.get('payment'))
|
|
|
|
|
|
- pricelist_id = get_pricelist_id(currency_id)
|
|
|
|
|
|
+ if mode not in ('product_picking', 'payment', 'product_taking'):
|
|
|
|
+ order_id = None
|
|
|
|
|
|
- invoice = None
|
|
|
|
|
|
+ if mode == 'purchase':
|
|
|
|
+ order_id, currency_id = drafting_order(journal_id, supplier_id, cart_items, date_now, payment_term_id)
|
|
|
|
+ making_order(order_id)
|
|
|
|
+ complete_order(order_id)
|
|
|
|
+ else:
|
|
|
|
+ paying_order(order_id)
|
|
|
|
|
|
- if mode == 'purchase':
|
|
|
|
- purchase_order = create_purchase_order(supplier_id, cart_items, date_now, currency_id, pricelist_id, payment_term_id)
|
|
|
|
- confirm_purchase_order(purchase_order.id)
|
|
|
|
-
|
|
|
|
- invoice = purchase_order.invoice_ids
|
|
|
|
- invoice.write({
|
|
|
|
- 'supplier_invoice_number': supplier_invoice_number
|
|
|
|
- })
|
|
|
|
- else:
|
|
|
|
- invoice = create_invoice(supplier_id, cart_items, currency_id, payment_term_id, supplier_invoice_number)
|
|
|
|
-
|
|
|
|
- invoice_ids = invoice.mapped(lambda x: x.id)
|
|
|
|
-
|
|
|
|
- prepare_invoice(invoice_ids, currency_id, date_now)
|
|
|
|
- move_lines = create_invoice_move_lines(invoice_ids, payment, date_now)
|
|
|
|
- account_move = create_account_move(invoice_ids, move_lines)
|
|
|
|
-
|
|
|
|
- validate_invoice(invoice_ids, mode)
|
|
|
|
-
|
|
|
|
- account_voucher = create_account_voucher(account_move.id, journal_id, currency_id, payment)
|
|
|
|
- close_invoice(invoice_ids)
|
|
|
|
|
|
+ if mode == 'product_picking':
|
|
|
|
+ order_id, currency_id = drafting_order(journal_id, supplier_id, cart_items, date_now, payment_term_id, warehouse_id)
|
|
|
|
+ making_order(order_id)
|
|
|
|
|
|
- statement_lines = create_bank_statement_lines(account_voucher.id)
|
|
|
|
- create_bank_statement(account_voucher.id, statement_lines, date_now)
|
|
|
|
|
|
+ if mode == 'payment':
|
|
|
|
+ order_id = data.get('orderId')
|
|
|
|
+ paying_order(order_id, supplier_invoice_number)
|
|
|
|
+
|
|
|
|
+ if mode == 'picking':
|
|
|
|
+ order_id = data.get('orderId')
|
|
|
|
+ complete_order(order_id)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # prepare_invoice(invoice_ids, currency_id, date_now)
|
|
|
|
+ # move_lines = create_invoice_move_lines(invoice_ids, payment, date_now)
|
|
|
|
+ # account_move = create_account_move(invoice_ids, move_lines)
|
|
|
|
+ #
|
|
|
|
+ # validate_invoice(invoice_ids, mode)
|
|
|
|
+ #
|
|
|
|
+ # account_voucher = create_account_voucher(account_move.id, journal_id, currency_id, payment)
|
|
|
|
+ # close_invoice(invoice_ids)
|
|
|
|
+ #
|
|
|
|
+ # statement_lines = create_bank_statement_lines(account_voucher.id)
|
|
|
|
+ # create_bank_statement(account_voucher.id, statement_lines, date_now)
|
|
|
|
+
|
|
|
|
+ # invoice = None
|
|
|
|
+ #
|
|
|
|
+ # if mode == 'purchase':
|
|
|
|
+ # purchase_order = create_purchase_order(supplier_id, cart_items, date_now, currency_id, pricelist_id, payment_term_id)
|
|
|
|
+ # confirm_purchase_order(purchase_order.id)
|
|
|
|
+ #
|
|
|
|
+ # invoice = purchase_order.invoice_ids
|
|
|
|
+ # invoice.write({
|
|
|
|
+ # 'supplier_invoice_number': supplier_invoice_number
|
|
|
|
+ # })
|
|
|
|
+ # else:
|
|
|
|
+ # invoice = create_invoice(supplier_id, cart_items, currency_id, payment_term_id, supplier_invoice_number)
|
|
|
|
+ #
|
|
|
|
+ # invoice_ids = invoice.mapped(lambda x: x.id)
|
|
|
|
+ #
|
|
|
|
+ # prepare_invoice(invoice_ids, currency_id, date_now)
|
|
|
|
+ # move_lines = create_invoice_move_lines(invoice_ids, payment, date_now)
|
|
|
|
+ # account_move = create_account_move(invoice_ids, move_lines)
|
|
|
|
+ #
|
|
|
|
+ # validate_invoice(invoice_ids, mode)
|
|
|
|
+ #
|
|
|
|
+ # account_voucher = create_account_voucher(account_move.id, journal_id, currency_id, payment)
|
|
|
|
+ # close_invoice(invoice_ids)
|
|
|
|
+ #
|
|
|
|
+ # statement_lines = create_bank_statement_lines(account_voucher.id)
|
|
|
|
+ # create_bank_statement(account_voucher.id, statement_lines, date_now)
|
|
|
|
|
|
return {
|
|
return {
|
|
'status': 'ok'
|
|
'status': 'ok'
|