|
@@ -176,7 +176,7 @@ class Purchases(http.Controller):
|
|
|
'''
|
|
|
Make JSON response to send
|
|
|
'''
|
|
|
- def make_response(self, data, status=200):
|
|
|
+ def make_response(self, data=None, status=200):
|
|
|
return Response(json.dumps(data), status=status, content_type='application/json')
|
|
|
|
|
|
'''
|
|
@@ -189,7 +189,7 @@ class Purchases(http.Controller):
|
|
|
'''
|
|
|
@http.route('/eiru_purchases/new', auth='user', methods=['GET'], cors='*')
|
|
|
def new_purchase(self, **kw):
|
|
|
- self.make_info_log('Sending json response')
|
|
|
+ self.make_info_log('Sending JSON response')
|
|
|
|
|
|
return self.make_response({
|
|
|
'date': self.get_server_date(),
|
|
@@ -259,9 +259,44 @@ class Purchases(http.Controller):
|
|
|
}
|
|
|
|
|
|
'''
|
|
|
- Create purchase resource route
|
|
|
+ Purchase processing resource route
|
|
|
'''
|
|
|
@http.route('/eiru_purchases/create', type='json', auth='user', methods=['POST'], cors='*')
|
|
|
- def create_purchase(self, **kw):
|
|
|
+ def process_purchase(self, **kw):
|
|
|
self.make_info_log('Creating purchase')
|
|
|
- print(kw)
|
|
|
+
|
|
|
+ # Step 1: Select currency
|
|
|
+ currency_id = self.get_currency_id(int(kw.get('journal')))
|
|
|
+
|
|
|
+ # Step 2: Save purchase
|
|
|
+
|
|
|
+ print(currency_id)
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'status': 'ok'
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ '''
|
|
|
+ Get currency id based on journal
|
|
|
+ '''
|
|
|
+ def get_currency_id(self, journal_id):
|
|
|
+ journal = request.env['account.journal'].browse(journal_id)
|
|
|
+ return journal.default_debit_account_id.currency_id.id or journal.default_debit_account_id.company_currency_id.id
|
|
|
+
|
|
|
+ '''
|
|
|
+ Save purchase and return it
|
|
|
+ '''
|
|
|
+ def create_purchase(self, partner_id, order_lines, currency_id=None, payment_term_id=None):
|
|
|
+ purchase_order = request.env['purchase.order'].create({
|
|
|
+ 'partner_id': partner_id,
|
|
|
+ 'order_line': [[0, False, {
|
|
|
+ 'product_id': line.id,
|
|
|
+ 'product_qty': line.qty,
|
|
|
+ 'price_unit': line.price
|
|
|
+ }] for line in order_lines],
|
|
|
+ 'date_order': datetime.now().strftime('%Y-%m-%d'),
|
|
|
+ 'currency_id': currency_id
|
|
|
+ })
|
|
|
+
|
|
|
+ return purchase_order
|