123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- from account_bank_statement import create_bank_statement, create_bank_statement_lines
- from account_invoice import create_invoice, prepare_invoice, validate_invoice, close_invoice
- from account_journal import get_journals, get_currencies_from_journal
- from account_move import create_invoice_move_lines, create_account_move
- from account_payment_term import get_payment_terms
- from account_voucher import create_account_voucher
- from http_response import make_gzip_response
- from product_pricelist import get_pricelist_id
- from product_template import get_products
- 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_payments_type import get_bank_payment_types
- from res_bank import get_banks
- from res_currency import check_base_currency, get_base_currency
- from res_partner import get_suppliers
- from res_users import get_current_user
- from server_date import get_date
- from stock_picking_type import get_picking_types
- from stock_picking import get_pickings
- from stock_warehouse import get_warehouses
- def get_data(mode=None):
- data = {}
- check_base_currency()
- warehouses = get_warehouses()
- location_ids = map(lambda x: x.get('locationStock').get('id'), warehouses)
- currencies = get_currencies_from_journal()
- if len(currencies) == 0:
- currencies = [get_base_currency()]
- if mode == 'purchase' or mode == 'expense':
- data = {
- 'date': get_date(),
- 'user': get_current_user(),
- 'currencies': currencies,
- 'journals': get_journals(),
- 'suppliers': get_suppliers(),
- 'products': get_products(mode, location_ids),
- 'pickingTypes': get_picking_types(),
- 'paymentTerms': get_payment_terms(),
- 'banks': get_banks(),
- 'bankPaymentTypes': get_bank_payment_types(),
- 'chequeTypes': get_cheque_types(),
- 'warehouses': warehouses
- }
- if mode == 'product_picking':
- data = {
- 'date': get_date(),
- 'user': get_current_user(),
- 'currencies': currencies,
- 'suppliers': get_suppliers(),
- 'products': get_products('purchase', location_ids),
- 'warehouses': warehouses
- }
- if mode == 'payment':
- data = {
- 'purchaseOrders': get_purchase_orders(),
- 'currencies': currencies,
- '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()
- }
- return make_gzip_response(data)
- def process_data(data=None):
- if not data:
- return {}
- def drafting_order(currency_id, supplier_id, cart_items, date_now, payment_term_id, warehouse_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()
- mode = data.get('mode')
- currency_id = data.get('currencyId')
- journal_id = data.get('journalId')
- supplier_id = data.get('supplierId')
- supplier_invoice_number = data.get('supplierInvoiceNumber', None)
- cart_items = data.get('items')
- payment_term_id = data.get('paymentTermId')
- warehouse_id = data.get('warehouseId', None)
- payment = float(data.get('payment', 0.0))
- if mode not in ('product_picking', 'payment', 'product_taking'):
- order_id = None
- if mode == 'purchase':
- order_id, currency_id = drafting_order(currency_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 == 'product_picking':
- order_id, currency_id = drafting_order(currency_id, supplier_id, cart_items, date_now, payment_term_id, warehouse_id)
- confirm_purchase_order(order_id)
- 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)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return {
- 'status': 'ok'
- }
|